Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3764 Widoki

Hi,


I have a custom field called  populated with a list of Brazilian cities.


I'm using an API to search a customer's address based on the ZIP code and automatically fill the field. Here's part of the code:

dic = json.loads(content)

search = self.env['res.city'].search([
('name', 'ilike', dic['city'])
    ])

self.city_id = search.id

Note: Unaccent is activated to handle special characters of brazilian language.


I've been using ILIKE because some of the cities in are in upper case, some are in lower case and some have upper and lower.


The code works fine most of the time but today I had an exception where search.id retrieved 3 values:


retrieved the string and search found 03 matches: , and (the correct result).


How can I perform search with "case insensitive" and "exact match" at same time?


Thanks in advance!






Awatar
Odrzuć
Najlepsza odpowiedź

Hello,

Please use "=ilike" in the search it will give you exact match with case insensitive.

search = self.env['res.city'].search([

 ('name', '=ilike', dic['city'])

    ])

Thank You!

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Awatar
Odrzuć