Skip to content

Commit 2c0d84a

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 2c0d84a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

purchase_lot/models/purchase_order_line.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@ 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("move_dest_ids.restrict_lot_id", "move_ids.restrict_lot_id")
21+
def _compute_lot_id(self):
22+
for line in self:
23+
line.lot_id = (
24+
line.move_dest_ids.restrict_lot_id | line.move_ids.restrict_lot_id
25+
)
26+
1527
@api.model
1628
def _prepare_purchase_order_line_from_procurement(
1729
self, product_id, product_qty, product_uom, company_id, values, po
@@ -46,7 +58,11 @@ def _find_candidate(
4658
values,
4759
):
4860
lot_id = values.get("restrict_lot_id", False)
49-
self = self.filtered(lambda l: l.lot_id.id == lot_id)
61+
moves_dest = values.get("move_dest_ids", False)
62+
if lot_id:
63+
self = self.filtered(lambda l: l.lot_id.id == lot_id)
64+
elif self.product_id.tracking != "none" and moves_dest:
65+
self = self.filtered(lambda l: moves_dest in l.move_dest_ids)
5066
return super()._find_candidate(
5167
product_id,
5268
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)