From b8502f186c8356087216ad99d6df0931432be385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Luna?= Date: Sat, 28 Mar 2020 00:41:08 -0300 Subject: [PATCH] Melhoria na DANFE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implementa blocos para impressão do endereço de entrega e endereço de retirada, conforme a NT2018 005. --- pytrustnfe/nfe/danfe.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++- setup.py | 2 +- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/pytrustnfe/nfe/danfe.py b/pytrustnfe/nfe/danfe.py index c8f99c8..742b6ad 100644 --- a/pytrustnfe/nfe/danfe.py +++ b/pytrustnfe/nfe/danfe.py @@ -125,6 +125,7 @@ class danfe(object): timezone=None, ): + tamanho_ocupado = 0 path = os.path.join(os.path.dirname(__file__), "fonts") pdfmetrics.registerFont( TTFont("NimbusSanL-Regu", os.path.join(path, "NimbusSanL Regular.ttf")) @@ -197,6 +198,8 @@ class danfe(object): self.ide_emit(oXML=oXML, timezone=timezone) self.destinatario(oXML=oXML, timezone=timezone) + tamanho_ocupado += self.entrega_retirada( + oXML=oXML, timezone=timezone) if oXML_cobr is not None: self.faturas(oXML=oXML_cobr, timezone=timezone) @@ -212,7 +215,7 @@ class danfe(object): list_cod_prod=list_cod_prod, ) - tamanho_ocupado = self.calculo_issqn(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 @@ -488,6 +491,75 @@ class danfe(object): self.nlin += 24 # Nr linhas ocupadas pelo bloco + def entrega_retirada(self, oXML=None, timezone=None): + elem_entrega = oXML.find(".//{http://www.portalfiscal.inf.br/nfe}entrega") + elem_retirada = oXML.find(".//{http://www.portalfiscal.inf.br/nfe}retirada") + self.canvas.setFont("NimbusSanL-Bold", 7) + + if elem_entrega: + elem = elem_entrega + self.string(self.nLeft + 1, self.nlin + 1, "INFORMAÇÕES DO LOCAL DE ENTREGA") + elif elem_retirada: + elem = elem_retirada + self.string(self.nLeft + 1, self.nlin + 1, "INFORMAÇÕES DO LOCAL DE RETIRADA") + else: + return 0 + + nMr = self.width - self.nRight + + self.nlin += 1 + + self.rect(self.nLeft, self.nlin + 2, self.width - self.nLeft - self.nRight, 20) + self.hline(self.nLeft, self.nlin + 8.66, self.width - self.nLeft) + self.hline(self.nLeft, self.nlin + 15.32, self.width - self.nLeft) + self.vline(nMr - 25, self.nlin + 2, 6.66) + self.vline(nMr - 70, self.nlin + 2, 6.66) + self.vline(nMr - 25, self.nlin + 8.66, 6.66) + self.vline(nMr - 90, self.nlin + 8.66, 6.66) + self.vline(nMr - 25, self.nlin + 15.32, 6.66) + self.vline(nMr - 37, self.nlin + 15.32, 6.66) + # Labels/Fields + self.canvas.setFont("NimbusSanL-Bold", 5) + self.string(self.nLeft + 1, self.nlin + 3.7, "NOME/RAZÃO SOCIAL") + self.string(nMr - 69, self.nlin + 3.7, "CNPJ/CPF") + self.string(nMr - 24, self.nlin + 3.7, "INSCRIÇÃO ESTADUAL") + self.string(self.nLeft + 1, self.nlin + 10.3, "ENDEREÇO") + self.string(nMr - 89, self.nlin + 10.3, "BAIRRO/DISTRITO") + self.string(nMr - 24, self.nlin + 10.3, "CEP") + self.string(self.nLeft + 1, self.nlin + 17.1, "MUNICÍPIO") + self.string(nMr - 24, self.nlin + 17.1, "FONE/FAX") + self.string(nMr - 36, self.nlin + 17.1, "UF") + # Conteúdo campos + self.canvas.setFont("NimbusSanL-Regu", 8) + self.string( + self.nLeft + 1, self.nlin + 7.5, tagtext(oNode=elem, cTag="xNome") + ) + cnpj_cpf = tagtext(oNode=elem, cTag="CNPJ") + if cnpj_cpf: + cnpj_cpf = format_cnpj_cpf(cnpj_cpf) + else: + cnpj_cpf = format_cnpj_cpf(tagtext(oNode=elem, cTag="CPF")) + self.string(nMr - 69, self.nlin + 7.5, cnpj_cpf) + self.string(nMr - 24, self.nlin + 7.5, tagtext(oNode=elem, cTag="IE")) + cEnd = "%s, %s %s" % ( + tagtext(oNode=elem, cTag="xLgr"), + tagtext(oNode=elem, cTag="nro"), + tagtext(oNode=elem, cTag="xCpl"), + ) + self.string(self.nLeft + 1, self.nlin + 14.3, cEnd) + self.string( + nMr - 89, self.nlin + 14.3, tagtext(oNode=elem, cTag="xBairro") + ) + self.string(nMr - 24, self.nlin + 14.3, tagtext(oNode=elem, cTag="CEP")) + self.string( + self.nLeft + 1, self.nlin + 21.1, tagtext(oNode=elem, cTag="xMun") + ) + self.string(nMr - 36, self.nlin + 21.1, tagtext(oNode=elem, cTag="UF")) + self.string(nMr - 24, self.nlin + 21.1, tagtext(oNode=elem, cTag="fone")) + + self.nlin += 24 # Nr linhas ocupadas pelo bloco + return 24 + def faturas(self, oXML=None, timezone=None): nMr = self.width - self.nRight diff --git a/setup.py b/setup.py index f99efb7..187eb61 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -VERSION = "1.0.51" +VERSION = "1.0.52" setup(