From 1327022f34255588a9ac553e3948277a81755663 Mon Sep 17 00:00:00 2001 From: Stephane Mangin <stephane.mangin@camptocamp.com> Date: Mon, 31 Oct 2022 10:29:32 +0000 Subject: [PATCH] [FIX] stock: Add readonly constraint on product template in models stock quant/move Avoid unwanted update of product_tmpl_id on product.product Somehow, the field product_tmpl_id on product.product could be updated to an unrelated product template, if the context key `default_product_tmpl_id` is set when an inventory move is created through an update of stock.quant.inventory_quantity. Setting readonly to True on both stock.quant and stock.move product_tmpl_id field prevents this unwanted update. closes odoo/odoo#104602 Signed-off-by: William Henrotin (whe) <whe@odoo.com> --- addons/stock/models/stock_move.py | 2 +- addons/stock/models/stock_quant.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 39bb525ba83f..52d1910f7ef4 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -72,7 +72,7 @@ class StockMove(models.Model): # TDE FIXME: make it stored, otherwise group will not work product_tmpl_id = fields.Many2one( 'product.template', 'Product Template', - related='product_id.product_tmpl_id', readonly=False, + related='product_id.product_tmpl_id', readonly=True, help="Technical: used in views") location_id = fields.Many2one( 'stock.location', 'Source Location', diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index e08bd72583ec..72bedd3b3ce9 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -56,7 +56,7 @@ class StockQuant(models.Model): ondelete='restrict', readonly=True, required=True, index=True, check_company=True) product_tmpl_id = fields.Many2one( 'product.template', string='Product Template', - related='product_id.product_tmpl_id', readonly=False) + related='product_id.product_tmpl_id', readonly=True) product_uom_id = fields.Many2one( 'uom.uom', 'Unit of Measure', readonly=True, related='product_id.uom_id') -- GitLab