diff --git a/addons/sale/models/sale_order_line.py b/addons/sale/models/sale_order_line.py index 0fde107d632..fc15a5abe73 100644 --- a/addons/sale/models/sale_order_line.py +++ b/addons/sale/models/sale_order_line.py @@ -617,7 +617,7 @@ class SaleOrderLine(models.Model): # Find biggest suitable packaging if line.product_id and line.product_uom_qty and line.product_uom: line.product_packaging_id = line.product_id.packaging_ids.filtered( - 'sales')._find_suitable_product_packaging(line.product_uom_qty, line.product_uom) + 'sales')._find_suitable_product_packaging(line.product_uom_qty, line.product_uom) or line.product_packaging_id @api.depends('product_packaging_id', 'product_uom', 'product_uom_qty') def _compute_product_packaging_qty(self): diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index 4b7da8a0e3c..7b60abbd877 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1292,3 +1292,26 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): so.order_line.product_uom_qty = 8 self.assertRecordValues(so.picking_ids, [{'location_id': warehouse.lot_stock_id.id, 'location_dest_id': customer_location.id}]) self.assertEqual(so.picking_ids.move_ids.product_uom_qty, 8) + + def test_packaging_and_qty_decrease(self): + packaging = self.env['product.packaging'].create({ + 'name': "Super Packaging", + 'product_id': self.product_a.id, + 'qty': 10.0, + }) + + so_form = Form(self.env['sale.order']) + so_form.partner_id = self.partner_a + with so_form.order_line.new() as line: + line.product_id = self.product_a + line.product_uom_qty = 10 + so = so_form.save() + so.action_confirm() + + self.assertEqual(so.order_line.product_packaging_id, packaging) + + with Form(so) as so_form: + with so_form.order_line.edit(0) as line: + line.product_uom_qty = 8 + + self.assertEqual(so.picking_ids.move_ids.product_uom_qty, 8)