Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
3343 Ansichten

My problem occurs when a user enters a country, this is not recognized by the system because in the name entered it is in the language of the interface.

Example:

from shell is correct:

In [5]: stato = self.env['res.country'].search([('name', '=', 'Italy')])
Out[5]: res.country()
In [7]: stato = self.env['res.country'].search([('name', '=', 'Italia')])
Out[7]: res.country(363,)

but I have problems in code file.py:

#python code from file.py
self.env['res.country'].search([('name', '=', 'Italia')])
res.country()

On db in table res_country the column name i saved Italy

The web interface is in Italian language.This creates a problem with the rest of the operation, because depending on the country I recover the correct province or city.
Can you help me? I don't understand why on the shell it works on the code no.
More info, I use docker for both postgres and odoo. With the classic settings






Avatar
Verwerfen

Hi,

It is better to search with the code of the country than the name of the country

Autor

Yes I know, but the customer writes the full name.

Sorry for my ignorance on Odoo.

Can you tell me how to connect shell with odoo. I tried running on ipython3

In [5]: stato = self.env['res.country'].search([('name', '=', 'Italy')])

and I am getting error:

NameError: name 'self' is not defined

Autor Beste Antwort

Found the solution!!!!

self.env['res.country'].with_context(lang='it_IT').search(......)

Use .with_context(lang)!!

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Dez. 22
16466
1
Apr. 20
142
1
Juni 19
4379
2
Juni 18
89
0
März 18
5995