[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
This commit is contained in:
committed by
Simon Lejeune
parent
900f0175db
commit
42e6396d4a
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user