From 42e6396d4a62340540a14f6252032f64d315be86 Mon Sep 17 00:00:00 2001 From: Parth Choksi Date: Mon, 24 Jun 2019 07:08:10 +0000 Subject: [PATCH] [IMP] product: barcode should not disappear on archiving product Before this commit when a user archives the product, the barcode field in its template used to get disappeared. Since barcode field in template is a related field to product, the field gets invisible in product template when the user archives the related product. After this commit, even when a product is archived, its barcode will still be visible in template. Here the barcode field is changed from related to computed. task-1978559 --- addons/product/models/product_template.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index eee7ae100b3..8ae4e807f75 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -130,7 +130,7 @@ class ProductTemplate(models.Model): '# Product Variants', compute='_compute_product_variant_count') # related to display product product information if is_product_variant - barcode = fields.Char('Barcode', related='product_variant_ids.barcode', readonly=False) + barcode = fields.Char('Barcode', compute='_compute_barcode', inverse='_set_barcode', search='_search_barcode') default_code = fields.Char( 'Internal Reference', compute='_compute_default_code', inverse='_set_default_code', store=True) @@ -262,6 +262,21 @@ class ProductTemplate(models.Model): for template in self: template.is_product_variant = False + @api.depends('product_variant_ids.barcode') + def _compute_barcode(self): + self.barcode = False + for template in self: + if len(template.product_variant_ids) == 1: + template.barcode = template.product_variant_ids.barcode + + def _search_barcode(self, operator, value): + templates = self.with_context(active_test=False).search([('product_variant_ids.barcode', operator, value)]) + return [('id', 'in', templates.ids)] + + def _set_barcode(self): + if len(self.product_variant_ids) == 1: + self.product_variant_ids.barcode = self.barcode + @api.model def _get_weight_uom_id_from_ir_config_parameter(self): """ Get the unit of measure to interpret the `weight` field. By default, we considerer