最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - E 250320 13:48:06 odoo_btn_utils:212 There is no country named: 'Country' - Stack Overflow

programmeradmin2浏览0评论

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
  • Your title and the error in the question seem to be very different. Is "Country" or "Lithuania" the one giving you problems? The error of the title suggest you have your country name in a variable named 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
  • maybe you can get more info from here odoo/documentation/17.0/developer/reference/… – farisfath25 Commented Mar 21 at 1:46
Add a comment  | 

1 Answer 1

Reset to default 0

The 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.

发布评论

评论列表(0)

  1. 暂无评论