Skip to Content
Menu
This question has been flagged
2 Replies
2094 Views

I am working from the customer section in the sales module, I have this code.  


is_client = fields.Boolean(compute='_customize_filter', string="is a cliente")


is_prospect= fields.Boolean(compute='_customize_filter', string="is a prospect")


is_contact = fields.Boolean(compute='_customize_filter', string="is a contact")


def _customize_filter(self):

     for partner in self:

          partner.is_client = True if partner.total_invoiced > 0 else False 

          partner.is_prospect = True if partner.sale_order_count > 0 else False 

         partner.is_contact = True if partner.parent_id else False 


How can I put a double validation in the is_prospect field to tell it to deactivate if the is_client field is True and only activate if it has sales but no invoices?


Odoo 13 community, thank you.






Avatar
Discard
Best Answer

HI,

Try with this code:

def _customize_filter(self):
for partner in self:
partner.is_client = True if partner.total_invoiced > 0 else False
partner.is_prospect = True if partner.sale_order_count > 0 and partner.total_invoiced == 0 else False
partner.is_contact = True if partner.parent_id else False


Thanks

Avatar
Discard
Author

Hello, thanks for answering.. What I am trying to do is a filter of the clients in the sales module, where if the contact has neither sales nor invoices, no boolean will be activated, if the contact only has sales, the lead boolean will be activated, if the contact has invoices it will be activated the boolean of client... my question here is... Can I use those fields that are in res.partner to be able to do filtering? Since in the view try to apply a filter domain in the client, but it doesn't work... In the booleans I already put a store=True to store the value in the database, but it still doesn't work, I appreciate your answer....

Best Answer

Hi,

You can modify your _customize_filter function to include the double validation for the is_prospect field. Here's an updated version of the function:

def _customize_filter(self):
for partner in self:
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

Regards

Avatar
Discard
Author

Hello, thanks for answering.. What I am trying to do is a filter of the clients in the sales module, where if the contact has neither sales nor invoices, no boolean will be activated, if the contact only has sales, the lead boolean will be activated, if the contact has invoices it will be activated the boolean of client... my question here is... Can I use those fields that are in res.partner to be able to do filtering? Since in the view try to apply a filter domain in the client, but it doesn't work... In the booleans I already put a store=True to store the value in the database, but it still doesn't work, I appreciate your answer....

Related Posts Replies Views Activity
2
Nov 22
9952
2
Jul 17
8515
0
Mar 25
1189
4
Apr 24
173806
1
Feb 24
26