Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
3873 Vizualizări

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!






Imagine profil
Abandonează
Cel mai bun răspuns

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

   

Imagine profil
Abandonează