跳至内容
菜单
此问题已终结
1 回复
3763 查看

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

   

形象
丢弃