[FIX] delivery: update picking weight when product of the move changes

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) <otd@odoo.com>
This commit is contained in:
Djamel Touati
2024-04-05 12:18:16 +00:00
parent 180224ae1d
commit a0235d1e77
2 changed files with 23 additions and 1 deletions
@@ -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')
@@ -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")