Skip to content

Commit

Permalink
[REF] erpbrasil.assinatura fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Jul 3, 2023
1 parent 6375093 commit 8c7a233
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
40 changes: 30 additions & 10 deletions l10n_br_fiscal_certificate/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@

import logging

from erpbrasil.assinatura import misc

from odoo import SUPERUSER_ID, api, tools
from odoo import _, SUPERUSER_ID, api, tools

from .constants import CERTIFICATE_TYPE_ECNPJ, CERTIFICATE_TYPE_NFE

_logger = logging.getLogger(__name__)

try:
from erpbrasil.assinatura import misc
except ImportError:
_logger.error(
_(
"Python Library erpbrasil.assinatura not installed!"
"It doesn't matter much until you want to send NFe or NFSe documents."
"You can install it later with: pip install erpbrasil.assinatura."
)
)


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
Expand All @@ -31,11 +42,20 @@ def prepare_fake_certificate_vals(
}

if not tools.config["without_demo"]:
for company in []: # companies:
l10n_br_fiscal_certificate_id = env["l10n_br_fiscal.certificate"]
company.certificate_nfe_id = l10n_br_fiscal_certificate_id.create(
prepare_fake_certificate_vals()
)
company.certificate_ecnpj_id = l10n_br_fiscal_certificate_id.create(
prepare_fake_certificate_vals(cert_type=CERTIFICATE_TYPE_ECNPJ)
try:
for company in []:
l10n_br_fiscal_certificate_id = env["l10n_br_fiscal.certificate"]
company.certificate_nfe_id = l10n_br_fiscal_certificate_id.create(
prepare_fake_certificate_vals()
)
company.certificate_ecnpj_id = l10n_br_fiscal_certificate_id.create(
prepare_fake_certificate_vals(cert_type=CERTIFICATE_TYPE_ECNPJ)
)
except NameError: # (means from erpbrasil.assinatura import misc failed)
_logger.error(
_(
"Python Library erpbrasil.assinatura not installed!"
"You can install it later with: pip install erpbrasil.assinatura."
"Demo companies fake A1 certificates were not created."
)
)
5 changes: 3 additions & 2 deletions l10n_br_fiscal_certificate/models/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
except ImportError:
_logger.error(
_(
"Python Library erpbrasil.assinatura not installed, "
"please install ex: pip install erpbrasil.assinatura."
"Python Library erpbrasil.assinatura not installed!"
"It doesn't matter much until you want to send NFe or NFSe documents."
"You can install it later with: pip install erpbrasil.assinatura."
)
)

Expand Down

0 comments on commit 8c7a233

Please sign in to comment.