Skip to content

Commit

Permalink
[IMP] l10n_br_nfe:Invoice Dashboard to BrazilFiscalReport lib
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianoMafraJunior authored and antoniospneto committed Jul 11, 2024
1 parent 14bb416 commit a0fe5a9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
6 changes: 6 additions & 0 deletions l10n_br_nfe/constants/nfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

DANFE_LIBRARY_DEFAULT = "brazil_fiscal_report"

DANFE_INVOICE_DISPLAY = [
("full_details", "Full Details"),
("duplicates_only", "Duplicates Only"),
]

DANFE_INVOICE_DISPLAY_DEFAULT = "full_details"

NFE_ENVIRONMENTS = [("1", "Produção"), ("2", "Homologação")]

Expand Down
13 changes: 13 additions & 0 deletions l10n_br_nfe/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from odoo.addons.spec_driven_model.models import spec_models

from ..constants.nfe import (
DANFE_INVOICE_DISPLAY,
DANFE_INVOICE_DISPLAY_DEFAULT,
DANFE_LIBRARY,
DANFE_LIBRARY_DEFAULT,
NFCE_DANFE_LAYOUT_DEFAULT,
Expand Down Expand Up @@ -174,6 +176,17 @@ class ResCompany(spec_models.SpecModel):
""",
)

danfe_invoice_display = fields.Selection(
selection=DANFE_INVOICE_DISPLAY,
default=DANFE_INVOICE_DISPLAY_DEFAULT,
help="Choose to generate a full or incomplete invoice frame in the DANFE.",
)

danfe_display_pis_cofins = fields.Boolean(
default=False,
help="Select whether PIS and COFINS should be displayed in DANFE.",
)

def _compute_nfe_data(self):
# compute because a simple related field makes the match_record fail
for rec in self:
Expand Down
23 changes: 16 additions & 7 deletions l10n_br_nfe/report/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from io import BytesIO

from brazilfiscalreport.danfe import Danfe, DanfeConfig, Margins
from brazilfiscalreport.danfe import Danfe, DanfeConfig, InvoiceDisplay, Margins
from erpbrasil.edoc.pdf import base
from lxml import etree

Expand Down Expand Up @@ -84,7 +84,11 @@ def render_danfe_brazilfiscalreport(self, nfe, nfe_xml):
else:
tmpLogo = False

config = self._get_danfe_config(tmpLogo)
danfe_invoice_display = nfe.company_id.danfe_invoice_display
config = self._get_danfe_config(tmpLogo, danfe_invoice_display)
if nfe.company_id.danfe_display_pis_cofins:
config.display_pis_cofins = True

danfe = Danfe(xml=nfe_xml, config=config)

tmpDanfe = BytesIO()
Expand All @@ -94,11 +98,16 @@ def render_danfe_brazilfiscalreport(self, nfe, nfe_xml):

return danfe_file, "pdf"

def _get_danfe_config(self, tmpLogo):
return DanfeConfig(
logo=tmpLogo,
margins=Margins(top=5, right=5, bottom=5, left=5),
)
def _get_danfe_config(self, tmpLogo, danfe_invoice_display):
danfe_config = {
"logo": tmpLogo,
"margins": Margins(top=2, right=2, bottom=2, left=2),
}

if danfe_invoice_display == "duplicates_only":
danfe_config["invoice_display"] = InvoiceDisplay.DUPLICATES_ONLY

return DanfeConfig(**danfe_config)

def render_danfe_erpbrasil(self, nfe_xml):
pdf = base.ImprimirXml.imprimir(
Expand Down
17 changes: 16 additions & 1 deletion l10n_br_nfe/views/res_company_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
/>
<field name="nfe_authorize_accountant_download_xml" />
<field name="nfe_authorize_technical_download_xml" />
<field name="danfe_library" />
</group>
</group>

Expand All @@ -44,6 +43,22 @@
<field name="nfce_csc_code" />
</group>
</group>

<group name="danfe_settings" string="DANFE Settings">
<group>
<field name="danfe_library" />
<field
name="danfe_invoice_display"
string="Invoice Display"
attrs="{'invisible': [('danfe_library', '!=', 'brazil_fiscal_report')]}"
/>
<field
name="danfe_display_pis_cofins"
string="PIS/COFINS Display"
attrs="{'invisible': [('danfe_library', '!=', 'brazil_fiscal_report')]}"
/>
</group>
</group>
</page>
</xpath>
</field>
Expand Down

0 comments on commit a0fe5a9

Please sign in to comment.