Skip to content

Commit 19840a9

Browse files
felps-devclaude
andcommitted
style: Fix ruff format issues in serializacao.py and reforma tributaria tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7c830b1 commit 19840a9

2 files changed

Lines changed: 58 additions & 114 deletions

File tree

pynfe/processamento/serializacao.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,12 +1335,8 @@ def _serializar_cbs(self, produto_servico, tag_raiz):
13351335
etree.SubElement(cbs, "vBC").text = "{:.2f}".format(
13361336
produto_servico.cbs_valor_base_calculo or 0
13371337
)
1338-
etree.SubElement(cbs, "pCBS").text = "{:.4f}".format(
1339-
produto_servico.cbs_aliquota or 0
1340-
)
1341-
etree.SubElement(cbs, "vCBS").text = "{:.2f}".format(
1342-
produto_servico.cbs_valor or 0
1343-
)
1338+
etree.SubElement(cbs, "pCBS").text = "{:.4f}".format(produto_servico.cbs_aliquota or 0)
1339+
etree.SubElement(cbs, "vCBS").text = "{:.2f}".format(produto_servico.cbs_valor or 0)
13441340

13451341
def _serializar_ibs(self, produto_servico, tag_raiz):
13461342
"""Serializa IBS (Imposto sobre Bens e Servicos)."""
@@ -1351,17 +1347,11 @@ def _serializar_ibs(self, produto_servico, tag_raiz):
13511347
etree.SubElement(ibs, "vBC").text = "{:.2f}".format(
13521348
produto_servico.ibs_valor_base_calculo or 0
13531349
)
1354-
etree.SubElement(ibs, "pIBS").text = "{:.4f}".format(
1355-
produto_servico.ibs_aliquota or 0
1356-
)
1357-
etree.SubElement(ibs, "vIBS").text = "{:.2f}".format(
1358-
produto_servico.ibs_valor or 0
1359-
)
1350+
etree.SubElement(ibs, "pIBS").text = "{:.4f}".format(produto_servico.ibs_aliquota or 0)
1351+
etree.SubElement(ibs, "vIBS").text = "{:.2f}".format(produto_servico.ibs_valor or 0)
13601352

13611353
if produto_servico.ibs_codigo_municipio_destino:
1362-
etree.SubElement(ibs, "cMunDest").text = (
1363-
produto_servico.ibs_codigo_municipio_destino
1364-
)
1354+
etree.SubElement(ibs, "cMunDest").text = produto_servico.ibs_codigo_municipio_destino
13651355

13661356
def _serializar_is(self, produto_servico, tag_raiz):
13671357
"""Serializa IS (Imposto Seletivo)."""
@@ -1372,12 +1362,8 @@ def _serializar_is(self, produto_servico, tag_raiz):
13721362
etree.SubElement(is_tag, "vBC").text = "{:.2f}".format(
13731363
produto_servico.is_valor_base_calculo or 0
13741364
)
1375-
etree.SubElement(is_tag, "pIS").text = "{:.4f}".format(
1376-
produto_servico.is_aliquota or 0
1377-
)
1378-
etree.SubElement(is_tag, "vIS").text = "{:.2f}".format(
1379-
produto_servico.is_valor or 0
1380-
)
1365+
etree.SubElement(is_tag, "pIS").text = "{:.4f}".format(produto_servico.is_aliquota or 0)
1366+
etree.SubElement(is_tag, "vIS").text = "{:.2f}".format(produto_servico.is_valor or 0)
13811367

13821368
def _serializar_declaracao_importacao(
13831369
self, produto_servico, tag_raiz="prod", retorna_string=True
@@ -1779,17 +1765,11 @@ def _serializar_nota_fiscal(self, nota_fiscal, tag_raiz="infNFe", retorna_string
17791765

17801766
# Reforma Tributaria - Totais IVA Dual
17811767
if nota_fiscal.totais_cbs:
1782-
etree.SubElement(icms_total, "vCBS").text = "{:.2f}".format(
1783-
nota_fiscal.totais_cbs
1784-
)
1768+
etree.SubElement(icms_total, "vCBS").text = "{:.2f}".format(nota_fiscal.totais_cbs)
17851769
if nota_fiscal.totais_ibs:
1786-
etree.SubElement(icms_total, "vIBS").text = "{:.2f}".format(
1787-
nota_fiscal.totais_ibs
1788-
)
1770+
etree.SubElement(icms_total, "vIBS").text = "{:.2f}".format(nota_fiscal.totais_ibs)
17891771
if nota_fiscal.totais_is:
1790-
etree.SubElement(icms_total, "vIS").text = "{:.2f}".format(
1791-
nota_fiscal.totais_is
1792-
)
1772+
etree.SubElement(icms_total, "vIS").text = "{:.2f}".format(nota_fiscal.totais_is)
17931773

17941774
# Transporte
17951775
transp = etree.SubElement(raiz, "transp")

tests/test_nfe_serializacao_reforma_tributaria.py

Lines changed: 48 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ def test_cst01_cbs_ibs_is_tributada_integralmente(self):
151151
xml = self._serializar_e_assinar()
152152

153153
# impostoMisto group exists
154-
imposto_misto = xml.xpath(
155-
"//ns:det/ns:imposto/ns:impostoMisto", namespaces=self.ns
156-
)
154+
imposto_misto = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto", namespaces=self.ns)
157155
self.assertEqual(len(imposto_misto), 1)
158156

159157
# CBS
@@ -167,14 +165,14 @@ def test_cst01_cbs_ibs_is_tributada_integralmente(self):
167165
)[0].text
168166
self.assertEqual(vbc_cbs, "1000.00")
169167

170-
pcbs = xml.xpath(
171-
"//ns:det/ns:imposto/ns:impostoMisto/ns:CBS/ns:pCBS", namespaces=self.ns
172-
)[0].text
168+
pcbs = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:CBS/ns:pCBS", namespaces=self.ns)[
169+
0
170+
].text
173171
self.assertEqual(pcbs, "8.8000")
174172

175-
vcbs = xml.xpath(
176-
"//ns:det/ns:imposto/ns:impostoMisto/ns:CBS/ns:vCBS", namespaces=self.ns
177-
)[0].text
173+
vcbs = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:CBS/ns:vCBS", namespaces=self.ns)[
174+
0
175+
].text
178176
self.assertEqual(vcbs, "88.00")
179177

180178
# IBS
@@ -188,14 +186,14 @@ def test_cst01_cbs_ibs_is_tributada_integralmente(self):
188186
)[0].text
189187
self.assertEqual(vbc_ibs, "1000.00")
190188

191-
pibs = xml.xpath(
192-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IBS/ns:pIBS", namespaces=self.ns
193-
)[0].text
189+
pibs = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IBS/ns:pIBS", namespaces=self.ns)[
190+
0
191+
].text
194192
self.assertEqual(pibs, "17.7000")
195193

196-
vibs = xml.xpath(
197-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IBS/ns:vIBS", namespaces=self.ns
198-
)[0].text
194+
vibs = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IBS/ns:vIBS", namespaces=self.ns)[
195+
0
196+
].text
199197
self.assertEqual(vibs, "177.00")
200198

201199
cmun = xml.xpath(
@@ -204,46 +202,38 @@ def test_cst01_cbs_ibs_is_tributada_integralmente(self):
204202
self.assertEqual(cmun, "4118402")
205203

206204
# IS
207-
cst_is = xml.xpath(
208-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:CST", namespaces=self.ns
209-
)[0].text
205+
cst_is = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:CST", namespaces=self.ns)[
206+
0
207+
].text
210208
self.assertEqual(cst_is, "01")
211209

212-
vbc_is = xml.xpath(
213-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:vBC", namespaces=self.ns
214-
)[0].text
210+
vbc_is = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:vBC", namespaces=self.ns)[
211+
0
212+
].text
215213
self.assertEqual(vbc_is, "1000.00")
216214

217-
pis_val = xml.xpath(
218-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:pIS", namespaces=self.ns
219-
)[0].text
215+
pis_val = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:pIS", namespaces=self.ns)[
216+
0
217+
].text
220218
self.assertEqual(pis_val, "1.0000")
221219

222-
vis = xml.xpath(
223-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:vIS", namespaces=self.ns
224-
)[0].text
220+
vis = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IS/ns:vIS", namespaces=self.ns)[
221+
0
222+
].text
225223
self.assertEqual(vis, "10.00")
226224

227225
# Totals
228-
vcbs_total = xml.xpath(
229-
"//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns
230-
)[0].text
226+
vcbs_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns)[0].text
231227
self.assertEqual(vcbs_total, "88.00")
232228

233-
vibs_total = xml.xpath(
234-
"//ns:total/ns:ICMSTot/ns:vIBS", namespaces=self.ns
235-
)[0].text
229+
vibs_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vIBS", namespaces=self.ns)[0].text
236230
self.assertEqual(vibs_total, "177.00")
237231

238-
vis_total = xml.xpath(
239-
"//ns:total/ns:ICMSTot/ns:vIS", namespaces=self.ns
240-
)[0].text
232+
vis_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vIS", namespaces=self.ns)[0].text
241233
self.assertEqual(vis_total, "10.00")
242234

243235
# vNF includes IBS/CBS/IS
244-
vnf = xml.xpath(
245-
"//ns:total/ns:ICMSTot/ns:vNF", namespaces=self.ns
246-
)[0].text
236+
vnf = xml.xpath("//ns:total/ns:ICMSTot/ns:vNF", namespaces=self.ns)[0].text
247237
self.assertEqual(vnf, "1275.00")
248238

249239
# ------------------------------------------------------------------
@@ -293,9 +283,7 @@ def test_cst03_isencao_sem_valores(self):
293283
xml = self._serializar_e_assinar()
294284

295285
# impostoMisto group exists (CBS + IBS present even if exempt)
296-
imposto_misto = xml.xpath(
297-
"//ns:det/ns:imposto/ns:impostoMisto", namespaces=self.ns
298-
)
286+
imposto_misto = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto", namespaces=self.ns)
299287
self.assertEqual(len(imposto_misto), 1)
300288

301289
# CBS CST present, no value tags
@@ -304,9 +292,7 @@ def test_cst03_isencao_sem_valores(self):
304292
)[0].text
305293
self.assertEqual(cst_cbs, "03")
306294

307-
vbc_cbs = xml.xpath(
308-
"//ns:det/ns:imposto/ns:impostoMisto/ns:CBS/ns:vBC", namespaces=self.ns
309-
)
295+
vbc_cbs = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:CBS/ns:vBC", namespaces=self.ns)
310296
self.assertEqual(len(vbc_cbs), 0) # No vBC for CST 03
311297

312298
# IBS CST present, no value tags
@@ -315,21 +301,15 @@ def test_cst03_isencao_sem_valores(self):
315301
)[0].text
316302
self.assertEqual(cst_ibs, "03")
317303

318-
vbc_ibs = xml.xpath(
319-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IBS/ns:vBC", namespaces=self.ns
320-
)
304+
vbc_ibs = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IBS/ns:vBC", namespaces=self.ns)
321305
self.assertEqual(len(vbc_ibs), 0)
322306

323307
# No IS group
324-
is_group = xml.xpath(
325-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IS", namespaces=self.ns
326-
)
308+
is_group = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IS", namespaces=self.ns)
327309
self.assertEqual(len(is_group), 0)
328310

329311
# No totals for CBS/IBS/IS (all zero)
330-
vcbs_total = xml.xpath(
331-
"//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns
332-
)
312+
vcbs_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns)
333313
self.assertEqual(len(vcbs_total), 0)
334314

335315
# ------------------------------------------------------------------
@@ -374,20 +354,14 @@ def test_sem_reforma_tributaria_sem_imposto_misto(self):
374354
xml = self._serializar_e_assinar()
375355

376356
# impostoMisto should NOT exist
377-
imposto_misto = xml.xpath(
378-
"//ns:det/ns:imposto/ns:impostoMisto", namespaces=self.ns
379-
)
357+
imposto_misto = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto", namespaces=self.ns)
380358
self.assertEqual(len(imposto_misto), 0)
381359

382360
# No reform totals
383-
vcbs_total = xml.xpath(
384-
"//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns
385-
)
361+
vcbs_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns)
386362
self.assertEqual(len(vcbs_total), 0)
387363

388-
vibs_total = xml.xpath(
389-
"//ns:total/ns:ICMSTot/ns:vIBS", namespaces=self.ns
390-
)
364+
vibs_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vIBS", namespaces=self.ns)
391365
self.assertEqual(len(vibs_total), 0)
392366

393367
# ------------------------------------------------------------------
@@ -479,29 +453,21 @@ def test_totais_acumulacao_multiplos_produtos(self):
479453
xml = self._serializar_e_assinar()
480454

481455
# Accumulated totals: CBS=132.00, IBS=265.50, IS=15.00
482-
vcbs_total = xml.xpath(
483-
"//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns
484-
)[0].text
456+
vcbs_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vCBS", namespaces=self.ns)[0].text
485457
self.assertEqual(vcbs_total, "132.00")
486458

487-
vibs_total = xml.xpath(
488-
"//ns:total/ns:ICMSTot/ns:vIBS", namespaces=self.ns
489-
)[0].text
459+
vibs_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vIBS", namespaces=self.ns)[0].text
490460
self.assertEqual(vibs_total, "265.50")
491461

492-
vis_total = xml.xpath(
493-
"//ns:total/ns:ICMSTot/ns:vIS", namespaces=self.ns
494-
)[0].text
462+
vis_total = xml.xpath("//ns:total/ns:ICMSTot/ns:vIS", namespaces=self.ns)[0].text
495463
self.assertEqual(vis_total, "15.00")
496464

497465
# vNF = 1000 + 500 + 132 + 265.50 + 15 = 1912.50
498466
# Wait: vNF = sum of (vProd + IBS + CBS + IS) for each product
499467
# Prod1: 1000 + 177 + 88 + 10 = 1275
500468
# Prod2: 500 + 88.50 + 44 + 5 = 637.50
501469
# Total: 1275 + 637.50 = 1912.50
502-
vnf = xml.xpath(
503-
"//ns:total/ns:ICMSTot/ns:vNF", namespaces=self.ns
504-
)[0].text
470+
vnf = xml.xpath("//ns:total/ns:ICMSTot/ns:vNF", namespaces=self.ns)[0].text
505471
self.assertEqual(vnf, "1912.50")
506472

507473
# ------------------------------------------------------------------
@@ -562,15 +528,15 @@ def test_misto_legacy_icms_pis_cofins_com_ibs_cbs(self):
562528
xml = self._serializar_e_assinar()
563529

564530
# Legacy ICMS still present
565-
icms_cst = xml.xpath(
566-
"//ns:det/ns:imposto/ns:ICMS/ns:ICMS00/ns:CST", namespaces=self.ns
567-
)[0].text
531+
icms_cst = xml.xpath("//ns:det/ns:imposto/ns:ICMS/ns:ICMS00/ns:CST", namespaces=self.ns)[
532+
0
533+
].text
568534
self.assertEqual(icms_cst, "00")
569535

570536
# Legacy PIS still present
571-
pis_cst = xml.xpath(
572-
"//ns:det/ns:imposto/ns:PIS/ns:PISAliq/ns:CST", namespaces=self.ns
573-
)[0].text
537+
pis_cst = xml.xpath("//ns:det/ns:imposto/ns:PIS/ns:PISAliq/ns:CST", namespaces=self.ns)[
538+
0
539+
].text
574540
self.assertEqual(pis_cst, "01")
575541

576542
# Legacy COFINS still present
@@ -592,9 +558,7 @@ def test_misto_legacy_icms_pis_cofins_com_ibs_cbs(self):
592558
self.assertEqual(ibs_cst, "02")
593559

594560
# No IS in this test
595-
is_group = xml.xpath(
596-
"//ns:det/ns:imposto/ns:impostoMisto/ns:IS", namespaces=self.ns
597-
)
561+
is_group = xml.xpath("//ns:det/ns:imposto/ns:impostoMisto/ns:IS", namespaces=self.ns)
598562
self.assertEqual(len(is_group), 0)
599563

600564

0 commit comments

Comments
 (0)