From 49d1ab50ca8613207c022f9638ece692b73562f7 Mon Sep 17 00:00:00 2001 From: Danimar Ribeiro Date: Tue, 2 Oct 2018 17:16:40 -0300 Subject: [PATCH] [IMP] Fixing the fields for service invoices and danfe --- pytrustnfe/nfe/danfe.py | 51 +++++++++++-- pytrustnfe/nfe/templates/NfeAutorizacao.xml | 106 ++++++++++++++-------------- setup.py | 2 +- 3 files changed, 102 insertions(+), 57 deletions(-) diff --git a/pytrustnfe/nfe/danfe.py b/pytrustnfe/nfe/danfe.py index 00c500e..12c30a7 100644 --- a/pytrustnfe/nfe/danfe.py +++ b/pytrustnfe/nfe/danfe.py @@ -197,7 +197,8 @@ class danfe(object): oXML=oXML, el_det=el_det, max_index=nId, list_desc=list_desc, list_cod_prod=list_cod_prod) - self.adicionais(oXML=oXML) + tamanho_ocupado = self.calculo_issqn(oXML=oXML) + self.adicionais(oXML=oXML, tamanho_diminuir=tamanho_ocupado) # Gera o restante das páginas do XML while index < nId: @@ -779,7 +780,49 @@ obsCont[@xCampo='NomeVendedor']") self.nlin += nH + 3 return id - def adicionais(self, oXML=None): + def calculo_issqn(self, oXML=None): + elem_emit = oXML.find(".//{http://www.portalfiscal.inf.br/nfe}emit") + el_total = oXML.find(".//{http://www.portalfiscal.inf.br/nfe}total") + issqn_total = el_total.find( + ".//{http://www.portalfiscal.inf.br/nfe}ISSQNtot") + if not issqn_total: + return 0 + + self.nlin += 1 + nMr = self.width - self.nRight + self.canvas.setFont('NimbusSanL-Bold', 7) + self.string(self.nLeft + 1, self.nlin + 1, 'CÁLCULO DO ISSQN') + self.rect(self.nLeft, self.nlin + 2, + self.width - self.nLeft - self.nRight, 5.5) + self.vline(nMr - 47.5, self.nlin + 2, 5.5) + self.vline(nMr - 95, self.nlin + 2, 5.5) + self.vline(nMr - 142.5, self.nlin + 2, 5.5) + self.vline(nMr - 190, self.nlin + 2, 5.5) + # Labels + self.canvas.setFont('NimbusSanL-Regu', 5) + self.string(self.nLeft + 1, self.nlin + 3.8, 'INSCRIÇÃO MUNICIPAL') + self.string(nMr - 141.5, self.nlin + 3.8, 'VALOR TOTAL DOS SERVIÇOS') + self.string(nMr - 94, self.nlin + 3.8, 'BASE DE CÁLCULO DO ISSQN') + self.string(nMr - 46.5, self.nlin + 3.8, 'VALOR DO ISSQN') + # Conteúdo campos + self.canvas.setFont('NimbusSanL-Regu', 8) + self.string( + self.nLeft + 1, self.nlin + 6.7, + tagtext(oNode=elem_emit, cTag='IM')) + self.stringRight( + self.nLeft + 94, self.nlin + 6.7, + format_number(tagtext(oNode=issqn_total, cTag='vServ'))) + self.stringRight( + self.nLeft + 141.5, self.nlin + 6.7, + format_number(tagtext(oNode=issqn_total, cTag='vBC'))) + self.stringRight( + self.nLeft + 189, self.nlin + 6.7, + format_number(tagtext(oNode=issqn_total, cTag='vISS'))) + + self.nlin += 8 # Nr linhas ocupadas pelo bloco + return 8 + + def adicionais(self, oXML=None, tamanho_diminuir=0): el_infAdic = oXML.find( ".//{http://www.portalfiscal.inf.br/nfe}infAdic") @@ -791,8 +834,8 @@ obsCont[@xCampo='NomeVendedor']") 'INFORMAÇÕES COMPLEMENTARES') self.string((self.width / 2) + 1, self.nlin + 4, 'RESERVADO AO FISCO') self.rect(self.nLeft, self.nlin + 2, - self.width - self.nLeft - self.nRight, 42) - self.vline(self.width / 2, self.nlin + 2, 42) + self.width - self.nLeft - self.nRight, 42 - tamanho_diminuir) + self.vline(self.width / 2, self.nlin + 2, 42 - tamanho_diminuir) # Conteúdo campos styles = getSampleStyleSheet() styleN = styles['Normal'] diff --git a/pytrustnfe/nfe/templates/NfeAutorizacao.xml b/pytrustnfe/nfe/templates/NfeAutorizacao.xml index bf1cc8b..1a616a0 100644 --- a/pytrustnfe/nfe/templates/NfeAutorizacao.xml +++ b/pytrustnfe/nfe/templates/NfeAutorizacao.xml @@ -266,6 +266,7 @@ {% with imposto = det.imposto %} {{ imposto.vTotTrib }} + {% if imposto.ICMS is defined %} {% if imposto.ICMS.CST == '00' -%} @@ -529,37 +530,58 @@ {% endif %} - {% if NFe.infNFe.ide.mod != '65' %} - - {{ imposto.IPI.clEnq }} - {{ imposto.IPI.CNPJProd }} - {{ imposto.IPI.cSelo }} - {{ imposto.IPI.qSelo }} - {{ imposto.IPI.cEnq }} - {% if imposto.IPI.CST in ('00', '49', '50', '99') %} - - {{ imposto.IPI.CST }} - {{ imposto.IPI.vBC }} - {{ imposto.IPI.pIPI }} - {{ imposto.IPI.qUnid }} - {{ imposto.IPI.vUnid }} - {{ imposto.IPI.vIPI }} - - {% endif %} - {% if imposto.IPI.CST in ('01', '02', '03', '04', '51', '52', '53', '54', '55') %} - - {{ imposto.IPI.CST }} - - {% endif %} - - {% if imposto.II is defined %} - - {{ imposto.II.vBC }} - {{ imposto.II.vDespAdu }} - {{ imposto.II.vII }} - {{ imposto.II.vIOF }} - {% endif %} + {% if NFe.infNFe.ide.mod != '65' and imposto.IPI is defined %} + + {{ imposto.IPI.clEnq }} + {{ imposto.IPI.CNPJProd }} + {{ imposto.IPI.cSelo }} + {{ imposto.IPI.qSelo }} + {{ imposto.IPI.cEnq }} + {% if imposto.IPI.CST in ('00', '49', '50', '99') %} + + {{ imposto.IPI.CST }} + {{ imposto.IPI.vBC }} + {{ imposto.IPI.pIPI }} + {{ imposto.IPI.qUnid }} + {{ imposto.IPI.vUnid }} + {{ imposto.IPI.vIPI }} + + {% endif %} + {% if imposto.IPI.CST in ('01', '02', '03', '04', '51', '52', '53', '54', '55') %} + + {{ imposto.IPI.CST }} + + {% endif %} + + {% if imposto.II is defined %} + + {{ imposto.II.vBC }} + {{ imposto.II.vDespAdu }} + {{ imposto.II.vII }} + {{ imposto.II.vIOF }} + + {% endif %} + {% endif %} + {% if imposto.ISSQN is defined %} + + {{ imposto.ISSQN.vBC }} + {{ imposto.ISSQN.vAliq }} + {{ imposto.ISSQN.vISSQN }} + {{ imposto.ISSQN.cMunFG }} + {{ imposto.ISSQN.cListServ }} + {{ imposto.ISSQN.vDeducao }} + {{ imposto.ISSQN.vOutro }} + {{ imposto.ISSQN.vDescIncond }} + {{ imposto.ISSQN.vDescCond }} + {{ imposto.ISSQN.vDeducao }} + {{ imposto.ISSQN.indISS }} + {{ imposto.ISSQN.cServico }} + {{ imposto.ISSQN.cMun }} + {{ imposto.ISSQN.cPais }} + {{ imposto.ISSQN.nProcesso }} + {{ imposto.ISSQN.indIncentivo }} + {% endif %} {% if imposto.PIS.CST in ('01', '02') %} @@ -637,33 +659,13 @@ {% endif %} {% if imposto.COFINSST is defined %} - + {{ imposto.COFINSST.vBC }} {{ imposto.COFINSST.pCOFINS }} {{ imposto.COFINSST.qBCProd }} {{ imposto.COFINSST.vAliqProd }} {{ imposto.COFINSST.vCOFINS }} - - {% endif %} - {% if imposto.ISSQN is defined %} - - {{ imposto.ISSQN.vBC }} - {{ imposto.ISSQN.vAliq }} - {{ imposto.ISSQN.vISSQN }} - {{ imposto.ISSQN.cMunFG }} - {{ imposto.ISSQN.cListServ }} - {{ imposto.ISSQN.vDeducao }} - {{ imposto.ISSQN.vOutro }} - {{ imposto.ISSQN.vDescIncond }} - {{ imposto.ISSQN.vDescCond }} - {{ imposto.ISSQN.vDeducao }} - {{ imposto.ISSQN.indISS }} - {{ imposto.ISSQN.cServico }} - {{ imposto.ISSQN.cMun }} - {{ imposto.ISSQN.cPais }} - {{ imposto.ISSQN.nProcesso }} - {{ imposto.ISSQN.vDeducao }} - + {% endif %} {% if imposto.ICMSUFDest is defined %} diff --git a/setup.py b/setup.py index e22686c..d596afb 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -VERSION = "1.0.10" +VERSION = "1.0.11" setup(