コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
3774 ビュー

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

   

アバター
破棄