diff --git a/addons/purchase_stock/tests/test_purchase_order.py b/addons/purchase_stock/tests/test_purchase_order.py index b602447e8dc..8d25ec146b5 100644 --- a/addons/purchase_stock/tests/test_purchase_order.py +++ b/addons/purchase_stock/tests/test_purchase_order.py @@ -630,3 +630,12 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon): wizard = self.env['stock.inventory.adjustment.name'].create({'quant_ids': quant}) wizard.action_apply() self.assertEqual(quant.quantity, 5) + + def test_po_edit_after_receive(self): + self.po = self.env['purchase.order'].create(self.po_vals) + self.po.button_confirm() + self.po.picking_ids.move_ids.quantity_done = 5 + self.po.picking_ids.button_validate() + self.assertEqual(self.po.picking_ids.move_ids.mapped('product_uom_qty'), [5.0, 5.0]) + self.po.with_context(import_file=True).order_line[0].product_qty = 10 + self.assertEqual(self.po.picking_ids.move_ids.mapped('product_uom_qty'), [5.0, 5.0, 5.0]) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 5267ec3f3a9..bba1ad7d4ea 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -313,8 +313,6 @@ class StockMoveLine(models.Model): # If this picking is already done we should generate an # associated done move. for move_line in mls: - if self.env.context.get('import_file') and move_line.reserved_uom_qty and not move_line._should_bypass_reservation(move_line.location_id): - raise UserError(_("It is not allowed to import reserved quantity, you have to use the quantity directly.")) if move_line.move_id or not move_line.picking_id: continue if move_line.picking_id.state != 'done': @@ -364,6 +362,9 @@ class StockMoveLine(models.Model): move.with_context(avoid_putaway_rules=True).product_uom_qty = move.quantity_done for ml, vals in zip(mls, vals_list): + if self.env.context.get('import_file') and ml.reserved_uom_qty and not ml.move_id._should_bypass_reservation(): + raise UserError(_("It is not allowed to import reserved quantity, you have to use the quantity directly.")) + if ml.state == 'done': if ml.product_id.type == 'product' and not self.env.context.get('bypass_reservation_update'): Quant = self.env['stock.quant']