OCA/l10n-france

Error searching SIREN

Closed this issue · 2 comments

Odoo 14 (latest). When trying to use the API to find the SIREN number for a company, I get an error.

Module

l10n_fr_siret_lookup

Describe the bug

Erreur:
Odoo Server Error

Traceback (most recent call last):
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/http.py", line 684, in dispatch
result = self._call_function(**self.params)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/http.py", line 360, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/http.py", line 348, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/http.py", line 913, in call
return self.method(*args, **kw)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/http.py", line 532, in response_wrap
response = f(*args, **kw)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/addons/web/controllers/main.py", line 1396, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/addons/web/controllers/main.py", line 1384, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/api.py", line 399, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/api.py", line 386, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/opt/bitnami/odoo-enterprise/l10n_fr_siret_lookup/wizard/fr_siret_lookup.py", line 76, in get_lines
res = self._prepare_partner_from_data(company["fields"])
File "/opt/bitnami/odoo-enterprise/l10n_fr_siret_lookup/wizard/fr_siret_lookup.py", line 46, in _prepare_partner_from_data
country_id = self.env["res.partner"]._opendatasoft_dpt2country(
File "/opt/bitnami/odoo-enterprise/l10n_fr_siret_lookup/models/res_partner.py", line 156, in _opendatasoft_dpt2country
if dpt_code and len(dpt_code) == 2:
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/bitnami/odoo/lib/odoo-14.0.post20220110-py3.8.egg/odoo/http.py", line 316, in _handle_exception
raise exception.with_traceback(None) from new_cause
TypeError: object of type 'int' has no len()

To Reproduce

Affected versions:

Steps to reproduce the behavior:

  1. Installed the two modules : l10n_fr_siret & l10n_fr_siret_lookup
  2. Open a company in Contacts, Action > search API SIRENE
  3. In the new dialogue , click on search
  4. An error window appears.

Expected behavior
The action has to produce suggestions of SIRET nubers

Additional context
Add any other context about the problem here. (e.g. OS, Python version, ...)

Hello
I have the same problem. The variable type of "dpt_code" is "Integer" instead of "String". I solved by changing the type in the function call in "\models\res_partner.py":
Before res["country_id"] = self._opendatasoft_dpt2country(dpt_code)
After res["country_id"] = self._opendatasoft_dpt2country(str(dpt_code))

And same in \wizard\fr_siret_lookup.py
Before country_id = self.env["res.partner"]._opendatasoft_dpt2country( data["codedepartementetablissement"] )
After country_id = self.env["res.partner"]._opendatasoft_dpt2country( str(data["codedepartementetablissement"]) )
It may not be too clean but I needed a quick fix.

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.