Skip to content
Browse files

[FIX] product: template creation packaging_ids

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

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 a6557a2)
- 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
  • Loading branch information...
kebeclibre committed Apr 24, 2019
1 parent c1f354b commit c0421f390b57f4bc9e9da58c5acdc7f8c9d94d04
Showing with 15 additions and 1 deletion.
  1. +2 −0 addons/product/models/
  2. +13 −1 addons/product/views/product_views.xml
@@ -312,6 +312,8 @@ def create(self, vals):
related_vals['volume'] = vals['volume']
if vals.get('weight'):
related_vals['weight'] = vals['weight']
if vals.get('packaging_ids'):
related_vals['packaging_ids'] = vals['packaging_ids']
if related_vals:
return template
@@ -87,7 +87,7 @@
attrs="{'invisible':['|', ('type', 'not in', ['product', 'consu']), ('product_variant_count', '>', 1)]}"
<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'}"/>
<page string="Notes" name="notes">
@@ -505,6 +505,18 @@

<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">
<!-- Don't forward port in V >= saas-11.5 -->
<xpath expr="//field[@name='product_id']" position="replace"/>
<xpath expr="//field[@name='id']" position="replace"/>

<record model="ir.actions.act_window" id="action_packaging_view">
<field name="name">Product Packages</field>
<field name="res_model">product.packaging</field>

0 comments on commit c0421f3

Please sign in to comment.
You can’t perform that action at this time.