Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Many2one res.partner Filter in CRM module

I am trying to apply a group by on customers in the opportunities section of the CRM module.

I want to group the customers/opportunities on industry.

I have used similar code in res.partner and I cannot work this one out!.

models.py

x_industry_id = fields.Many2one(string="Industry", comodel_name="res.partner")

views.xml

 <record id="view_crm_case_opportunities_filter_inherit" model="ir.ui.view">
    <field name="name">crm.lead.search.opportunity</field>
        <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.view_crm_case_opportunities_filter"/>
    <field name="arch" type="xml">

     <xpath expr="//search" position="inside">

        <filter name="x_industry_id" string="Industry" context="{'group_by':'x_industry_id'}" domain="[('industry_id','!=', False)]"/>

       </xpath>

    </field>
</record>

I am also having the same issue with filters and other groups using the same method.

They just do not appear like normal!

How can I apply Groups and Filters to different models

like image 960
johnashu Avatar asked Mar 22 '19 11:03

johnashu


1 Answers

Remove the domain parameter and put your filter inside the group tag of the search tag, since you are trying to create a group, not a domain filter:

<record id="view_crm_case_opportunities_filter_inherit" model="ir.ui.view">
    <field name="name">crm.lead.search.opportunity</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.view_crm_case_opportunities_filter"/>
    <field name="arch" type="xml">
        <xpath expr="//search/group" position="inside">
            <filter name="x_industry_id" string="Industry" context="{'group_by':'x_industry_id'}"/>
        </xpath>
    </field>
</record>     

In search views there are three kind of filters:

  • Filter by text: allow users to compare a field to some text and find those records which match the expression. They use the field tag and parameters like filter_domain or operator, among others (E.g.: <field name="lost_reason"/>).

  • Filter by domain: allow users to click on the filter you have created and see only the records which match the domain you have specified. They use the filter tag and the domain parameter, among others (E.g.: <filter string="My Pipeline" name="assigned_to_me" domain="[('user_id', '=', uid)]" help="Opportunities that are assigned to me"/>).

  • Filter by group: allow users to group records by a field. They are inside the group tag in a search view, use the filter tag and the context parameter (with the key group_by), among others (E.g.: <filter string="Salesperson" context="{'group_by':'user_id'}"/>).

So I think you are mixing two kinds of filters. That is why you should remove domain.

And of course, check that you have added the crm dependency in the __manifest__.py file, and restarted Odoo service (updating your module) after this.

like image 137
forvas Avatar answered Sep 25 '22 09:09

forvas