Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4699 Lượt xem

hi all,

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'),

]

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Smithjohn45,

Yes, it can be achieved within Odoo like this method.

For case insensitive constraints you can always use Odoo Constraints instead of SQL.

Like this Example, 

 - List out all Data for Specific fields in one list and convert it in either ['Lower' or 'upper Case], Then check for the New Value with the 'in' operator, and return the opposite of result.


Code: (Object: 'res.company')

    @api.constrains('name')

    def _check_unique_company(self):

        company_ids = self.search([]) - self

        value = [x.name.lower() for x in company_ids]

        if self.name and self.name.lower() in value:

            raise ValidationError(_('The combination is already Exist'))

        return True

Thanks..

For more information Contact us:- https://kanakinfosystems.com/odoo-development-services

Ảnh đại diện
Huỷ bỏ
Tác giả

thanks a bunch... will implement it and check, hope this will work as you have mentioned :)

Tác giả

but the mis spelled words problem is still unresolved.

For this question it is about the unique value to be check with in-casesensitive. So that you can handle through the odoo constraint instead sql.

But for to check spell of word you need some library to work around this like 'textblob'

Example,

from textblob import TextBlob

a = "cmputr" # incorrect spelling

print("original text: "+str(a))

b = TextBlob(a)

# prints the corrected spelling

print("corrected text: "+str(b.correct()))

So you can use this kind of technique in odoo and use your custom development.

Câu trả lời hay nhất

This is certainly not Odoo-related.

Ảnh đại diện
Huỷ bỏ
Tác giả

is there any spell check like module/library to prevent user from t his type of mistakes? at least we can inform him/her for this mistake.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 25
2261
2
thg 7 25
7743
2
thg 7 25
4166
2
thg 7 25
3942
2
thg 6 25
2542