diff --git a/addons/product/models/product.py b/addons/product/models/product.py index fd75d899983..63fac183442 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -163,6 +163,10 @@ class ProductProduct(models.Model): pricelist_item_ids = fields.Many2many( 'product.pricelist.item', 'Pricelist Items', compute='_get_pricelist_items') + packaging_ids = fields.One2many( + 'product.packaging', 'product_id', 'Packaging', + help="Gives the different ways to package the same product.") + _sql_constraints = [ ('barcode_uniq', 'unique(barcode)', _("A barcode can only be assigned to one product !")), ] @@ -572,7 +576,7 @@ class ProductPackaging(models.Model): name = fields.Char('Packaging Type', required=True) sequence = fields.Integer('Sequence', default=1, help="The first in the sequence is the default one.") - product_tmpl_id = fields.Many2one('product.template', string='Product') + product_id = fields.Many2one('product.product', string='Product') qty = fields.Float('Quantity per Package', help="The total number of products you can have per pallet or box.") diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 8e9b20dddfb..0ff3fc873cc 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -100,9 +100,8 @@ class ProductTemplate(models.Model): 'res.company', 'Company', default=lambda self: self.env['res.company']._company_default_get('product.template'), index=1) packaging_ids = fields.One2many( - 'product.packaging', 'product_tmpl_id', 'Logistical Units', - help="Gives the different ways to package the same product. This has no impact on " - "the picking order and is mainly used if you use the EDI module.") + 'product.packaging', string="Packaging", compute="_compute_packaging_ids", inverse="_set_packaging_ids", + help="Gives the different ways to package the same product.") seller_ids = fields.One2many('product.supplierinfo', 'product_tmpl_id', 'Vendors') active = fields.Boolean('Active', default=True, help="If unchecked, it will allow you to hide the product without removing it.") @@ -246,6 +245,17 @@ class ProductTemplate(models.Model): if len(self.product_variant_ids) == 1: self.product_variant_ids.default_code = self.default_code + @api.depends('product_variant_ids', 'product_variant_ids.packaging_ids') + def _compute_packaging_ids(self): + for p in self: + if len(p.product_variant_ids) == 1: + p.packaging_ids = p.product_variant_ids.packaging_ids + + def _set_packaging_ids(self): + for p in self: + if len(p.product_variant_ids) == 1: + p.product_variant_ids.packaging_ids = p.packaging_ids + @api.constrains('categ_id') def _check_category(self): if self.categ_id.type == 'view': diff --git a/addons/product/views/product_views.xml b/addons/product/views/product_views.xml index e1a93ae861a..4766c18c734 100644 --- a/addons/product/views/product_views.xml +++ b/addons/product/views/product_views.xml @@ -62,7 +62,7 @@ @@ -225,6 +225,11 @@ + + + @@ -294,6 +299,9 @@ lst_price {'readonly': [('product_variant_count', '>', 1)]} + + {'invisible': 0} + diff --git a/addons/product_expiry/data/product_expiry_demo.xml b/addons/product_expiry/data/product_expiry_demo.xml index c034f12c006..851c9ba1b24 100644 --- a/addons/product_expiry/data/product_expiry_demo.xml +++ b/addons/product_expiry/data/product_expiry_demo.xml @@ -20,8 +20,8 @@ box of 10 - 12 - + 10 + @@ -41,8 +41,8 @@ Box of 5 - 12 - + 5 + @@ -62,8 +62,8 @@ Bag of 2 - 6 - + 2 + @@ -83,8 +83,8 @@ Boxes of 1 liter - 4 - + 1 +