@api.constrains('phone', 'owner')
def check_phone_owner_uniq(self):
for record in self:
duplicate_records = self.search([
('phone', '=', record.phone),
('owner', '=', record.owner.id),
('id', '!=', record.id)
])
if duplicate_records:
raise ValidationError("You cannot have two tenants with the same phone number for the same owner!")
I want to use api.constrains to check. It's working, but when debug I check id record and I see its still create record (its only hide this record).
How can not create record when it show an error message?