Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
3141 Visualizzazioni

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.

Avatar
Abbandona
Risposta migliore

Hello Learning_Odoo,

Please find code in comment. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Abbandona

lease find below code it may help you to resolve this issue,

<record id="inherit_view_res_partner_filter" model="ir.ui.view">
<field name="name">res.partner.select</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<xpath expr="//search//filter[@name='type_company']" position="after">
<filter name="is_client" string="Es un cliente PRUEBA" domain="[('is_client', '!=', False)]"/>
</xpath>
</field>
</record>

Risposta migliore

Hi,

If you are making the field as stored fields, you should add proper dependencies to the compute function, so that the function will get recalculated when the dependencies get changed.  

So you have to check and see, whether proper dependencies can be added so that it can be made as storable field.

If it cannot be made as stored field, other option to define the search functions for the field. See:  Searchable Non Stored Compute Field In Odoo


Thanks

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
mar 25
877
2
giu 25
9222
2
feb 24
1607
1
ott 17
3334
1
lug 25
1540