Odoo Help


View extension and model inheritance

Sebastián Seifert
on 11/8/16, 3:02 PM 670 views


I´m trying to create a base module with some other modules extending it, and adding more functionality to this base module.

In order to extend de base module, I´m using inheritance without changing the _name field, using only the field _inherit. (I´ll copy my code at the end).

To extend the views of the model I´m using extension inheritance.

Everything works fine the first time I install all modules, but when I try to update the base module, the server will throw and exception because it can´t find the fields from the subclases for the already extended view.

I´ve managed to make it work running an sql script that erase this views. But i would like not to do that, just get the base module updated clicking on the update button of the module. 

I´ll copy my code now.

class document(models.Model):
     _name = 'document_control_base.document'

     def _get_resources_list(self):
            model_obj = self.env['document_control_base.resource_type']
            return model_obj._get_resources_list()
       STATE_SELECTION = [('active', 'Vigente'),('to_expire', 'Proximo a vencer'),('expired', 'Vencido')]

      name = fields.Char("Nombre",readonly=True,store=True,compute='_compute_name')
  document_name_id = fields.Many2one("document_control_base.document_name","Nombre del documento")
document_condition_ids = fields.Many2many("document_control_base.document_condition", "document_condition_rel", "document_id", "condition_id", "Condiciones del documento")
res_partner_id = fields.Many2one("res.partner",string="Empresa/Recurso Externo")

class document(models.Model):
    _inherit = 'document_control_base.document'
    fleet_vehicle_id = fields.Many2one("fleet.vehicle",string="Vehiculo")

    def _compute_name(self):
        super(document, self)._compute_name()
    resid = self.fleet_vehicle_id.name if self.fleet_vehicle_id.name else ''
    self.name = resid.title() + self.name
<record id="document_control_base.document_form" model="ir.ui.view">
<field name="model">document_control_base.document</field>
<field name="arch" type="xml">
<form string="Documentos">
<label for="name" class="oe_edit_only" />
<field name="name" class="oe_edit_only" />
<field name="res_type" class="oe_edit_only oe_inline" widget="radio"/>
<field name="res_partner_id" domain="['|','&amp;','&amp;','&amp;',('is_company', '=', False),('parent_id', '!=', False),
('active', '=', True),('employee','=',False),'&amp;','&amp;','&amp;',('is_company', '=', True),('parent_id', '=', False),('active', '=', True),('employee','=',False)]"
attrs="{'invisible':[('res_type', '!=', 'res.partner')]}" class="oe_edit_only"/>
<field name="file_binary" filename="file_name" />
<field name="file_name" class="oe_inline oe_right" invisible="1" />
<field name="document_name_id" domain="[('res_type','=',res_type)]"/>
<field name="document_condition_ids" widget="many2many_tags" />
<field name="description" />
<field name="no_expiration" />
<field name="expiration_id"
context="{'form_view_ref': 'document_control_base.expiration_form','resources':'expirations','name':'Vencimiento:','res_partner_id':res_partner_id,'document_name_id':document_name_id}" />
<field name="in_renewal" />
<field name="state" readonly="1" class="oe_edit_only" />
<record model="ir.ui.view" id="document_control_base.document_form_fleet">
<field name="model">document_control_base.document</field>
<field name="inherit_id" ref="document_control_base.document_form" />
<field name="arch" type="xml">
<field name="res_partner_id" position="after">
<label for="fleet_vehicle_id" attrs="{'invisible':[('res_type', '!=', 'fleet.vehicle')]}" class="oe_edit_only" />
<field name="fleet_vehicle_id" attrs="{'invisible':[('res_type', '!=', 'fleet.vehicle')]}" class="oe_edit_only"/>
<field name="expiration_id" position="attributes">
<attribute name="context">{'form_view_ref': 'document_control_base.expiration_form','resources':'expirations','name':'Vencimiento:','res_partner_id':res_partner_id,'fleet_vehicle_id':fleet_vehicle_id,'document_name_id':document_name_id}</attribute><!-- <attribute name="context" add=" py.PY_setItem(py.evaluate(expr.first, context),'fleet_vehicle_id', fleet_vehicle_id)" separator=" "></attribute> -->

why using 2 classes here?

Ameera PP
on 11/8/16, 10:40 PM

The first is from the base module. The second is from the extending module, there are several modules extending the base class. Fleet is only one. And their are installed separately. I can´t erase the answer. Sorry.

Sebastián Seifert
on 11/9/16, 8:02 AM
Sebastián Seifert
On 11/9/16, 8:01 AM

The first is from the base module. The second is from the extending module, there are several modules extending the base class. Fleet is only one. And their are installed separately. 

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/8/16, 3:02 PM
Seen: 670 times
Last updated: 11/9/16, 8:01 AM