Skip to Content
Menu
This question has been flagged
2 Replies
24833 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>

Avatar
Discard
Best Answer

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. 

Avatar
Discard

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.

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' ?

Author Best Answer

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

  

Avatar
Discard
Related Posts Replies Views Activity
3
Aug 24
5498
4
Jul 24
38806
5
Apr 23
93701
3
Nov 22
2953
3
Aug 22
3037