I have an issue where columns are not sortable on certain related fields.
I have extended the res.partner form with the following code snippet:
class CrmProject(models.Model):
_name = 'crm.project'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_inherits = {
'res.partner': 'partner_id',
}
_order = "name asc"
@api.model
def _get_domain_employee(self):
ids = self.env.ref('aim_contacts.res_partner_business_2').ids
return [('business_id', '=', ids)]
.
.
industry_id = fields.Many2one('crm.project.industry', 'Construction Type')
I have extended the sales/opportunity module with the following snippet:
class CrmOpportunity(models.Model):
_name = 'crm.opportunity'
_inherit = ['mail.thread', 'ir.needaction_mixin', 'aim.res.common']
_order = 'name asc'
@api.model
def _get_domain_employee(self):
ids = self.env.ref('aim_contacts.res_partner_business_2').ids
return [('business_id', '=', ids)]
name = fields.Char('Topic', required=True)
.
.
crm_project_id = fields.Many2one('crm.project', 'Project', track_visibility='onchange')
industry_id = fields.Many2one('crm.project.industry', 'Construction Type',related='crm_project_id.industry_id', readonly=True)
The view is defined as follows:
<record id="crm_opportunity_tree_view" model="ir.ui.view">
<field name="name">crm.opportunity.tree.view</field>
<field name="model">crm.opportunity</field>
<field name="arch" type="xml">
<tree string="Opportunities">
<field name="name" string="Topic" invisible="1"/>
<field name="crm_project_id"/>
<field name="industry_id"/>
</tree>
</field>
</record>
Issue 1: When the opportunities page is loaded, clicking on the "Construction Type" (industry_id) header does nothing.
Issue 2: Also, when clicking on the "Project" (crm_project_id) header, the column is sorted by id rather than name (even though it is displaying name).
I thought issue 2 could be resolved by adding to crm.project.py:
_order = "name asc"
but it did not work.
Any help would be greatly appreciated.
Update
The method of adding store=True to related fields works. There is an issue though that if the field is already created, then it will/may not update with the most resent data.
To get around this, I created another field with the same information as the original, and then linked to it. I have read that others drop the fields and create them again.