Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
2108 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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

Mejor respuesta

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
Descartar
Autor

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

Publicaciones relacionadas Respuestas Vistas Actividad
2
nov 22
9965
2
jul 17
8546
0
mar 25
1221
4
abr 24
173890
1
feb 24
26