From 324c9f072d22e33705de1caad8813fa560aa709d Mon Sep 17 00:00:00 2001 From: PNO <pno@odoo.com> Date: Wed, 23 Nov 2022 09:16:11 +0000 Subject: [PATCH] [FIX] stock: multi-company check to change product type On the ticket https://github.com/odoo/odoo/pull/101547 a constraint was added to prevent the user from changing the product type if some moves have already been made. This was done because changing the type creates inconsistencies (like breaking the valuation). However, it currently only checks if there are moves on the current company, when it should check in all companies. This can be fixed by adding sudo. closes odoo/odoo#106320 X-original-commit: e8bb4a50aa0d3829d590858784e2c573118bc392 Signed-off-by: William Henrotin (whe) <whe@odoo.com> --- 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 50f3ac8da866..71bc8400adb9 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -863,7 +863,7 @@ class ProductTemplate(models.Model): if 'type' in vals and vals['type'] != 'product' and sum(self.mapped('nbr_reordering_rules')) != 0: raise UserError(_('You still have some active reordering rules on this product. Please archive or delete them first.')) if any('type' in vals and vals['type'] != prod_tmpl.type for prod_tmpl in self): - existing_done_move_lines = self.env['stock.move.line'].search([ + existing_done_move_lines = self.env['stock.move.line'].sudo().search([ ('product_id', 'in', self.mapped('product_variant_ids').ids), ('state', '=', 'done'), ], limit=1) -- GitLab