From 0cae6b06be55f9d101e1220044988c3d3dbfe16c Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Fri, 1 Sep 2023 15:44:33 +1000 Subject: [PATCH] [FIX] stock: change UOM on product block - multi company There is code to block the UOM changing if there are done moves. Because it searches in non-sudo mode, it does NOT currently stop you changing the UOM if the product has moves in a different company. closes odoo/odoo#134900 X-original-commit: 426744646c25e8c2b17e3a50de186bd91b5e645f Signed-off-by: Tiffany Chang (tic) --- addons/stock/models/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index acc3d8e6523..fec3f0e6bc3 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -862,7 +862,7 @@ class ProductTemplate(models.Model): if 'uom_id' in vals: new_uom = self.env['uom.uom'].browse(vals['uom_id']) updated = self.filtered(lambda template: template.uom_id != new_uom) - done_moves = self.env['stock.move'].search([('product_id', 'in', updated.with_context(active_test=False).mapped('product_variant_ids').ids)], limit=1) + done_moves = self.env['stock.move'].sudo().search([('product_id', 'in', updated.with_context(active_test=False).mapped('product_variant_ids').ids)], limit=1) if done_moves: raise UserError(_("You cannot change the unit of measure as there are already stock moves for this product. If you want to change the unit of measure, you should rather archive this product and create a new one.")) if 'type' in vals and vals['type'] != 'product' and sum(self.mapped('nbr_reordering_rules')) != 0: