Skip to Content
Menu
This question has been flagged
3 Replies
4296 Views

This question is for V11 CE.  In the business I work for, many of our contacts are not customers, but suppliers or donators (a custom field added to the res.partner).  Our users can often forget to deselect that boolean field and select the right one, which means contacts don't show up correctly in filtered lists. 

Consequently, I would like I want to modify the Contact creation process so that the customer boolean field (Is a Customer) is not set to True by default.  How can I do this?  I would also like it to happen when using the 'Convert to Task' button that is created when the 'Lead to Tasks' (crm_project) module is installed.  This process creates a new contact that also has the customer boolean set to True, though I am guessing it uses the same process that creating a new contact from the Contacts menu does.

Also, I would like it if at least one of the customer, supplier or donator booleans must be set to True before a new contact can be saved, to prevent users creating contacts that don't belong to any of the contact types.

Avatar
Discard
Best Answer

Hi,

You can remove the deafult=True from the field, or make default=False

customer = fields.Boolean(string='Is a Customer', default=False,
help="Check this box if this contact is a customer.")


Then to prevent the saving of record without ticking customer, supplier or your third field. Add a constrain for the model res.partner.

@api.constrains('customer', 'supplier', 'third_field')
def check_ticks(self):
if not self.customer and not self.supplier and not self.third_filed_name:
raise ValidationError(_("Customer or Vendor Has to be Ticked..!"))


Full Code:

from odoo.exceptions import ValidationError

class ResPartner(models.Model):
_inherit = 'res.partner'

customer = fields.Boolean(string='Is a Customer', default=False,
help="Check this box if this contact is a customer.")

@api.constrains('customer', 'supplier', 'third_field')
def check_ticks(self):
if not self.customer and not self.supplier and not self.third_filed_name:
raise ValidationError(_("Customer or Vendor Has to be Ticked..!"))

Thanks

Avatar
Discard
Author

wow, thank you. I will try it and report back

Best Answer

Give default=False in he field that has to remain unchecked by default

For example,

isacustomer=fields.Boolean(string="IS A CUSTOMER",default=False,readonly=True)

readonly=True will make the boolean field non-accessible
Avatar
Discard
Author

Thanks for answering. Do you mean I should create a module that inherits from Contacts? Also, what about the second part of my question. I have edited it above to make it more clear.

Yes. The changes must be done in a new inherited module for Contacts

Related Posts Replies Views Activity
0
May 21
1622
2
Jan 20
2552
1
Jun 19
2697
3
Aug 22
10333
2
Jul 22
7251