-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_br_account_nfe: print danfe
- Loading branch information
1 parent
6e8ca4a
commit edacdb7
Showing
7 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .hooks import post_init_hook | ||
|
||
from . import models | ||
from . import report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import ir_actions_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<odoo> | ||
<record id="report_danfe_account" model="ir.actions.report"> | ||
<field name="name">DANFE</field> | ||
<field name="model">account.move</field> | ||
<field name="report_type">qweb-pdf</field> | ||
<field name="report_name">main_template_danfe_account</field> | ||
<field name="report_file">main_template_danfe_account</field> | ||
<field name="print_report_name">'%s' % (object.document_key)</field> | ||
<field name="binding_model_id" ref="account.model_account_move" /> | ||
<field name="binding_type">report</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 Engenere.one | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class IrActionsReport(models.Model): | ||
_inherit = "ir.actions.report" | ||
|
||
def temp_xml_autorizacao(self, xml_string): | ||
return super().temp_xml_autorizacao(xml_string=xml_string) | ||
|
||
def _render_qweb_html(self, res_ids, data=None): | ||
if self.report_name == "main_template_danfe_account": | ||
return | ||
return super()._render_qweb_html(res_ids, data=data) | ||
|
||
def _render_qweb_pdf(self, res_ids, data=None): | ||
if self.report_name not in ["main_template_danfe_account"]: | ||
return super()._render_qweb_pdf(res_ids, data=data) | ||
|
||
nfe = self.env["account.move"].search([("id", "in", res_ids)]) | ||
|
||
return self._render_danfe(nfe) | ||
|
||
def _render_danfe(self, nfe): | ||
return super()._render_danfe(nfe=nfe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import test_nfe_generate_tags_cobr_dup_pag | ||
from . import test_nfce_contingency | ||
from . import test_nfe_danfe_account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Engenere.one | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from unittest.mock import patch | ||
|
||
from odoo.tests import SavepointCase, tagged | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestGeneratePaymentInfo(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
|
||
def test_generate_danfe_brazil_fiscal_report(self): | ||
nfe = self.env.ref("l10n_br_account_nfe.demo_nfe_dados_de_cobranca") | ||
nfe.action_post() | ||
|
||
danfe_report = self.env["ir.actions.report"].search( | ||
[("report_name", "=", "main_template_danfe_account")] | ||
) | ||
danfe_pdf = danfe_report._render_qweb_pdf([nfe.id]) | ||
self.assertTrue(danfe_pdf) | ||
|
||
def test_generate_danfe_erpbrasil_edoc(self): | ||
nfe = self.env.ref("l10n_br_account_nfe.demo_nfe_dados_de_cobranca") | ||
nfe.company_id.danfe_library = "erpbrasil.edoc.pdf" | ||
|
||
with patch("erpbrasil.edoc.pdf.base.ImprimirXml.imprimir") as mock_make_pdf: | ||
mock_make_pdf.return_value = b"Mock PDF" | ||
|
||
nfe.action_post() | ||
|
||
danfe_report = self.env["ir.actions.report"].search( | ||
[("report_name", "=", "main_template_danfe_account")] | ||
) | ||
danfe_pdf = danfe_report._render_qweb_pdf([nfe.id]) | ||
self.assertTrue(danfe_pdf) |