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

adding new fields to an inherited form view (product)

By
amina
on 1/12/16, 5:46 AM 1,794 views


I have created a module that inherits from product but adding other new fields doesn't work, after updating it gaves me the error that the field "model_mat" doesn't existe menchening that I have tried the same thing with the partner form view and it worked correctly so what could be wrong with it so here is my files : class.py

class equipement(osv.osv):
    _name='product.product'
    _inherit=['product.product','product.template']
    _columns = {
            'model_mat':fields.char('Model de materiel'), 
            'num_ligne':fields.integer('N° ligne'), 
           }
equipement()

equipement_view.xml

<record id="view_product_form_inherit" model="ir.ui.view">
        <field name="name">product.template.common.form.inherit</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//page[1]" position="inside">
                <group>
                    <field name="model_mat"/>
                    <field name="num_ligne"/>
                </group>
            </xpath>
        </field>
    </record>   

openerp.py

{

"name" : "Gestion Centre Visite Technique",
"version" : "1.0",
"author" : "Amina",
"website" : "Onets.ma",
"category" : "Gestion_Centre",
"depends" : ['base','product','sale'],
"data":[
        'equipement_view.xml',
        'inherit_product.xml',
            ],
"description" : " Ce module vous permet la gestion de votre centre de visite technique",
"installable": "True"

}

inherit_product.xml

<data>
    <record model="ir.actions.act_window" id="product_normal_action_sell">
        <field name="name">Equipements</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.product</field>
        <field name="view_mode">kanban,tree,form</field>
        <field name="view_type">form</field>
        <field name="context">{"search_default_filter_to_sell":1}</field>
        <field name="help" type="html">
          <p class="oe_view_nocontent_create">
            Cliquer pour définir un nouvel article.
          </p><p>
            Un équipement est quelque chose que vous vendez ou achetez. 
            Cela peut être des biens, des consommables ou des services.
          </p>
        </field>
    </record> 
        <menuitem id="cvt" name="Centre visite technique"/>
        <menuitem id="GC" name="Gestion centre" parent="cvt"/>
        <menuitem name="Equipements" action="product_normal_action_sell" id="choix_equipement" parent="GC" sequence="100"/>
</data>

1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 1/12/16, 7:36 AM

Hi,

You may try like this:

class.py:

from openerp import models, fields, api

class equipment(models.Model):

_inherit = 'product.template'

model_mat = fields.Char('Model de materiel')

num_ligne = fields.Integer('N° ligne')

equipment_view.xml:

<openerp>

<data>

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

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

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

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

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

<xpath expr="//page[1]" position="inside">

<group>

<field name="model_mat"/>

<field name="num_ligne"/>

</group>

</xpath>

</field>

</record>

</data>

</openerp>

And please note when you inherit multiple models, use _inherits instead of _inherit. 

Actually, it is perfectly acceptable to have multiple modules in an "inherit". The two (inherits vs. inherits) change the design of the models differently. https://www.odoo.com/documentation/8.0/reference/orm.html#reference-orm-inheritance It is also possible for a model to use both "inherit" and "inherits" to achieve whatever their desired result is.

Htm-Mbs, Travis Waelbroeck
on 5/3/16, 4:13 PM

You are right Travis, it is possible to use _inherit and _inherits together. But when you are inheriting multiple models, can you use like _inherit = 'model.one', 'model.two' ?

Akhil P Sivan
on 5/4/16, 2:32 AM
0
amina
On 1/15/16, 4:22 AM

it worked thankyou,but only after seperating classes in other py file, if I may say that the reason why it was not working earlier is that I have declared 2 classes in the same .py file using different objects and importing from different classes the first one using osv.osv the other one using models.Model and when importing each one's fields there happens the Conflict between the two classes because one is declaring a field.Char and the other one is using field.char which causes "as I think" this error that it was giving me :  odoo AttributeError: 'module' object has no attribute 'char'

so I was doing like this in same file which is uncorrect I think

from openerp import models, fields, api                                                                                                                                                           from openerp.osv import fields, osv

  

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: 1/12/16, 5:46 AM
Seen: 1794 times
Last updated: 1/15/16, 4:22 AM