[FIX] stock : update UoM of SM on product change

An error appears when we try to change the product in transfer line via
product/search

steps to reproduce the error :
1- create 2 products : Test 1 (UoM is Cm) and Test 2 (Uom is g)
2- create a delivery order and add Test 1
3- UoM error due to the UoM not being updated at the time of change

The error was happening because when updating the product directly in
the line section , the stock_move item already has a UoM and the if
statement makes it impossible to change it , so the error appears.

opw-3231298

closes odoo/odoo#117504

X-original-commit: ece3dea8c1ab43a854a57513cc317e8618010542
Signed-off-by: Adrien Widart <awt@odoo.com>
Signed-off-by: Mahdi Cheikh Rouhou (macr) <macr@odoo.com>
This commit is contained in:
Mahdi cheikh rouhou (macr)
2023-04-05 13:57:50 +02:00
parent 29d55e4403
commit 1b76e2835d
2 changed files with 10 additions and 3 deletions
+1 -3
View File
@@ -189,9 +189,7 @@ class StockMove(models.Model):
@api.depends('product_id')
def _compute_product_uom(self):
for move in self:
if not move.product_uom:
move.product_uom = move.product_id.uom_id.id
move.product_uom = move.product_id.uom_id.id
@api.depends('has_tracking', 'picking_type_id.use_create_lots', 'picking_type_id.use_existing_lots', 'state')
def _compute_display_assign_serial(self):
+9
View File
@@ -5976,6 +5976,15 @@ class StockMove(TransactionCase):
})
self.assertEqual(move.product_uom, self.product.uom_id)
self.assertEqual(move.move_line_ids.product_uom_id, self.product.uom_id)
uom_kg = self.env.ref('uom.product_uom_kgm')
product1 = self.env['product.product'].create({
'name': 'product1',
'type': 'product',
'uom_id': uom_kg.id,
'uom_po_id': uom_kg.id
})
move.product_id = product1
self.assertEqual(move.product_uom, product1.uom_id)
def test_move_line_compute_locations(self):
stock_location = self.env['stock.location'].create({