[FIX] product: template creation packaging_ids

Create a new product, but don't save it just yet
give it a name,
Add some packagings
Save

Before this commit:
- the form to create the packaging had a mandatory product_id field
which is useless in a x2m context (fixed in v11.5 with a6557a2306)
- the packages disappeared after save
This was because at template creation, all "real" fields that are on
its variants must be manually set after the creation, including packaging_ids

OPW 1970589

closes odoo/odoo#32925

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2019-04-25 07:30:10 +00:00
parent c8fdf32db1
commit f2528a6924
2 changed files with 16 additions and 1 deletions
@@ -312,6 +312,9 @@ class ProductTemplate(models.Model):
related_vals['volume'] = vals['volume']
if vals.get('weight'):
related_vals['weight'] = vals['weight']
# Please do forward port
if vals.get('packaging_ids'):
related_vals['packaging_ids'] = vals['packaging_ids']
if related_vals:
template.write(related_vals)
return template
+13 -1
View File
@@ -87,7 +87,7 @@
colspan="4"
attrs="{'invisible':['|', ('type', 'not in', ['product', 'consu']), ('product_variant_count', '>', 1)]}"
groups="product.group_stock_packaging">
<field name="packaging_ids" nolabel="1" context="{'default_product_id': product_variant_id,'tree_view_ref':'product.product_packaging_tree_view', 'form_view_ref':'product.product_packaging_form_view'}"/>
<field name="packaging_ids" nolabel="1" context="{'default_product_id': product_variant_id,'tree_view_ref':'product.product_packaging_tree_view', 'form_view_ref':'product.product_packaging_form_view2'}"/>
</group>
</page>
<page string="Notes" name="notes">
@@ -505,6 +505,18 @@
</field>
</record>
<!-- Don't forward port in V >= saas-11.5 -->
<record id="product_packaging_form_view2" model="ir.ui.view">
<field name="name">product.packaging.form.view2</field>
<field name="model">product.packaging</field>
<field name="mode">primary</field>
<field name="inherit_id" ref="product.product_packaging_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_id']" position="replace"/>
<xpath expr="//field[@name='id']" position="replace"/>
</field>
</record>
<record model="ir.actions.act_window" id="action_packaging_view">
<field name="name">Product Packages</field>
<field name="res_model">product.packaging</field>