I am running into an issue on Odoo version 17.
The issue is that I am trying to receive the country id from odoo based on my users selected country and I get the error:
[E 250320 13:48:06 odoo_btn_utils:212] There is no country named: Lithuania
This error appears on any kind of country and I am assuming that it could be due to wrong call to check the country, but can't figure out what to fix directly. I tried looking in our odoo to see the correct call for countries or to check countries that are available and they're codes, but sadly couldn't find it as well.
Code that executes the country_id search:
def get_country_id(country_name):
try:
countries = execute_model('res.country', 'search_read', [[['name', '=', country_name]]], {'fields': ['id', 'name']})
except ValueError as e:
logger.error(f"An error occurred while retrieving CountryID: {countries}")
return get_general_error_message()
if not countries:
logger.error(f'There is no country named: {country_name}')
return get_general_error_message()
return countries[0]['id']
I am running into an issue on Odoo version 17.
The issue is that I am trying to receive the country id from odoo based on my users selected country and I get the error:
[E 250320 13:48:06 odoo_btn_utils:212] There is no country named: Lithuania
This error appears on any kind of country and I am assuming that it could be due to wrong call to check the country, but can't figure out what to fix directly. I tried looking in our odoo to see the correct call for countries or to check countries that are available and they're codes, but sadly couldn't find it as well.
Code that executes the country_id search:
def get_country_id(country_name):
try:
countries = execute_model('res.country', 'search_read', [[['name', '=', country_name]]], {'fields': ['id', 'name']})
except ValueError as e:
logger.error(f"An error occurred while retrieving CountryID: {countries}")
return get_general_error_message()
if not countries:
logger.error(f'There is no country named: {country_name}')
return get_general_error_message()
return countries[0]['id']
Share
Improve this question
asked Mar 20 at 12:40
B0K1NGB0K1NG
34 bronze badges
2
|
1 Answer
Reset to default 0The issue is likely due to the way the search domain is being passed. In your code you’re wrapping the domain in an extra list:
[[['name', '=', country_name]]]
But the expected format for a search domain in Odoo’s API is a single list of conditions, like this:
[['name', '=', country_name]]
Because of the extra nesting, the domain isn’t being interpreted correctly by Odoo, and no records are found even if “Lithuania” exists in your database.
Country
but instead of using the variable value you are passing it as a string"Country"
. But then in your question the error you report is completely different, and it looks like the name of the country is actually valid:"Lithuania"
. So what's your actual error? – Cincinnatus Commented Mar 20 at 13:12