Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
3879 Представления

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!






Аватар
Отменить
Лучший ответ

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

   

Аватар
Отменить