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

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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....

Risposta migliore

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
Abbandona
Autore

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....

Post correlati Risposte Visualizzazioni Attività
2
nov 22
10119
2
lug 17
8707
0
mar 25
1520
4
apr 24
174386
1
feb 24
26