Skip to content

Commit

Permalink
[IMP] purchase_lot : lot_id is computed from stock moves so that it c…
Browse files Browse the repository at this point in the history
…an be updated after confirmation and purchase order lines aren't merged even if lots aren't defined at creation
  • Loading branch information
metaminux committed Apr 17, 2024
1 parent 7297386 commit 3dd3663
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions purchase_lot/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@ class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

lot_id = fields.Many2one(
"stock.lot", string="Serial Number", readonly=True, copy=False
"stock.lot",
string="Serial Number",
readonly=True,
copy=False,
compute="_compute_lot_id",
store=True,
)

@api.depends(
"move_ids", "move_ids.restrict_lot_id", "move_ids.move_dest_ids.restrict_lot_id"
)
def _compute_lot_id(self):
for line in self:
line.lot_id = (
line.move_ids.restrict_lot_id
| line.move_ids.move_dest_ids.restrict_lot_id
)

@api.model
def _prepare_purchase_order_line_from_procurement(
self, product_id, product_qty, product_uom, company_id, values, po
Expand Down Expand Up @@ -46,7 +61,11 @@ def _find_candidate(
values,
):
lot_id = values.get("restrict_lot_id", False)
self = self.filtered(lambda l: l.lot_id.id == lot_id)
moves_dest = values.get("move_dest_ids", False)
if lot_id:
self = self.filtered(lambda l: l.lot_id.id == lot_id)
elif self.product_id.tracking != "none" and moves_dest:
self = self.filtered(lambda l: moves_dest in l.move_dest_ids)
return super()._find_candidate(
product_id,
product_qty,
Expand Down
2 changes: 1 addition & 1 deletion purchase_lot/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class StockRule(models.Model):
@api.model
def _get_procurements_to_merge_groupby(self, procurement):
return (
procurement.values.get("restrict_lot_id"),
procurement.values.get("move_dest_ids"),
super()._get_procurements_to_merge_groupby(procurement),
)

0 comments on commit 3dd3663

Please sign in to comment.