1
votes

In odoo10, I wrote a @api.onchange function on change of name which return warning popup if name already in database, so As I click on save button after giving input in name field then It returning a warning popup but also form saving on background which I don't want.

So, what is the actual problem here? Please find attached screenshot below. Thanks

enter image description here

1
Can you paste the code of your onchange method here, please? - forvas
@api.onchange('displayname', 'firstname', 'lastname') @api.multi def check_duplicate_name(self): if self.name: contact = self.env['res.partner'].search([('name', '=', self.name)]) if contact: return { 'warning': { 'title': 'Warning Message', 'warning': 'Company/Contact name already exist.\nDo you want to continue?', } } - rahul mehra
Your problem is that Odoo lets you save the record after the warning is shown (although the name already exists in the database), isn't it? - forvas
My problem is that until the warning message is there the form should need to be in editable state. - rahul mehra
What it's your question? Are you having any specific issue? - Axel Mendoza

1 Answers

2
votes

If the problem is that Odoo lets you save the record after the warning is shown (although the name already exists in the database), you have to add a SQL constraint to your model, because the warning in the onchange method does not prevent users from storing the records.

_sql_constraints = [
    ('name_unique', 'unique(name)',
    'There is another record with the same name stored in the database!')
]

Of course you can keep your onchange warning in order to let the user know that if they keep that name, they're getting an error when saving the record.