Hi, I'm trying to create a custom filter to divide contacts into 3 categories:
1st is a client
2nd is a prospect
3° It is contact.
This is the code I am using.
is_client = fields.Boolean(compute='_customize_filter', string="Es un cliente")
is_prospect = fields.Boolean(compute='_customize_filter', string="Es un prospecto")
is_contact = fields.Boolean(compute='_customize_filter', string="Es un contacto")
def _customize_filter(self):
for partner in self:
partner.is_prospect = True
partner.is_client = partner.total_invoiced > 0
partner.is_contact = bool(partner.parent_id)
if partner.sale_order_count > 0:
if partner.total_invoiced == 0 and not partner.is_client:
partner.is_prospect = True
else:
partner.is_prospect = False
else:
partner.is_prospect = False
In res.partner there are 3 fields (which are in a bar) called total_invoiced, sale_order_count and parent_id...
What I'm trying to do is the following...
If the contact has sales but no invoices made, the lead boolean will be activated.
2° If the contact has sales and has invoices, the boolean of he is a customer will be activated, but the boolean of is a prospect will be deactivated (because when he already has invoices made, he already becomes a customer).
3° If the contact has a sub-contact, the sub-contact will activate the boolean of that contact.
The condition works perfectly, but where the problem comes from is when doing the filtering.
This is my xml code (just try to do the client filter)
id="filter_register" model="ir.ui.view">
name="name">res.partner
name="model">res.partner
name="inherit_id" ref="base.view_res_partner_filter"/>
name="arch" type="xml">
expr="//search/separator" position="after">
domain="[('is_client','=',True)]" name="is_client" string="Es un cliente PRUEBA"/>
But the filter doesn't work like that...
If I set the store=True to the boolean fields it doesn't work either, since locally at the moment of reloading the page, the log gets stuck and no longer advances...
Is there a way that I can create this filter for the 3 boolean fields?
Or if there is a module that already activates the boolean fields automatically and allows me to make filters...
Since the modules I found do not have a condition in which the fields are automatically activated...
Thank you.