From 1b76e2835d63f5c6e9f39f4e53a501e873e91e2d Mon Sep 17 00:00:00 2001 From: "Mahdi cheikh rouhou (macr)" Date: Mon, 27 Mar 2023 09:20:44 +0000 Subject: [PATCH] [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 Signed-off-by: Mahdi Cheikh Rouhou (macr) --- addons/stock/models/stock_move.py | 4 +--- addons/stock/tests/test_move.py | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 30844ab6da9..5fe1712add2 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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): diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index f45ac2cea10..5c816e82b6c 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -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({