Browse Source

Criado classe para geração do danfe

tags/0.1.5
Danimar Ribeiro 11 years ago
parent
commit
12f172cb9a
  1. 53
      pytrustnfe/pdf/Danfe.py
  2. 5
      pytrustnfe/pdf/__init__.py
  3. 1
      pytrustnfe/servicos/Comunicacao.py
  4. 4
      pytrustnfe/test/test_comunicacao.py
  5. 18
      pytrustnfe/test/test_danfe.py

53
pytrustnfe/pdf/Danfe.py

@ -0,0 +1,53 @@
# coding=utf-8
'''
Created on 01/07/2015
@author: danimar
'''
from pytrustnfe.xml.DynamicXml import DynamicXml
from reportlab.platypus.tables import Table
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import A4
from reportlab.platypus.doctemplate import SimpleDocTemplate
from reportlab.lib import colors
inch = 28.34
class Danfe(object):
objeto = None
def __init__(self, objetoNFe):
assert isinstance(objetoNFe, DynamicXml),\
'ObjetoNFe deve ser do tipo DynamicXml'
self.objeto = objetoNFe
def gerar(self):
doc = SimpleDocTemplate(
'/home/danimar/projetos/pdfs/danfe.pdf',
pagesize=A4, leftMargin=0.5 * inch, rightMargin=0.5 * inch,
topMargin=0.5 * inch, bottomMargin=0.5 * inch)
elementos = []
data = [
['Recebemos de verdesaine industria e comércio os produtos constantes na nota fiscal abaixo ', '',
'NF-e\nNº 000.000.001\nSérie 001'],
['Data de recebimento',
'Identificação e assinatura do recebedor',
'']
]
estilo = [('SPAN', (0, 0), (1, 0)),
('SPAN', (2, 0), (2, 1)),
('FONTSIZE', (0, 0), (1, 1), 8.0),
('VALIGN', (0, 0), (1, 1), 'TOP'),
('ALIGN', (2, 0), (2, 1), 'CENTER'),
('GRID', (0, 0), (3, 1), 1, colors.black)]
colunas = [4 * inch, 12 * inch, 4 * inch]
table = Table(data, style=estilo, colWidths=colunas)
elementos.append(table)
doc.build(elementos)

5
pytrustnfe/pdf/__init__.py

@ -0,0 +1,5 @@
'''
Created on 01/07/2015
@author: danimar
'''

1
pytrustnfe/servicos/Comunicacao.py

@ -97,6 +97,7 @@ class Comunicacao(object):
obj = objectify.fromstring(nodes[0].toxml()) obj = objectify.fromstring(nodes[0].toxml())
return nodes[0].toxml(), obj return nodes[0].toxml(), obj
return xml_retorno, objectify.fromstring(xml_retorno)

4
pytrustnfe/test/test_comunicacao.py

@ -29,6 +29,10 @@ class test_comunicacao(unittest.TestCase):
conn.getresponse.return_value = retorno conn.getresponse.return_value = retorno
com = Comunicacao(dir_pfx, '123456') com = Comunicacao(dir_pfx, '123456')
com.url = 'nfe.sefaz.gov.br'
com.web_service = '/wsTeste'
com.metodo = 'teste'
com.tag_retorno = 'testResult'
xml, objeto = com._executar_consulta('') xml, objeto = com._executar_consulta('')
self.assertEqual(xml, XML_RETORNO, 'Envio de NF-e com problemas - xml de retorno inválido') self.assertEqual(xml, XML_RETORNO, 'Envio de NF-e com problemas - xml de retorno inválido')

18
pytrustnfe/test/test_danfe.py

@ -0,0 +1,18 @@
'''
Created on 01/07/2015
@author: danimar
'''
import unittest
from pytrustnfe.pdf.Danfe import Danfe
from pytrustnfe.xml.DynamicXml import DynamicXml
class test_danfe(unittest.TestCase):
def test_geracao_danfe(self):
nfe = DynamicXml('ProtNFe')
pdf = Danfe(nfe)
pdf.gerar()
Loading…
Cancel
Save