We have the model "website.support.ticket", with the "partner_id" field. We have the model "crm.lead", with the "partner_id" field. (Two models with one field in common)
The idea is to put a page (dropdown) to the view of crm_lead to see the list of all website_support_tickets related with the partner of the crm_lead current view.
In the xml file we have this code, working fine:
<record id="view_order_form" model="ir.ui.view">
<field name="name">Opportunities Extend</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<page name="lead" position="after">
<page string="Support Tickets">
<field name="support_ticket_lines"/>
</page>
</page>
</field>
</record>
In the python file I have tried to connect the models with a related field:
class crm_lead_extend(models.Model):
_inherit = ['crm.lead']
support_ticket_lines = fields.One2many(related='partner_id.support_ticket_ids')
But it shows an error:
in _setup_related_full field = target._fields[name] KeyError: 'support_ticket_ids'
How can I achieve this?
You got that error because you are expecting that the field support_ticket_ids
exists in the res.partner
model, however, you have not declared it there.
Preserve your code, and add to res.partner
model the following:
class ResPartner(models.Model):
_inherit = 'res.partner'
support_ticket_ids = fields.One2many(
comodel_name='website.support.ticket',
inverse_name='partner_id',
string='Support Ticket Lines',
)