Can you help me understand how inheritance by delegation works ? I've implemented the following:
# Generic service base model
class business_services(osv.Model):
_name = "business.services"
_description = "Business Services"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_columns = {
'name': fields.char('Service name', size=64, required=True),
...
}
business_services()
# Specific service model
class business_service_service1(osv.Model):
_name = 'business.service.service1'
_inherits = {'business.services': 'service_id'}
_columns = {
'service_id': fields.many2one('business.services', 'Service ID',required=False,ondelete='cascade'),
... (other specific service1 columns)
}
business_service_service1()
class business_service_service2(osv.Model):
_name = 'business.service.service2'
_inherits = {'business.services': 'service_id'}
_columns = {
'service_id': fields.related('service_id','business_services_id',type="many2one",relation="business.services",string="Service ID",required=False,ondelete='cascade'),
... (other specific service2 columns)
}
business_service_service2()
I'm instantiating a new service thanks to a wizard that opens the proper view :
def action_view_business_services_add(self, cr, uid, ids, context=None):
switch...
res = {
'name': 'Services',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'business.service.service1',
'view_id': False,
'type': 'ir.actions.act_window',
# 'context': "{'service_id':active_id}",
}
return res
This works fine, except for the relation between the _inheritsed object and its parent. I read on the doc that when one _inheritS a model, the instantation process populates the parent's table. In my case, the 'service_id' field never gets populated automatically :
- The field is turned to required=True by the system
- If I don't place the field, a field is created with name "Automatically created field to link to parent"
My problem is that at the moment, the system asks me to populate the field 'service_id' by hand. I would like it to have its value automatically set.
I see that there is such an implementation in product_template with field 'product_tmpl_id' acting as the foreign key, but i don't understand how it gets populated.
As in service2 in my example, i've seen that some implementations use a 'related' field, but i get no luck this way either. What's the proper way to achieve this ?
Thank you