Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to add a field in product.product after made some changes in product template ?

By
Anabela Damas
on 11/17/15, 10:00 AM 902 views

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

0
Maurice Agée
On 11/17/15, 12:07 PM

Test without visibility condition

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

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 :

Versão Integral, Anabela Damas
on 11/18/15, 4:03 AM

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

Versão Integral, Anabela Damas
on 11/18/15, 4:51 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/17/15, 10:00 AM
Seen: 902 times
Last updated: 11/18/15, 5:57 AM