Skip to content

Commit

Permalink
[FIX] mrp{,_subcontracting}: update demand to match subcontract MO
Browse files Browse the repository at this point in the history
Steps to reproduce:
- Manufacturing -> Configuration -> Settings -> Enable subcontracting
- Products -> Bill of Material
- Create a 'subcontracting' BoM for product A from supplier S
- Inventory -> Overview -> Receipts -> New immediate transfer
- Set S as 'Receive from', A as product and hit save
- Open move details and set the MO quantity to produce to 10.
- Record components for all 10 finished products

Issue:
After recording the production, a backorder is created for 1 less
quantity than before on top of the existing MO with 10 qty.
Recording the production once again (by clicking again on the Record
Production button, since the form didn't close) will somehow again
increment the initial MO's qty to produce, while validating the
backorder MO.

This is mainly due to an inconsistency between the subcontracted move's
demand and the subcontract MO's qty to produce. By syncing them, the
issue can be avoided.

Task-3383596

Part-of: odoo#129009
  • Loading branch information
clesgow committed Oct 6, 2023
1 parent cde05a9 commit 005b51f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion addons/mrp/wizard/change_production_qty.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _update_finished_moves(self, production, new_qty, old_qty):
if self._need_quantity_propagation(move, qty):
push_moves |= move.copy({'product_uom_qty': qty})
else:
move.write({'product_uom_qty': move.product_uom_qty + qty})
self._update_product_qty(move, qty)

if push_moves:
push_moves._action_confirm()._action_assign()
Expand All @@ -53,6 +53,10 @@ def _update_finished_moves(self, production, new_qty, old_qty):
def _need_quantity_propagation(self, move, qty):
return move.move_dest_ids and not float_is_zero(qty, precision_rounding=move.product_uom.rounding)

@api.model
def _update_product_qty(self, move, qty):
move.write({'product_uom_qty': move.product_uom_qty + qty})

def change_prod_qty(self):
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
for wizard in self:
Expand Down
9 changes: 9 additions & 0 deletions addons/mrp_subcontracting/wizard/change_production_qty.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ class ChangeProductionQty(models.TransientModel):
def _need_quantity_propagation(self, move, qty):
res = super()._need_quantity_propagation(move, qty)
return res and not any(m.is_subcontract for m in move.move_dest_ids)

@api.model
def _update_product_qty(self, move, qty):
res = super()._update_product_qty(move, qty)
subcontract_moves = move.move_dest_ids.filtered(lambda m: m.is_subcontract)
if subcontract_moves:
subcontract_moves[0].with_context(cancel_backorder=False).write({'product_uom_qty': subcontract_moves[0].product_uom_qty + qty})

return res

0 comments on commit 005b51f

Please sign in to comment.