This question has been flagged

Hi, 

I am trying to understand the connection of product.template to the product.product. 

I read in some question that : 

If you add a field to product.template (template), then the field value will be shared to all variants (product.product) of that template.
If you add a field to product.product (variant), then the field value will be different in each variant of the same template (product.template)

This make sense to me, and I add some fields in template that I wanted the value to be the same in all variants (product.product): 

class product_template(osv.osv):

_inherit = 'product.template'

_columns = {

'date': fields.boolean('Date'),

'date_start': fields.date('Date Start),

'date_stop': fields.date('Date Stop),
}


<record id="product_template_form_view_inherit" model="ir.ui.view">

<field name="name">product.template.inherit.form</field>

<field name="model">product.template</field>

<field name="inherit_id" ref="product.product_template_form_view"/>

<field name="arch" type="xml">

<div name="options" position="after">

<div class="oe_left" name="options" groups="base.group_user">

<div>

<field name="date"/>

<label for="date"/>

</div>

</div>

</div>

<xpath expr="/form/sheet/notebook/page[@string='Information']" position='after'>

<page name="date" string="Dates" attrs="{'invisible': [ ('date','=',False)]}" >

<group>

<group>

<field name="date_start"/>

<field name="date_stop"/>

</group>

</group>

</page>

</xpath>

</field>

</record>

But now I'm trying to add a field that I want to be specific for each variant (product.product). And I want to put the field in the page  ("date") that I added before to product.template. 

I tried like this :

<record id="product_normal_form_view_inherit" model="ir.ui.view">
<field name="name">product.normal.inh.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
 <xpath expr="/form/sheet/notebook/page[@string='Dates']" position='inside'>
<field name="stock_discount"/>
</xpath>
</field>
</record>

ERROR: 

Error details:
Element '<xpath expr="/form/sheet/notebook/page[@string='Dates']">' cannot be located in parent view

Error context:
View `product.normal.inh.form`
[view_id: 1224, xml_id: n/a, model: product.product, parent_id: 477]" while parsing /opt/odoo/openerp/addon/change_product/product_view.xml:103,


Now I try this: 

<record id="product_normal_form_view_inherit" model="ir.ui.view">
   <field name="name">product.normal.inh.form</field>
            <field name="model">product.product</field>
            <field eval="57" name="priority"/>
            <field name="inherit_id" ref="product_template_form_view_inherit"/>
            <field name="arch" type="xml">
	        <xpath expr="/form/sheet/notebook/page[@string='Dates']" position='inside'>
		    <group>
			<field name="stock_discount"/>
		    </group>
		</xpath>
	    </field>
       </record>

And with this code I don't have any error but I also doesn't have the field in the view.... 

How can I put the new field of product.product in the new page of product.template? 

Thanks

Avatar
Discard
Best Answer

Test without visibility condition

                page name="date" string="Dates" attrs="{'invisible': [ ('date','=',False)]}

Avatar
Discard
Author

I tried that but the error is the same... I think is because I add the page to product.template and I'm trying to inherit the product.product.... I really don't know what view to inherit to add the new field to the new page ... I think the error is in this line :

Author

field name="inherit_id" ref="product.product_normal_form_view"