Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][RFC] l10n_br_nfe: refactor nfce qrcode methods #3542

Open
wants to merge 5 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions l10n_br_account_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,9 @@ def _update_nfce_for_offline_contingency(self):
res = super()._update_nfce_for_offline_contingency()
if self.move_ids:
copy_invoice = self.move_ids[0].copy()

copy_invoice.fiscal_document_id.processador_edoc = self.processador_edoc
copy_invoice.processador_edoc = self.processador_edoc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Porque pular linhas antes e depois? Não me parece que essas duas linhas seriam um bloco logico espcial, logo não acho bom pular linhas antes e depois. Eu perdi algo?

copy_invoice.action_post()
return res
21 changes: 19 additions & 2 deletions l10n_br_account_nfe/tests/test_nfce_contingency.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2023 KMEE (Felipe Zago Rodrigues <[email protected]>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields
from odoo.tests import TransactionCase


Expand Down Expand Up @@ -54,8 +55,24 @@ def prepare_account_move_nfce(self):
"payment_mode_id": payment_mode.id,
"company_id": self.env.ref("base.main_company").id,
"line_ids": [
(0, 0, {"account_id": receivable_account_id.id, "credit": 10}),
(0, 0, {"account_id": payable_account_id.id, "debit": 10}),
(
0,
0,
{
"date_maturity": fields.Date.today(),
"account_id": receivable_account_id.id,
"credit": 10,
},
),
(
0,
0,
{
"date_maturity": fields.Date.today(),
"account_id": payable_account_id.id,
"debit": 10,
},
),
],
}
)
Expand Down
40 changes: 28 additions & 12 deletions l10n_br_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,10 +896,17 @@ def _serialize(self, edocs):
for record in self.with_context(lang="pt_BR").filtered(
filter_processador_edoc_nfe
):
processor = record.processador_edoc

# TODO: Avaliar a possibilidade de remover esse flush e invalidate
record.flush()
record.invalidate_cache()
inf_nfe = record._build_binding("nfe", "40")

if hasattr(record, "move_ids") and record.move_ids:
record.move_ids.processador_edoc = processor
record.processador_edoc = processor

Comment on lines +899 to +909
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poderia explicar um pouco qual a necessidade desse código?

inf_nfe_supl = None
if record.nfe40_infNFeSupl:
inf_nfe_supl = record.nfe40_infNFeSupl._build_binding("nfe", "40")
Expand Down Expand Up @@ -1226,14 +1233,25 @@ def _is_nfe_found(c_stat):

def _prepare_nfce_send(self):
self.ensure_one()
self._prepare_payments_for_nfce()
self.nfe40_infNFeSupl = self.env["l10n_br_fiscal.document.supplement"].create(
{
"nfe40_qrCode": self.get_nfce_qrcode(),
"nfe40_urlChave": self.get_nfce_qrcode_url(),
}
self.nfe40_detPag.filtered(lambda p: p.nfe40_tPag == "99").write(
{"nfe40_xPag": "Outros"}
)

def _document_qrcode(self):
super()._document_qrcode()

for record in self.filtered(lambda d: d.document_type == MODELO_FISCAL_NFCE):
if record.nfe40_infNFeSupl:
record.nfe40_infNFeSupl.unlink()
record.nfe40_infNFeSupl = self.env[
"l10n_br_fiscal.document.supplement"
].create(
{
"qrcode": record.get_nfce_qrcode(),
"url_key": record.get_nfce_qrcode_url(),
}
)

def _eletronic_document_send(self):
super()._eletronic_document_send()
for record in self.filtered(filter_processador_edoc_nfe):
Expand Down Expand Up @@ -1517,6 +1535,8 @@ def get_nfce_qrcode(self):
processador = self._edoc_processor()
if self.nfe_transmission == "1":
return processador.monta_qrcode(self.document_key)
if not self.serialize() or not len(self.serialize()):
return

serialized_doc = self.serialize()[0]
xml = processador.assina_raiz(serialized_doc, serialized_doc.infNFe.Id)
Expand All @@ -1525,15 +1545,11 @@ def get_nfce_qrcode(self):
def get_nfce_qrcode_url(self):
if self.document_type != MODELO_FISCAL_NFCE:
return
if self._edoc_processor() is None:
return

return self._edoc_processor().consulta_qrcode_url

def _prepare_payments_for_nfce(self):
for rec in self.filtered(lambda d: d.document_type == MODELO_FISCAL_NFCE):
rec.nfe40_detPag.filtered(lambda p: p.nfe40_tPag == "99").write(
{"nfe40_xPag": "Outros"}
)

def action_danfe_nfce_report(self):
return (
self.env["ir.actions.report"]
Expand Down
4 changes: 2 additions & 2 deletions l10n_br_nfe/tests/test_nfce.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def setUp(self):
}
)
self.document_id.company_id.certificate_nfe_id = certificate_id
self.document_id.company_id.nfce_csc_token = "DUMMY"
self.document_id.company_id.nfce_csc_code = "DUMMY"
self.document_id.company_id.nfce_csc_token = "1"
self.document_id.company_id.nfce_csc_code = "1"

self.prepare_test_nfe(self.document_id)

Expand Down
Loading