Skip to content

Commit

Permalink
Merge pull request #20 from CristianoMafraJunior/brazil_fiscal_report…
Browse files Browse the repository at this point in the history
…_duplica_fix

Fix format w_dup_text + Install qpdf + Fields PIS e COFINS
  • Loading branch information
antoniospneto authored Jun 27, 2024
2 parents edb9b88 + cdd2555 commit c7c50dc
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install qpdf ⚙️
run: sudo apt-get update --allow-releaseinfo-change && sudo apt-get install qpdf
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools fpdf2 phonenumbers python-barcode pytest pytest-cov
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ Here is a breakdown of all the configuration options available in ``DanfeConfig`
config.font_type = FontType.COURIER
```
- **Default**: ``TIMES``

8. **Display PIS COFINS**
- **Type**: ``Bool``
- **Values**: ``True``, ``False``
- **Description**: Displays PIS and COFINS taxes in the DANFE totals.
- **Example**::
```python
config.display_pis_cofins = True
```
- **Default**: ``False``
### Usage Example with Customization

Here’s how to set up a ``DanfeConfig`` object with a full set of customizations::
Expand Down
1 change: 1 addition & 0 deletions brazilfiscalreport/danfe/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ class DanfeConfig:
tax_configuration: TaxConfiguration = TaxConfiguration.STANDARD_ICMS_IPI
invoice_display: InvoiceDisplay = InvoiceDisplay.FULL_DETAILS
font_type: FontType = FontType.TIMES
display_pis_cofins: bool = False
18 changes: 17 additions & 1 deletion brazilfiscalreport/danfe/danfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, xml, config: DanfeConfig = None):
self.price_precision = config.decimal_config.price_precision
self.quantity_precision = config.decimal_config.quantity_precision
self.invoice_display = config.invoice_display
self.display_pis_cofins = config.display_pis_cofins

root = ET.fromstring(xml)
self.inf_nfe = root.find(f"{URL}infNFe")
Expand Down Expand Up @@ -1044,7 +1045,7 @@ def _draw_billing(self):
valor = format_number(valor, 2)
dup_text = f"{num} {venc} {valor}"
dups_text.append(dup_text)
w_dup_text = self.get_string_width(dup_text)
w_dup_text = self.get_string_width(dup_text) + 2
max_width = max(max_width, w_dup_text)

# Calculates the number of `duplicatas` that can fit in one line,
Expand Down Expand Up @@ -1084,12 +1085,14 @@ def _draw_taxes(self):
v_icms = format_number(extract_text(self.totais, "vICMS"), precision=2)
v_bcst = format_number(extract_text(self.totais, "vBCST"), precision=2)
v_st = format_number(extract_text(self.totais, "vST"), precision=2)
v_pis = format_number(extract_text(self.totais, "vPIS"), precision=2)
v_prod = format_number(extract_text(self.totais, "vProd"), precision=2)
v_frete = format_number(extract_text(self.totais, "vFrete"), precision=2)
v_seg = format_number(extract_text(self.totais, "vSeg"), precision=2)
v_desc = format_number(extract_text(self.totais, "vDesc"), precision=2)
v_outro = format_number(extract_text(self.totais, "vOutro"), precision=2)
v_ipi = format_number(extract_text(self.totais, "vIPI"), precision=2)
v_confins = format_number(extract_text(self.totais, "vCOFINS"), precision=2)
v_nf = format_number(extract_text(self.totais, "vNF"), precision=2)
v_tot_trib = format_number(extract_text(self.totais, "vTotTrib"), precision=2)

Expand Down Expand Up @@ -1143,6 +1146,19 @@ def _draw_taxes(self):
w=0, description="VALOR TOTAL DA NOTA", content=v_nf, type="number"
),
]
if self.display_pis_cofins:
fields_line1.insert(
-1,
BaseFieldInfo(
w=0, description="VALOR DO PIS", content=v_pis, type="number"
),
)
fields_line2.insert(
-1,
BaseFieldInfo(
w=0, description="VALOR DO COFINS", content=v_confins, type="number"
),
)
block_impostos.add_fields([fields_line1, fields_line2])
block_impostos.render()

Expand Down
Binary file modified tests/generated/dacce/cce.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_add_info_below_prod.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_add_info_next_page.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_default.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_duplicatas_only.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_minimal.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_multipage_landscape.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_overload.pdf
Binary file not shown.
Binary file added tests/generated/danfe/danfe_pis_confins.pdf
Binary file not shown.
Binary file modified tests/generated/danfe/danfe_sn.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/test_danfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,13 @@ def test_danfe_duplicatas_only(tmp_path, load_danfe):
danfe = load_danfe("nfe_overload.xml", config=config)
pdf_path = get_pdf_output_path("danfe", "danfe_duplicatas_only")
assert_pdf_equal(danfe, pdf_path, tmp_path)


def test_danfe_pis_config(tmp_path, load_danfe):
config = DanfeConfig(
margins=Margins(top=2, right=2, bottom=2, left=2),
display_pis_cofins=True,
)
danfe = load_danfe("nfe_test_1.xml", config=config)
pdf_path = get_pdf_output_path("danfe", "danfe_pis_confins")
assert_pdf_equal(danfe, pdf_path, tmp_path)

0 comments on commit c7c50dc

Please sign in to comment.