Skip to content

Inclusão de envio de valores no campo linha digitável e código de barras #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pyboleto/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CustomProperty(object):
:type length: integer

"""

def __init__(self, name, length):
self.name = name
self.length = length
Expand Down Expand Up @@ -117,6 +118,8 @@ class BoletoData(object):

**Parâmetros não obrigatórios**:

:param codigo_barras: Se o codigo de barras for informado, não calcula
:param linha_digitavel_ext: Se a linha digitável for informada (com espaços), não calcula
:param quantidade:
:param especie: Nunca precisa mudar essa opção *(default: 'R$')*
:param especie_documento:
Expand Down Expand Up @@ -161,6 +164,8 @@ def __init__(self, **kwargs):
self.sacado_endereco = kwargs.pop('sacado_endereco', "")
self.sacado_bairro = kwargs.pop('sacado_bairro', "")
self.sacado_cep = kwargs.pop('sacado_cep', "")
self.codigo_barras = kwargs.pop('codigo_barras', "")
self.linha_digitavel_ext = kwargs.pop('linha_digitavel_ext', "")
if kwargs:
raise TypeError("Paramêtro(s) desconhecido: %r" % (kwargs, ))
self._cedente_endereco = None
Expand All @@ -187,6 +192,9 @@ def barcode(self):
Total 44
"""

if self.codigo_barras != "":
return self.codigo_barras

for attr, length, data_type in [
('codigo_banco', 3, str),
('moeda', 1, str),
Expand Down Expand Up @@ -435,6 +443,10 @@ def linha_digitavel(self):
Esta é a linha que o cliente pode utilizar para digitar se o código
de barras não estiver legível.
"""

if self.linha_digitavel_ext != "":
return self.linha_digitavel_ext

linha = self.barcode
if not linha:
raise BoletoException("Boleto doesn't have a barcode")
Expand Down
2 changes: 1 addition & 1 deletion pyboleto/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def drawBoletoCarneDuplo(self, boletoDados1, boletoDados2=None):
d = self.drawBoletoCarne(boletoDados1, y)
y += d[1] + 6 * mm
# self._drawHorizontalCorteLine(0, y, d[0])
y += 7 * mm
# y += 7 * mm
if boletoDados2:
self.drawBoletoCarne(boletoDados2, y)

Expand Down
58 changes: 58 additions & 0 deletions tests/test_banco_itau_com_dados_calculados.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
import unittest
import datetime

from pyboleto.bank.itau import BoletoItau

from .testutils import BoletoTestCase


class TestBancoItauComDadosCalculados(unittest.TestCase):
def setUp(self):
self.dados = []
for i in range(3):
d = BoletoItau()
d.carteira = '109'
d.agencia_cedente = '0293'
d.conta_cedente = '01328'
d.conta_cedente_dv = '1'
d.data_vencimento = datetime.date(2009, 10, 19)
d.data_documento = datetime.date(2009, 10, 19)
d.data_processamento = datetime.date(2009, 10, 19)
d.valor_documento = 29.80
d.nosso_numero = str(157 + i)
d.numero_documento = str(456 + i)
d.linha_digitavel_ext = "34191.09008 00015.710296 30132.810000 4 43950000002888"
d.codigo_barras = "34194439500000029801090000015710293013281999"
self.dados.append(d)

def test_linha_digitavel(self):
self.assertEqual(
self.dados[0].linha_digitavel,
'34191.09008 00015.710296 30132.810000 4 43950000002888'
)

def test_codigo_de_barras(self):
self.assertEqual(
self.dados[0].barcode,
'34194439500000029801090000015710293013281999'
)

def test_agencia(self):
self.assertEqual(self.dados[0].agencia_cedente, '0293')

def test_conta(self):
self.assertEqual(self.dados[0].conta_cedente, '01328')

def test_dv_nosso_numero(self):
self.assertEqual(self.dados[0].dv_nosso_numero, 1)

def test_dv_agencia_conta_cedente(self):
self.assertEqual(self.dados[0].dv_agencia_conta_cedente, 0)


suite = unittest.TestLoader().loadTestsFromTestCase(
TestBancoItauComDadosCalculados)

if __name__ == '__main__':
unittest.main()