Skip to content

Commit 2559d50

Browse files
Merge pull request #93 from PedroJoMa/danfe-new-config-cancelled-nfe
DANFE: Adiciona marca d'água "cancelada" em DanfeConfig para caso a nfe seja cancelada.
2 parents 44211a4 + 22b9c79 commit 2559d50

8 files changed

Lines changed: 436 additions & 4 deletions

brazilfiscalreport/danfe/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class DanfeConfig:
6060
invoice_display: InvoiceDisplay = InvoiceDisplay.FULL_DETAILS
6161
font_type: FontType = FontType.TIMES
6262
display_pis_cofins: bool = False
63+
watermark_cancelled: bool = False
6364
product_description_config: ProductDescriptionConfig = field(
6465
default_factory=ProductDescriptionConfig
6566
)

brazilfiscalreport/danfe/danfe.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ def __init__(self, xml, config: DanfeConfig = None):
6060
self.invoice_display = config.invoice_display
6161
self.display_pis_cofins = config.display_pis_cofins
6262
self.product_description_config = config.product_description_config
63+
self.watermark_cancelled = config.watermark_cancelled
6364

6465
root = ET.fromstring(xml)
6566
self.inf_nfe = root.find(f"{URL}infNFe")
6667
self.prot_nfe = root.find(f"{URL}protNFe")
68+
6769
self.emit = root.find(f"{URL}emit")
6870
self.ide = root.find(f"{URL}ide")
6971
self.dest = root.find(f"{URL}dest")
@@ -488,14 +490,23 @@ def _draw_void_watermark(self):
488490
is_protocol_available = bool(self.prot_nfe)
489491

490492
# Exit early if no watermark is needed
493+
font_size = 60
494+
if self.watermark_cancelled:
495+
if is_production_environment:
496+
watermark_text = "CANCELADA"
497+
else:
498+
watermark_text = "CANCELADA - SEM VALOR FISCAL"
499+
font_size = 45
500+
else:
501+
watermark_text = "SEM VALOR FISCAL"
502+
491503
if is_production_environment and is_protocol_available:
492504
return
505+
self.set_font(self.default_font, "B", font_size)
493506

494-
self.set_font(self.default_font, "B", 60)
495-
watermark_text = "SEM VALOR FISCAL"
496507
width = self.get_string_width(watermark_text)
497508
self.set_text_color(r=220, g=150, b=150)
498-
height = 15
509+
height = font_size * 0.25
499510
page_width = self.w
500511
page_height = self.h
501512
x_center = (page_width - width) / 2

docs/danfe.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Here is a breakdown of all the configuration options available in `DanfeConfig`:
141141
**Product Description Config**
142142

143143
- **Type**: `ProductDescriptionConfig`
144-
- **Fields**: `display_branch`, `branch_info_prefix`, `display_additional_info`, `display_anp` and `display_anvisa`.
144+
- **Fields**: `display_branch`, `branch_info_prefix`, `display_additional_info`, `display_anvisa`, `display_anp`.
145145
- **Description**: Whether or not to display the product branch in the DANFE product description.
146146
- **Example**:
147147
```python
@@ -162,6 +162,18 @@ Here is a breakdown of all the configuration options available in `DanfeConfig`:
162162

163163
---
164164

165+
**Watermark cancelled**
166+
167+
- **Type**: `Bool`
168+
- **Description**: Indicates whether the "CANCELADA" watermark should be displayed on the DANFE for a cancelled invoice.
169+
- **Example**:
170+
```python
171+
config.watermark_cancelled = True
172+
```
173+
- **Default**: `SEM VALOR FISCAL`.
174+
175+
---
176+
165177
### Usage Example with Customization
166178

167179
Here’s how to set up a ``DanfeConfig`` object with a full set of customizations::
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
3+
<infNFe versao="4.00" Id="NFe35200159594315000157550010000000022062777169">
4+
<ide>
5+
<cUF>35</cUF>
6+
<cNF>06277716</cNF>
7+
<natOp>Venda</natOp>
8+
<mod>55</mod>
9+
<serie>1</serie>
10+
<nNF>2</nNF>
11+
<dhEmi>2020-01-01T12:00:00+01:00</dhEmi>
12+
<dhSaiEnt>2020-01-01T12:00:00+01:00</dhSaiEnt>
13+
<tpNF>1</tpNF>
14+
<idDest>1</idDest>
15+
<cMunFG>3550308</cMunFG>
16+
<tpImp>1</tpImp>
17+
<tpEmis>1</tpEmis>
18+
<cDV>9</cDV>
19+
<tpAmb>1</tpAmb>
20+
<finNFe>1</finNFe>
21+
<indFinal>1</indFinal>
22+
<indPres>0</indPres>
23+
<procEmi>0</procEmi>
24+
<verProc>Odoo Brasil OCA v14</verProc>
25+
</ide>
26+
<emit>
27+
<CNPJ>81583054000129</CNPJ>
28+
<xNome>Empresa Lucro Presumido Ltda</xNome>
29+
<xFant>Empresa Lucro Presumido</xFant>
30+
<enderEmit>
31+
<xLgr>Avenida Paulista</xLgr>
32+
<nro>1</nro>
33+
<xCpl>Ao lado da casa</xCpl>
34+
<xBairro>Bela Vista</xBairro>
35+
<cMun>3550308</cMun>
36+
<xMun>São Paulo</xMun>
37+
<UF>SP</UF>
38+
<CEP>01311000</CEP>
39+
<cPais>1058</cPais>
40+
<xPais>Brasil</xPais>
41+
<fone>5511999999999</fone>
42+
</enderEmit>
43+
<IE>078016350838</IE>
44+
<CRT>3</CRT>
45+
</emit>
46+
<dest>
47+
<CPF>76586507812</CPF>
48+
<xNome>NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
49+
<enderDest>
50+
<xLgr>Rua do Bosque</xLgr>
51+
<nro>238</nro>
52+
<xBairro>Barra Funda</xBairro>
53+
<cMun>3550308</cMun>
54+
<xMun>São Paulo</xMun>
55+
<UF>SP</UF>
56+
<CEP>01136000</CEP>
57+
<cPais>1058</cPais>
58+
<xPais>Brasil</xPais>
59+
<fone>1138817417</fone>
60+
</enderDest>
61+
<indIEDest>1</indIEDest>
62+
<email>cliente11@cliente11.com.br</email>
63+
</dest>
64+
<det nItem="1">
65+
<prod>
66+
<cProd>FURN_9001</cProd>
67+
<cEAN>SEM GTIN</cEAN>
68+
<xProd>Flipover</xProd>
69+
<NCM>96100000</NCM>
70+
<CFOP>5102</CFOP>
71+
<uCom>UN</uCom>
72+
<qCom>300.0000</qCom>
73+
<vUnCom>1950.0000000000</vUnCom>
74+
<vProd>1950.00</vProd>
75+
<cEANTrib>SEM GTIN</cEANTrib>
76+
<uTrib>UN</uTrib>
77+
<qTrib>300.0000</qTrib>
78+
<vUnTrib>1950.0000000000</vUnTrib>
79+
<indTot>1</indTot>
80+
<rastro>
81+
<nLote>10252024</nLote>
82+
<dVal>2027-01-25</dVal>
83+
<qLote>200.000</qLote>
84+
<dFab>2024-05-01</dFab>
85+
</rastro>
86+
<rastro>
87+
<nLote>20252025</nLote>
88+
<dVal>2028-07-12</dVal>
89+
<qLote>100.000</qLote>
90+
<dFab>2024-01-25</dFab>
91+
</rastro>
92+
</prod>
93+
<imposto>
94+
<ICMS>
95+
<ICMS20>
96+
<orig>0</orig>
97+
<CST>20</CST>
98+
<modBC>0</modBC>
99+
<pRedBC>51.1100</pRedBC>
100+
<vBC>953.36</vBC>
101+
<pICMS>18.0000</pICMS>
102+
<vICMS>171.60</vICMS>
103+
</ICMS20>
104+
</ICMS>
105+
<IPI>
106+
<cEnq>999</cEnq>
107+
<IPINT>
108+
<CST>53</CST>
109+
</IPINT>
110+
</IPI>
111+
<PIS>
112+
<PISAliq>
113+
<CST>01</CST>
114+
<vBC>1950.00</vBC>
115+
<pPIS>0.6500</pPIS>
116+
<vPIS>12.68</vPIS>
117+
</PISAliq>
118+
</PIS>
119+
<COFINS>
120+
<COFINSAliq>
121+
<CST>01</CST>
122+
<vBC>1950.00</vBC>
123+
<pCOFINS>3.0000</pCOFINS>
124+
<vCOFINS>58.50</vCOFINS>
125+
</COFINSAliq>
126+
</COFINS>
127+
</imposto>
128+
<infAdProd>/ST: 469,53 FCP ST: R$ 25,38 (ID)</infAdProd>
129+
</det>
130+
<total>
131+
<ICMSTot>
132+
<vBC>953.36</vBC>
133+
<vICMS>171.60</vICMS>
134+
<vICMSDeson>0.00</vICMSDeson>
135+
<vFCP>0.00</vFCP>
136+
<vBCST>0.00</vBCST>
137+
<vST>0.00</vST>
138+
<vFCPST>0.00</vFCPST>
139+
<vFCPSTRet>0.00</vFCPSTRet>
140+
<vProd>1950.00</vProd>
141+
<vFrete>0.00</vFrete>
142+
<vSeg>0.00</vSeg>
143+
<vDesc>0.00</vDesc>
144+
<vII>0.00</vII>
145+
<vIPI>0.00</vIPI>
146+
<vIPIDevol>0.00</vIPIDevol>
147+
<vPIS>12.68</vPIS>
148+
<vCOFINS>58.50</vCOFINS>
149+
<vOutro>0.00</vOutro>
150+
<vNF>1950.00</vNF>
151+
</ICMSTot>
152+
</total>
153+
<transp>
154+
<modFrete>9</modFrete>
155+
</transp>
156+
<pag>
157+
<detPag>
158+
<indPag>0</indPag>
159+
<tPag>01</tPag>
160+
<vPag>1950.00</vPag>
161+
</detPag>
162+
</pag>
163+
<infAdic>
164+
<infAdFisco>Documento emitido por: Marc Demo</infAdFisco>
165+
</infAdic>
166+
</infNFe>
167+
</NFe>

0 commit comments

Comments
 (0)