跳至内容
菜单
此问题已终结

Hi i am looking for the settings on automated action fields and the python code to avoid my staff from creating duplicate contacts in Odoo V14. I did similar automated action on product internal reference which works perfectly but cannot manage to do so for the contacts.

形象
丢弃

If you need any help regarding coding you can contact with us: softwarebox18@gmail.com

最佳答案

Hi,

You can avoid creating a duplicate contact by generating a error message by checking the unique field.

For example:

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

 
    @api.onchange('name')
def _check_name(self):
partner = self.search([])
name = partner.mapped('name')
if self.name:
if self.name in name:
raise ValidationError('Duplicate Customer Name.')
 

Here, it will generate a validation error if the creating customer name already exists in contacts. And it will prevent creating customers with the same name.

Regards

形象
丢弃
编写者

Hello,
Thank you for replying so promptly, I have not done any coding on the forms before, I was able to locate res.partner in models but within the model there are a lot of options to go about. any chance you can guide me which field I should apply this code too.

相关帖文 回复 查看 活动
0
11月 23
1129
1
9月 23
2321
1
8月 23
1571
2
9月 20
2574
0
10月 23
8266