File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,32 @@ def _prepare_merge_moves_distinct_fields(self):
3535 distinct_fields += ["elaboration_ids" , "elaboration_note" ]
3636 return distinct_fields
3737
38+ def write (self , vals ):
39+ # Propagate elaboration quantities to sale order line when quantity_done changes
40+ # in done moves (unlock picking)
41+ res = False
42+ # Use Demand field because Done field is computed and Demand is updated to Done
43+ # when move state is done (In this version 15.0) TODO: Check in new versions
44+ if "product_uom_qty" in vals and self [:1 ].state == "done" :
45+ moves_with_elaborations = self .filtered (
46+ lambda m : m .sale_line_id and m .elaboration_ids
47+ )
48+ old_quantities = {
49+ move : move .product_uom_qty for move in moves_with_elaborations
50+ }
51+ res = super ().write (vals )
52+ for move in moves_with_elaborations :
53+ qty_difference = move .product_uom_qty - old_quantities [move ]
54+ if not qty_difference :
55+ continue
56+ for move_elab in move .elaboration_ids :
57+ sale_elab = move .sale_line_id .order_id .order_line .filtered (
58+ lambda x : x .product_id == move_elab .product_id
59+ )[:1 ]
60+ if sale_elab :
61+ sale_elab .product_uom_qty += qty_difference
62+ return res or super ().write (vals )
63+
3864
3965class StockMoveLine (models .Model ):
4066 _inherit = "stock.move.line"
Original file line number Diff line number Diff line change @@ -182,3 +182,12 @@ def test_multi_elaboration_per_line(self):
182182 elaboration_lines = self .order .order_line .filtered ("is_elaboration" )
183183 self .assertEqual (len (elaboration_lines ), 2 )
184184 self .assertEqual (sum (elaboration_lines .mapped ("product_uom_qty" )), 12.0 )
185+
186+ def test_sale_elaboration_done_move_changes (self ):
187+ self .order .action_confirm ()
188+ self .order .picking_ids .move_lines .quantity_done = 10.0
189+ self .order .picking_ids ._action_done ()
190+ self .order .picking_ids .move_lines .quantity_done = 15.0
191+ elaboration_lines = self .order .order_line .filtered ("is_elaboration" )
192+ self .assertEqual (len (elaboration_lines ), 1 )
193+ self .assertEqual (elaboration_lines .product_uom_qty , 15.0 )
You can’t perform that action at this time.
0 commit comments