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")