Skip to content

Commit

Permalink
Merge PR #3610 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by CarlosRoca13
  • Loading branch information
OCA-git-bot committed Mar 6, 2025
2 parents 505a15e + c278360 commit 8fc8be1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions sale_elaboration/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ def _prepare_merge_moves_distinct_fields(self):
distinct_fields += ["elaboration_ids", "elaboration_note"]
return distinct_fields

def write(self, vals):
# Propagate elaboration quantities to sale order line when quantity_done changes
# in done moves (unlock picking)
res = False
# Use Demand field because Done field is computed and Demand is updated to Done
# when move state is done (In this version 15.0) TODO: Check in new versions
if "product_uom_qty" in vals and self[:1].state == "done":
moves_with_elaborations = self.filtered(
lambda m: m.sale_line_id and m.elaboration_ids
)
old_quantities = {
move: move.product_uom_qty for move in moves_with_elaborations
}
res = super().write(vals)
for move in moves_with_elaborations:
qty_difference = move.product_uom_qty - old_quantities[move]
if not qty_difference:
continue
for move_elab in move.elaboration_ids:
sale_elab = move.sale_line_id.order_id.order_line.filtered(
lambda x: x.product_id == move_elab.product_id
)[:1]
if sale_elab:
sale_elab.product_uom_qty += qty_difference
return res or super().write(vals)


class StockMoveLine(models.Model):
_inherit = "stock.move.line"
Expand Down
9 changes: 9 additions & 0 deletions sale_elaboration/tests/test_sale_elaboration.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,12 @@ def test_multi_elaboration_per_line(self):
elaboration_lines = self.order.order_line.filtered("is_elaboration")
self.assertEqual(len(elaboration_lines), 2)
self.assertEqual(sum(elaboration_lines.mapped("product_uom_qty")), 12.0)

def test_sale_elaboration_done_move_changes(self):
self.order.action_confirm()
self.order.picking_ids.move_lines.quantity_done = 10.0
self.order.picking_ids._action_done()
self.order.picking_ids.move_lines.quantity_done = 15.0
elaboration_lines = self.order.order_line.filtered("is_elaboration")
self.assertEqual(len(elaboration_lines), 1)
self.assertEqual(elaboration_lines.product_uom_qty, 15.0)

0 comments on commit 8fc8be1

Please sign in to comment.