Skip to content

Commit fc3a67a

Browse files
committed
Merge pull request #1 from Groupe-Voltaire-SAS/16.0-imp-purchase_lot-update-restrict-lot_pol
16.0 imp purchase lot update restrict lot on purchase order line
2 parents 2c0d84a + f332134 commit fc3a67a

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

purchase_lot/models/purchase_order_line.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class PurchaseOrderLine(models.Model):
2121
def _compute_lot_id(self):
2222
for line in self:
2323
line.lot_id = (
24-
line.move_dest_ids.restrict_lot_id | line.move_ids.restrict_lot_id
24+
line.move_dest_ids.restrict_lot_id
25+
| line.move_ids.restrict_lot_id
26+
| line.sale_order_line.lot_id
2527
)
2628

2729
@api.model

purchase_lot/tests/test_purchase_lot.py

+65
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (C) 2022 Akretion (<http://www.akretion.com>).
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4+
from odoo.tests import Form
45
from odoo.tests.common import TransactionCase
6+
from odoo.tools import mute_logger
57

68

79
class TestPurchaseLot(TransactionCase):
@@ -31,6 +33,24 @@ def setUpClass(cls):
3133
}
3234
)
3335
cls.out_picking_type = cls.env.ref("stock.picking_type_out")
36+
cls.supplier = cls.env["res.partner"].create({"name": "Vendor"})
37+
cls.customer = cls.env["res.partner"].create({"name": "Customer"})
38+
cls.external_serial_product = cls.env["product.product"].create(
39+
{
40+
"name": "Pen drive",
41+
"type": "product",
42+
"categ_id": cls.env.ref("product.product_category_1").id,
43+
"lst_price": 100.0,
44+
"standard_price": 0.0,
45+
"uom_id": cls.env.ref("uom.product_uom_unit").id,
46+
"uom_po_id": cls.env.ref("uom.product_uom_unit").id,
47+
"seller_ids": [
48+
(0, 0, {"delay": 1, "partner_id": cls.supplier.id, "min_qty": 2.0})
49+
],
50+
"route_ids": [(4, buy_route.id, 0), (4, mto_route.id, 0)],
51+
}
52+
)
53+
cls.external_serial_product.product_tmpl_id.tracking = "serial"
3454

3555
def test_purchase_lot(self):
3656
lot1 = self.env["stock.lot"].create(
@@ -88,3 +108,48 @@ def test_purchase_lot(self):
88108
self.assertEqual(pol1.lot_id.id, lot1.id)
89109
pol1.order_id.button_confirm()
90110
self.assertEqual(pol1.move_ids.restrict_lot_id.id, lot1.id)
111+
112+
def test_lot_propagation(self):
113+
# Required for `route_id` to be visible in the view
114+
self.env.user.groups_id += self.env.ref("stock.group_adv_location")
115+
116+
# Create a sales order with a line of 200 PCE incoming shipment,
117+
# with route_id drop shipping
118+
so_form = Form(self.env["sale.order"])
119+
so_form.partner_id = self.customer
120+
so_form.payment_term_id = self.env.ref(
121+
"account.account_payment_term_end_following_month"
122+
)
123+
with mute_logger("odoo.tests.common.onchange"):
124+
# otherwise complains that there's not enough inventory and
125+
# apparently that's normal according to @jco and @sle
126+
with so_form.order_line.new() as line:
127+
line.product_id = self.external_serial_product
128+
line.product_uom_qty = 200
129+
line.price_unit = 1.00
130+
line.route_id = self.env.ref("purchase_stock.route_warehouse0_buy")
131+
132+
sale_order_drp_shpng = so_form.save()
133+
sale_order_drp_shpng.order_line.lot_id = self.env["stock.lot"].create(
134+
{
135+
"name": "Seq test DS pdt",
136+
"product_id": self.external_serial_product.id,
137+
}
138+
)
139+
initial_lot = sale_order_drp_shpng.order_line.lot_id
140+
# Confirm sales order
141+
sale_order_drp_shpng.action_confirm()
142+
143+
# Check a quotation was created to a certain vendor
144+
# and confirm so it becomes a confirmed purchase order
145+
purchase = self.env["purchase.order"].search(
146+
[("partner_id", "=", self.supplier.id)]
147+
)
148+
self.assertEqual(purchase.state, "draft")
149+
self.assertTrue(purchase.order_line.lot_id)
150+
self.assertEqual(purchase.order_line.lot_id, initial_lot)
151+
purchase.button_confirm()
152+
purchase.button_approve()
153+
self.assertTrue(purchase.picking_ids.move_ids.restrict_lot_id)
154+
self.assertTrue(purchase.order_line.lot_id)
155+
self.assertEqual(purchase.order_line.lot_id, initial_lot)

0 commit comments

Comments
 (0)