Hi,
If you want to filter and group by property_product_pricelist on res.partner without storing the field, you need to define a _search method in Python. This tells Odoo how to search on a non-stored computed field, so it can be used in search views for filters and group_by.
Please refer to the code below:
from odoo import models, fields, api
class ResPartner(models.Model):
_inherit = 'res.partner'
property_product_pricelist = fields.Many2one(
comodel_name='product.pricelist',
string="Pricelist",
compute='_compute_product_pricelist',
inverse="_inverse_product_pricelist",
search='_search_property_product_pricelist', # Enable filter/group_by
company_dependent=False,
domain=lambda self: [('company_id', 'in', (self.env.company.id, False))],
)
@api.model
def _search_property_product_pricelist(self, operator, value):
# This assumes the pricelist is stored or linked through some relation
return [('property_product_pricelist', operator, value)]
XML- Filter:
<record id="view_res_partner_filter" model="ir.ui.view">
<field name="name">res.partner.search.inherit.pricelist</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<xpath expr="//filter[@name='user_id']" position="after">
<filter string="Pricelist" name="group_pricelist" domain="[]" context="{'group_by': 'property_product_pricelist'}"/>
</xpath>
</field>
</record>
Hope it helps.