This question has been flagged
2 Replies
5650 Views

Hi, 

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'

       @api.model
     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")

    @api.one
    @api.depends('file_name','res_partner_id','document_name_id','state','fleet_vehicle_id')
    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">
<sheet>
<label for="name" class="oe_edit_only" />
<h1>
<field name="name" class="oe_edit_only" />
</h1>
<group>
<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"/>
</group>
<group>
<group>
<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" />
</group>
</group>
<group>
<field name="no_expiration" />
<field name="expiration_id"
attrs="{'invisible':[('no_expiration','=',True)]}"
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" />
</group>
</sheet>
</form>
</field>
</record>
....
<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>
<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> -->
</field>
</field>
</record>
Avatar
Discard

why using 2 classes here?

Author

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.

Author Best Answer

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. 

Avatar
Discard