I can use _sql_constraints as mentioned below to prevent duplicates but when user enter like:
Bakery
bakery
bakry
etc...
how i can prevent user to NOT enter this type of value?
> _sql_constraints = [
>
> ('categoryname_unique',
>
> 'unique(name)',
>
> 'each category should be unique'),
>
> ]
I believe the _sql_constraints is not case sensitive so Bakery should be considered the same as bakery , therefore the record can't be created if it's the same attribute with different cases. Right?
Alternative, you can change it to selection
field. Instead of User enter value, let's manager creates that values and User will select it from the list.
at least i can avoid duplication with same spelling but in either case (case insensitive) using below code (thanks to odoo forum - @Neha Sharma-Kanak)
@api.constrains('name')
def _check_unique_brand(self):
brand_ids = self.search([]) - self
value = [x.name.lower() for x in brand_ids]
if self.name and self.name.lower() in value:
raise ValidationError(_('The Brand Name is already Exist'))
return True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.