Skip to content

Commit

Permalink
[TEST] l10n_br_cte: dacte print
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Nov 21, 2024
1 parent 7caaf51 commit 45c9e20
Showing 1 changed file with 30 additions and 33 deletions.
63 changes: 30 additions & 33 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from datetime import datetime
from enum import Enum

from brazilfiscalreport.dacte import Dacte
from erpbrasil.base.fiscal import cnpj_cpf

# TODO: precisa tratar
Expand Down Expand Up @@ -83,9 +84,6 @@

CTE_XML_NAMESPACE = {"cte": "http://www.portalfiscal.inf.br/cte"}

# TODO: https://github.com/Engenere/BrazilFiscalReport/pull/23
# from brazilfiscalreport.dacte import Dacte


_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1755,33 +1753,32 @@ def _document_number(self):
) from e
return result

# TODO: Tratar
# def make_pdf(self):
# if not self.filtered(filter_processador_edoc_cte):
# return super().make_pdf()

# file_pdf = self.file_report_id
# self.file_report_id = False
# file_pdf.unlink()

# if self.authorization_file_id:
# arquivo = self.authorization_file_id
# xml_string = base64.b64decode(arquivo.datas).decode()
# else:
# arquivo = self.send_file_id
# xml_string = base64.b64decode(arquivo.datas).decode()
# # TODO: implementar temp_xml_autorizacao igual nfe ?
# # xml_string = self.temp_xml_autorizacao(xml_string)

# pdf = Dacte(xml=xml_string).output()

# self.file_report_id = self.env["ir.attachment"].create(
# {
# "name": self.document_key + ".pdf",
# "res_model": self._name,
# "res_id": self.id,
# "datas": base64.b64encode(pdf),
# "mimetype": "application/pdf",
# "type": "binary",
# }
# )
def make_pdf(self):
if not self.filtered(filter_processador_edoc_cte):
return super().make_pdf()

Check warning on line 1758 in l10n_br_cte/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_cte/models/document.py#L1758

Added line #L1758 was not covered by tests

file_pdf = self.file_report_id
self.file_report_id = False
file_pdf.unlink()

Check warning on line 1762 in l10n_br_cte/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_cte/models/document.py#L1760-L1762

Added lines #L1760 - L1762 were not covered by tests

if self.authorization_file_id:
arquivo = self.authorization_file_id
xml_string = base64.b64decode(arquivo.datas).decode()

Check warning on line 1766 in l10n_br_cte/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_cte/models/document.py#L1765-L1766

Added lines #L1765 - L1766 were not covered by tests
else:
arquivo = self.send_file_id
xml_string = base64.b64decode(arquivo.datas).decode()

Check warning on line 1769 in l10n_br_cte/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_cte/models/document.py#L1768-L1769

Added lines #L1768 - L1769 were not covered by tests
# TODO: implementar temp_xml_autorizacao igual nfe ?
# xml_string = self.temp_xml_autorizacao(xml_string)

pdf = Dacte(xml=xml_string).output()

Check warning on line 1773 in l10n_br_cte/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_cte/models/document.py#L1773

Added line #L1773 was not covered by tests

self.file_report_id = self.env["ir.attachment"].create(

Check warning on line 1775 in l10n_br_cte/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_cte/models/document.py#L1775

Added line #L1775 was not covered by tests
{
"name": self.document_key + ".pdf",
"res_model": self._name,
"res_id": self.id,
"datas": base64.b64encode(pdf),
"mimetype": "application/pdf",
"type": "binary",
}
)

0 comments on commit 45c9e20

Please sign in to comment.