From fac4127470a670a7d2ca9364514f85fd9e70711e Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 16 Oct 2015 10:42:32 +0200 Subject: [PATCH] [IMP] product: Change 'default_code' to a compute field Goal : Don't display the internal reference from one of the product template as it was currently the case, because it was a related field to a one2many. Here, we use the same behavior as for weight,volume or standard price fields. If only 1 variant, i.e. no variant used, take the default_code from the template If more than 1 variant, do not display anything. --- addons/product/product.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/product/product.py b/addons/product/product.py index 798d8101565..027d3684ad1 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -512,7 +512,11 @@ class product_template(osv.osv): # related to display product product information if is_product_variant 'barcode': fields.related('product_variant_ids', 'barcode', type='char', string='Barcode', oldname='ean13'), - 'default_code': fields.related('product_variant_ids', 'default_code', type='char', string='Internal Reference'), + 'default_code': fields.function(_compute_product_template_field, fnct_inv=_set_product_template_field, multi='_compute_product_template_field', type='char', string='Internal Reference', store={ + _name: (lambda s,c,u,i,t: i, ['product_variant_ids'], 10), + 'product.product': (_get_template_id_from_product, ['product_tmpl_id', 'default_code'], 10), + }), + 'item_ids': fields.one2many('product.pricelist.item', 'product_tmpl_id', 'Pricelist Items'), }