From 88a9074345f5dcc45b7ed5ef01d6dd1f16cc8aa8 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Tue, 25 Jul 2023 08:37:42 +0000 Subject: [PATCH] [FIX] sale_stock: update SO line with import Creates a sale order, then validates the delivery. Modify the sale order lines qty via import. We expect a new delivery instead we have a UserError The purpose of the userError is to avoid editing reserved quantity directly in the picking. But in SO/PO case it's handle by the system and quantities are correctly reserved so the UserError should not happens. Remove the basic constraint on stock since it should not be an issue anymore opw-3336131 closes odoo/odoo#130870 X-original-commit: 87f62c90e703049bde8676663851a98e3b19f9db Signed-off-by: Tiffany Chang (tic) Signed-off-by: Arnold Moyaux (arm) --- addons/sale_stock/tests/test_sale_stock.py | 26 ++++++++++++++++++++++ addons/stock/i18n/stock.pot | 9 -------- addons/stock/models/stock_move_line.py | 3 --- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index 97c2f0e4e8d..e8b424c96e6 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1184,6 +1184,32 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): self.assertEqual(so.order_line[1].qty_delivered, 1) self.assertEqual(so.order_line[1].product_uom.id, uom_km_id) + def test_19_deliver_update_so_line_qty(self): + """ + Creates a sale order, then validates the delivery + modifying the sale order lines qty via import and ensures + a new delivery is created. + """ + self.product_a.type = 'product' + self.env['stock.quant']._update_available_quantity( + self.product_a, self.company_data['default_warehouse'].lot_stock_id, 10) + + # Create sale order + sale_order = self._get_new_sale_order() + sale_order.action_confirm() + + # Validate delivery + picking = sale_order.picking_ids + picking.move_ids.write({'quantity_done': 10}) + picking.button_validate() + + # Update the line and check a new delivery is created + with Form(sale_order.with_context(import_file=True)) as so_form: + with so_form.order_line.edit(0) as line: + line.product_uom_qty = 777 + + self.assertEqual(len(sale_order.picking_ids), 2) + def test_multiple_returns(self): # Creates a sale order for 10 products. sale_order = self._get_new_sale_order() diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index 50826bda4e0..2e243127aef 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -3820,15 +3820,6 @@ msgstr "" msgid "Is quantity done editable" msgstr "" -#. module: stock -#. odoo-python -#: code:addons/stock/models/stock_move_line.py:0 -#, python-format -msgid "" -"It is not allowed to import reserved quantity, you have to use the quantity " -"directly." -msgstr "" - #. module: stock #. odoo-python #: code:addons/stock/models/stock_quant.py:0 diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 8985cd50264..c62d798451d 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -362,9 +362,6 @@ 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']