From a0235d1e77fc08686df793994aa14eb470e13c74 Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Thu, 28 Mar 2024 15:13:08 +0000 Subject: [PATCH] [FIX] delivery: update picking weight when product of the move changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a storable product “P1” and "P2": - Weight "P1": 1kg - Weight "P2": 2kg - Create a picking with the product “P1” - Change the product of the move to “P2” Problem: The picking weight is not updated opw-3754884 closes odoo/odoo#160215 X-original-commit: 849ece86a6cf49c0a9249ed910aa52add197f431 Signed-off-by: Djamel Touati (otd) --- addons/stock_delivery/models/stock_picking.py | 2 +- .../tests/test_delivery_stock_move.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/addons/stock_delivery/models/stock_picking.py b/addons/stock_delivery/models/stock_picking.py index f73355ee02a..98e1de95fe2 100644 --- a/addons/stock_delivery/models/stock_picking.py +++ b/addons/stock_delivery/models/stock_picking.py @@ -123,7 +123,7 @@ class StockPicking(models.Model): except (ValueError, TypeError): return False - @api.depends('move_ids') + @api.depends('move_ids.weight') def _cal_weight(self): for picking in self: picking.weight = sum(move.weight for move in picking.move_ids if move.state != 'cancel') diff --git a/addons/stock_delivery/tests/test_delivery_stock_move.py b/addons/stock_delivery/tests/test_delivery_stock_move.py index 63841394fa3..a8bc0bd4f40 100644 --- a/addons/stock_delivery/tests/test_delivery_stock_move.py +++ b/addons/stock_delivery/tests/test_delivery_stock_move.py @@ -237,3 +237,25 @@ class StockMoveInvoice(AccountTestInvoicingCommon): done_delivery = sale_order.picking_ids.filtered(lambda p: p.state == "done") self.assertFalse(done_delivery.carrier_id.id, "The shipping method should not be set in done deliveries.") self.assertFalse(return_picking.carrier_id.id, "The shipping method should not set in return pickings") + + def test_picking_weight(self): + """Test if the picking weight is correctly computed when the product of the move changes.""" + self.product_cable_management_box.weight = 1.0 + self.product_a.weight = 2.0 + so = self.SaleOrder.create({ + "partner_id": self.partner_18.id, + "order_line": [(0, 0, { + "name": "Cable Management Box", + "product_id": self.product_cable_management_box.id, + "product_uom_qty": 1, + "product_uom": self.product_uom_unit.id, + "price_unit": 750.00, + })], + }) + so.action_confirm() + picking = so.picking_ids + self.assertEqual(picking.weight, 1.0, "The weight of the picking should be 1.0") + self.product_cable_management_box.weight = 2.0 + self.assertEqual(picking.weight, 1.0, "The weight of the picking should not change") + picking.move_ids.product_id = self.product_a + self.assertEqual(picking.weight, 2.0, "The weight of the picking should be 2.0")