Skip to content

Commit 3dd3663

Browse files
committed
[IMP] purchase_lot : lot_id is computed from stock moves so that it can be updated after confirmation and purchase order lines aren't merged even if lots aren't defined at creation
1 parent 7297386 commit 3dd3663

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

purchase_lot/models/purchase_order_line.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,24 @@ class PurchaseOrderLine(models.Model):
99
_inherit = "purchase.order.line"
1010

1111
lot_id = fields.Many2one(
12-
"stock.lot", string="Serial Number", readonly=True, copy=False
12+
"stock.lot",
13+
string="Serial Number",
14+
readonly=True,
15+
copy=False,
16+
compute="_compute_lot_id",
17+
store=True,
1318
)
1419

20+
@api.depends(
21+
"move_ids", "move_ids.restrict_lot_id", "move_ids.move_dest_ids.restrict_lot_id"
22+
)
23+
def _compute_lot_id(self):
24+
for line in self:
25+
line.lot_id = (
26+
line.move_ids.restrict_lot_id
27+
| line.move_ids.move_dest_ids.restrict_lot_id
28+
)
29+
1530
@api.model
1631
def _prepare_purchase_order_line_from_procurement(
1732
self, product_id, product_qty, product_uom, company_id, values, po
@@ -46,7 +61,11 @@ def _find_candidate(
4661
values,
4762
):
4863
lot_id = values.get("restrict_lot_id", False)
49-
self = self.filtered(lambda l: l.lot_id.id == lot_id)
64+
moves_dest = values.get("move_dest_ids", False)
65+
if lot_id:
66+
self = self.filtered(lambda l: l.lot_id.id == lot_id)
67+
elif self.product_id.tracking != "none" and moves_dest:
68+
self = self.filtered(lambda l: moves_dest in l.move_dest_ids)
5069
return super()._find_candidate(
5170
product_id,
5271
product_qty,

purchase_lot/models/stock_rule.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class StockRule(models.Model):
1111
@api.model
1212
def _get_procurements_to_merge_groupby(self, procurement):
1313
return (
14-
procurement.values.get("restrict_lot_id"),
14+
procurement.values.get("move_dest_ids"),
1515
super()._get_procurements_to_merge_groupby(procurement),
1616
)

0 commit comments

Comments
 (0)