[REF] product: move packaging_ids on product.product
Currently, the packaging of products are set on product.template, which will cause problem if we use vatiants and packaging. So we move the packaging from product.product to have the possibility to have different packaging on different product variant of the same product template.
This commit is contained in:
@@ -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.")
|
||||
|
||||
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<page string="Inventory" name="inventory" groups="stock.group_stock_user,product.group_stock_packaging">
|
||||
<group name="packaging" string="Packaging"
|
||||
colspan="4"
|
||||
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}"
|
||||
attrs="{'invisible':['|', ('type', 'not in', ['product', 'consu']), ('product_variant_count', '>', 1)]}"
|
||||
groups="product.group_stock_packaging">
|
||||
<field name="packaging_ids" nolabel="1"/>
|
||||
</group>
|
||||
@@ -225,6 +225,11 @@
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
<group name="packaging" string="Packaging"
|
||||
colspan="4"
|
||||
groups="product.group_stock_packaging">
|
||||
<field name="packaging_ids" nolabel="1"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
@@ -294,6 +299,9 @@
|
||||
<attribute name="name">lst_price</attribute>
|
||||
<attribute name="attrs">{'readonly': [('product_variant_count', '>', 1)]}</attribute>
|
||||
</field>
|
||||
<group name="packaging" position="attributes">
|
||||
<attribute name="attrs">{'invisible': 0}</attribute>
|
||||
</group>
|
||||
<field name="name" position="after">
|
||||
<field name="product_tmpl_id" class="oe_inline" readonly="1" invisible="1" attrs="{'required': [('id', '!=', False)]}"/>
|
||||
</field>
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
<record id="product_package_jambon" model="product.packaging">
|
||||
<field name="name">box of 10</field>
|
||||
<field name="qty">12</field>
|
||||
<field name="product_tmpl_id" ref="product_product_jambon_product_template" />
|
||||
<field name="qty">10</field>
|
||||
<field name="product_id" ref="product_product_jambon" />
|
||||
</record>
|
||||
|
||||
<record id="product_product_from" model="product.product">
|
||||
@@ -41,8 +41,8 @@
|
||||
</record>
|
||||
<record id="product_package_from" model="product.packaging">
|
||||
<field name="name">Box of 5</field>
|
||||
<field name="qty">12</field>
|
||||
<field name="product_tmpl_id" ref="product_product_from_product_template" />
|
||||
<field name="qty">5</field>
|
||||
<field name="product_id" ref="product_product_from" />
|
||||
</record>
|
||||
|
||||
<record id="product_product_pain" model="product.product">
|
||||
@@ -62,8 +62,8 @@
|
||||
</record>
|
||||
<record id="product_package_pain" model="product.packaging">
|
||||
<field name="name">Bag of 2</field>
|
||||
<field name="qty">6</field>
|
||||
<field name="product_tmpl_id" ref="product_product_pain_product_template" />
|
||||
<field name="qty">2</field>
|
||||
<field name="product_id" ref="product_product_pain" />
|
||||
</record>
|
||||
|
||||
<record id="product_product_lait" model="product.product">
|
||||
@@ -83,8 +83,8 @@
|
||||
</record>
|
||||
<record id="product_package_lait" model="product.packaging">
|
||||
<field name="name">Boxes of 1 liter</field>
|
||||
<field name="qty">4</field>
|
||||
<field name="product_tmpl_id" ref="product_product_lait_product_template" />
|
||||
<field name="qty">1</field>
|
||||
<field name="product_id" ref="product_product_lait" />
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user