diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 33434edfd98..9db5a2b9d49 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -73,6 +73,13 @@ class StockMove(models.Model): order_finished_lot_ids = fields.Many2many('stock.production.lot', compute='_compute_order_finished_lot_ids') finished_lots_exist = fields.Boolean('Finished Lots Exist', compute='_compute_order_finished_lot_ids') + def _unreserve_initial_demand(self, new_move): + # If you were already putting stock.move.lots on the next one in the work order, transfer those to the new move + self.filtered(lambda m: m.production_id or m.raw_material_production_id)\ + .mapped('move_line_ids')\ + .filtered(lambda ml: ml.qty_done == 0.0)\ + .write({'move_id': new_move, 'product_uom_qty': 0}) + @api.depends('active_move_line_ids.qty_done', 'active_move_line_ids.product_uom_id') def _compute_done_quantity(self): super(StockMove, self)._compute_done_quantity() diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 393b0a31c28..c5375658518 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1067,6 +1067,9 @@ class StockMove(models.Model): break return extra_move + def _unreserve_initial_demand(self, new_move): + pass + def _action_done(self): self.filtered(lambda move: move.state == 'draft')._action_confirm() # MRP allows scrapping draft moves @@ -1107,9 +1110,7 @@ class StockMove(models.Model): move_line.write({'product_uom_qty': move_line.qty_done}) except UserError: pass - - # If you were already putting stock.move.lots on the next one in the work order, transfer those to the new move - move.move_line_ids.filtered(lambda x: x.qty_done == 0.0).write({'move_id': new_move, 'product_uom_qty': 0}) + move._unreserve_initial_demand(new_move) move.move_line_ids._action_done() # Check the consistency of the result packages; there should be an unique location across # the contained quants. diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 8326328bc95..53948b477f9 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -1753,16 +1753,27 @@ class StockMove(TransactionCase): backorder_wizard = self.env[(res_dict_for_back_order.get('res_model'))].browse(res_dict_for_back_order.get('res_id')) backorder_wizard.with_context(debug=True).process() backorder = self.env['stock.picking'].search([('backorder_id', '=', picking_pack_cust.id)]) - backordered_ml = backorder.move_line_ids - quant_lot3 = self.env['stock.quant'].search([('lot_id', '=', backordered_ml.lot_id.id)]) + backordered_move = backorder.move_lines # due to the rounding, the backordered quantity is 0.999 ; we shoudln't be able to reserve # 0.999 on a tracked by serial number quant - self.assertEqual(backordered_ml.product_uom_qty, 0) - self.assertTrue(backordered_ml.lot_id) + backordered_move._action_assign() + self.assertEqual(backordered_move.reserved_availability, 0) # force the serial number and validate - backordered_ml.qty_done = 1 + lot3 = self.env['stock.production.lot'].search([('name', '=', "lot3")]) + backorder.write({'move_line_ids': [(0, 0, { + 'product_id': self.product2.id, + 'product_uom_id': self.uom_unit.id, + 'qty_done': 1, + 'product_uom_qty': 0, + 'lot_id': lot3.id, + 'package_id': False, + 'result_package_id': False, + 'location_id': backordered_move.location_id.id, + 'location_dest_id': backordered_move.location_dest_id.id, + 'move_id': backordered_move.id, + })]}) overprocessed_wizard = backorder.button_validate() overprocessed_wizard = self.env['stock.overprocessed.transfer'].browse(overprocessed_wizard['res_id'])