Skip to content

Commit

Permalink
[IMP] l10n_br_mdfe: add make pdf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Nov 26, 2024
1 parent 77ff291 commit f213726
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 5 deletions.
83 changes: 79 additions & 4 deletions l10n_br_mdfe/demo/fiscal_document_demo.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<!-- MDFe Test - Fiscal Operation - Comment Dummy-->
<record id="l10n_br_fiscal.fo_manifesto" model="l10n_br_fiscal.operation">
<field
name="comment_ids"
eval="[(6,0,[ref('l10n_br_fiscal.fiscal_comment_dummy')])]"
/>
</record>

<!-- MDFe Test - NFe Related -->
<record id="demo_mdfe_related_nfe" model="l10n_br_fiscal.document.related">
<field name="document_key">41190806117473000150550010000586251016759484</field>
<field name="document_total_weight">10</field>
<field name="document_total_amount">33.19</field>
</record>


<!-- MDFe Test - Modal Ferroviário - LC -->
<record id="demo_mdfe_lc_modal_ferroviario" model="l10n_br_fiscal.document">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field name="document_type_id" ref="l10n_br_fiscal.document_58" />
<field
name="document_serie_id"
Expand Down Expand Up @@ -48,9 +57,28 @@
/>
</record>

<!-- MDFe Test - Modal Ferroviário - LC - Document Lines -->
<record
id="demo_mdfe_lc_modal_ferroviario_1-1"
model="l10n_br_fiscal.document.line"
>
<field name="document_id" ref="demo_mdfe_lc_modal_ferroviario" />
<field name="name">Manifesto</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="price_unit">0</field>
<field name="quantity">1</field>
<field name="fiscal_operation_type">out</field>
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field
name="fiscal_operation_line_id"
ref="l10n_br_fiscal.fo_manifesto_manifesto"
/>
</record>


<!-- MDFe Test - Modal Rodoviário - LC -->
<record id="demo_mdfe_lc_modal_rodoviario" model="l10n_br_fiscal.document">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field name="document_type_id" ref="l10n_br_fiscal.document_58" />
<field
name="document_serie_id"
Expand Down Expand Up @@ -88,9 +116,25 @@
/>
</record>

<!-- MDFe Test - Modal Rodoviário - LC - Document Lines -->
<record id="demo_mdfe_lc_modal_rodoviario_1-1" model="l10n_br_fiscal.document.line">
<field name="document_id" ref="demo_mdfe_lc_modal_rodoviario" />
<field name="name">Manifesto</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="price_unit">0</field>
<field name="quantity">1</field>
<field name="fiscal_operation_type">out</field>
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field
name="fiscal_operation_line_id"
ref="l10n_br_fiscal.fo_manifesto_manifesto"
/>
</record>


<!-- MDFe Test - Modal Aéreo - SN -->
<record id="demo_mdfe_sn_modal_aereo" model="l10n_br_fiscal.document">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field name="document_type_id" ref="l10n_br_fiscal.document_58" />
<field
name="document_serie_id"
Expand Down Expand Up @@ -125,9 +169,25 @@
/>
</record>

<!-- MDFe Test - Modal Aéreo - SN - Document Lines -->
<record id="demo_mdfe_sn_modal_aereo_1-1" model="l10n_br_fiscal.document.line">
<field name="document_id" ref="demo_mdfe_sn_modal_aereo" />
<field name="name">Manifesto</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="price_unit">0</field>
<field name="quantity">1</field>
<field name="fiscal_operation_type">out</field>
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field
name="fiscal_operation_line_id"
ref="l10n_br_fiscal.fo_manifesto_manifesto"
/>
</record>


<!-- MDFe Test - Modal Aquaviário - SN -->
<record id="demo_mdfe_sn_modal_aquaviario" model="l10n_br_fiscal.document">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field name="document_type_id" ref="l10n_br_fiscal.document_58" />
<field
name="document_serie_id"
Expand Down Expand Up @@ -165,4 +225,19 @@
/>
</record>

<!-- MDFe Test - Modal Aquaviário - SN - Document Lines -->
<record id="demo_mdfe_sn_modal_aquaviario_1-1" model="l10n_br_fiscal.document.line">
<field name="document_id" ref="demo_mdfe_sn_modal_aquaviario" />
<field name="name">Manifesto</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="price_unit">0</field>
<field name="quantity">1</field>
<field name="fiscal_operation_type">out</field>
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field
name="fiscal_operation_line_id"
ref="l10n_br_fiscal.fo_manifesto_manifesto"
/>
</record>

</odoo>
2 changes: 1 addition & 1 deletion l10n_br_mdfe/report/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _render_qweb_pdf(self, res_ids, data=None):

def _render_damdfe(self, mdfe):
if mdfe.document_type != "58":
raise UserError(_("You can only print a DAMDFE of a MDF-e(58)."))
raise UserError(_("You can only print a DAMDFE of a MDFe(58)."))

mdfe_xml = False
if mdfe.authorization_file_id:
Expand Down
1 change: 1 addition & 0 deletions l10n_br_mdfe/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import test_mdfe_import
from . import test_mdfe_structure
from . import test_mdfe_res_partner
from . import test_mdfe_damdfe
39 changes: 39 additions & 0 deletions l10n_br_mdfe/tests/test_mdfe_damdfe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 - TODAY, Marcel Savegnago <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase


class TestDamdfeGeneration(TransactionCase):
def setUp(self):
super().setUp()

def test_generate_damdfe_brazil_fiscal_report(self):
mdfe = self.env.ref("l10n_br_mdfe.demo_mdfe_lc_modal_rodoviario")
mdfe.action_document_confirm()
mdfe.view_pdf()

self.assertTrue(mdfe.file_report_id)

def test_generate_damdfe_document_type_error(self):
damdfe_report = self.env["ir.actions.report"].search(
[("report_name", "=", "main_template_damdfe")]
)
mdfe = self.env.ref("l10n_br_mdfe.demo_mdfe_lc_modal_rodoviario")
mdfe.document_type_id = self.env.ref("l10n_br_fiscal.document_01")
mdfe.action_document_confirm()
with self.assertRaises(UserError) as captured_exception:
damdfe_report._render_qweb_pdf([mdfe.id])
self.assertEqual(
captured_exception.exception.args[0],
"You can only print a DAMDFE of a MDFe(58).",
)

def test_generate_damdfe_brazil_fiscal_report_partner(self):
mdfe = self.env.ref("l10n_br_mdfe.demo_mdfe_lc_modal_rodoviario")
mdfe.action_document_confirm()
mdfe.issuer = "partner"
mdfe.view_pdf()

self.assertTrue(mdfe.file_report_id)

0 comments on commit f213726

Please sign in to comment.