diff --git a/addons/mrp/tests/test_stock.py b/addons/mrp/tests/test_stock.py index 0086ed9cb58..d5750305ff1 100644 --- a/addons/mrp/tests/test_stock.py +++ b/addons/mrp/tests/test_stock.py @@ -227,6 +227,40 @@ class TestWarehouseMrp(common.TestMrpCommon): self.assertEqual(location_dest.id, self.depot_location.id) self.assertNotEqual(location_dest.id, self.stock_location.id) + def test_backorder_unpacking(self): + """ Test that movement of pack in backorder is correctly handled. """ + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) + warehouse.write({'manufacture_steps': 'pbm'}) + + self.product_1.type = 'product' + self.env['stock.quant']._update_available_quantity(self.product_1, self.stock_location, 100) + + mo_form = Form(self.env['mrp.production']) + mo_form.bom_id = self.bom_4 + mo_form.product_qty = 100 + mo = mo_form.save() + mo.action_confirm() + + package = self.env['stock.quant.package'].create({}) + + picking = mo.picking_ids + picking.move_line_ids.write({ + 'quantity': 20, + 'result_package_id': package.id, + }) + + res_dict = picking.button_validate() + wizard = Form(self.env[res_dict['res_model']].with_context(res_dict['context'])).save() + wizard.process() + + backorder = picking.backorder_ids + backorder.move_line_ids.quantity = 80 + backorder.button_validate() + + self.assertEqual(picking.state, 'done') + self.assertEqual(backorder.state, 'done') + self.assertEqual(mo.move_raw_ids.move_line_ids.mapped('quantity_product_uom'), [20, 80]) + class TestKitPicking(common.TestMrpCommon): @classmethod def setUpClass(cls): diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index d362ae254d1..63fbdafc06e 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1688,8 +1688,8 @@ Please change the quantity done or the rounding precision of your unit of measur if not available_move_lines: continue for move_line in move.move_line_ids.filtered(lambda m: m.quantity_product_uom): - if available_move_lines.get((move_line.location_id, move_line.lot_id, move_line.result_package_id, move_line.owner_id)): - available_move_lines[(move_line.location_id, move_line.lot_id, move_line.result_package_id, move_line.owner_id)] -= move_line.quantity_product_uom + if available_move_lines.get((move_line.location_id, move_line.lot_id, move_line.package_id, move_line.owner_id)): + available_move_lines[(move_line.location_id, move_line.lot_id, move_line.package_id, move_line.owner_id)] -= move_line.quantity_product_uom for (location_id, lot_id, package_id, owner_id), quantity in available_move_lines.items(): need = move.product_qty - sum(move.move_line_ids.mapped('quantity_product_uom')) # `quantity` is what is brought by chained done move lines. We double check