Skip to content

Commit

Permalink
[REF] l10n_br_ie_search: merge webservice classes
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniospneto committed Sep 7, 2024
1 parent feae1cf commit dca8196
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 64 deletions.
1 change: 0 additions & 1 deletion l10n_br_ie_search/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import sefaz_webservice
from . import sintegra_webservice
from . import res_config_settings
52 changes: 52 additions & 0 deletions l10n_br_ie_search/models/sefaz_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
class SefazWebservice(models.AbstractModel):
_inherit = "l10n_br_cnpj_search.webservice.abstract"

# SEFAZ

@api.model
def sefaz_validate(self, response):
if not response.ok:
Expand All @@ -36,3 +38,53 @@ def _sefaz_import_data(self, data):
def sefaz_search(self, uf, cnpj, processador):
response = processador.consultar_cadastro(uf, int(punctuation_rm(cnpj)))
return response.retorno

# SINTEGRA

@api.model
def _get_query(self, cnpj, token):
return {
"token": token,
"cnpj": punctuation_rm(cnpj),
"plugin": "ST",
}

@api.model
def _get_token(self):
return (
self.env["ir.config_parameter"]
.sudo()
.get_param("l10n_br_ie_search.sintegra_token")
)

@api.model
def sintegra_validate(self, response):
self._validate(response)
data = response.json()
if data.get("status") == "ERROR":
raise ValidationError(_(data.get("message")))
return data

@api.model
def _validate(self, response):
if response.status_code != 200:
raise ValidationError(_("%s" % response.reason))

@api.model
def _sintegra_import_data(self, data):
res = {
"inscr_est": self.get_data(data, "inscricao_estadual"),
}
return res

@api.model
def get_data(self, data, name, title=False, lower=False):
value = False
if data.get(name):
value = data[name]
if lower:
value = value.lower()
elif title:
value = value.title()

return value
63 changes: 0 additions & 63 deletions l10n_br_ie_search/models/sintegra_webservice.py

This file was deleted.

0 comments on commit dca8196

Please sign in to comment.