Skip to content

Commit

Permalink
FIX #11 - Agora o ano é definido conforme a data de vencimento da fat…
Browse files Browse the repository at this point in the history
…ura.

Também traduzi todos os comentários evitando a macarronada portinglês e facilitando a vida de outros brasileiros que queiram contribuir. No caso ficou, código em inglês documentação em português.
  • Loading branch information
josecoelho committed Nov 25, 2014
1 parent b0a541e commit 4d59eda
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 76 deletions.
9 changes: 5 additions & 4 deletions bbvisa2ofx/bbvisa2ofx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

def convert ( fileTxt, fileOfx, closeOfxFile=True):
"""
fileTxt: python loaded file of txt to be convertedCaminho para o arquivo txt disponibilizado pelo banco do brasil
fileOfx: python loaded file with path to ofx that will be generated
closeOfxFile: if false do not close fileOfx on the end of convertion (workaroud to use an StringIO class instead of default file class)
fileTxt: python file para o arquivo txt disponibilizado pelo banco do brasil
fileOfx: python file com o caminho para o ofx que sera gerado
closeOfxFile: se false nao fecha fileOfx (workaroud a classe para usar StringIO ao inves da classe file do python)
Em um arquivo OFX temos um banco, que possui contas (neste caso apenas uma) que por sua vez possuem transacoes.
Os itens retornados pelo parser do txt, representam transacoes de uma conta
Expand Down Expand Up @@ -104,6 +105,6 @@ def convert ( fileTxt, fileOfx, closeOfxFile=True):

if(closeOfxFile):
out.close()
print "Success converted"
print "Convertido com sucesso!"


64 changes: 32 additions & 32 deletions bbvisa2ofx/test/exemploFaturaCartao.txt.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NEWFILEUID:NON
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<DTSERVER>20140901</DTSERVER>
<DTSERVER>20141125</DTSERVER>
<LANGUAGE>POR</LANGUAGE>
<FI>
<ORG>Banco do Brasil</ORG>
Expand All @@ -38,111 +38,111 @@ NEWFILEUID:NON
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>20140901</DTSTART>
<DTEND>20140901</DTEND>
<DTSTART>20141125</DTSTART>
<DTEND>20141125</DTEND>

<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000811</DTPOSTED>
<DTPOSTED>20140811</DTPOSTED>
<TRNAMT>1000.0</TRNAMT>
<FITID>190008111000.0PGTODEBITOCONTA3333000006037200</FITID>
<FITID>201408111000.0PGTODEBITOCONTA3333000006037200</FITID>
<MEMO>PGTO DEBITO CONTA 3333 000006037 200 </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000725</DTPOSTED>
<DTPOSTED>20140725</DTPOSTED>
<TRNAMT>-46.86</TRNAMT>
<FITID>19000725-46.86AtlassianSydney</FITID>
<FITID>20140725-46.86AtlassianSydney</FITID>
<MEMO>Atlassian Sydney </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000728</DTPOSTED>
<DTPOSTED>20140728</DTPOSTED>
<TRNAMT>-2.99904</TRNAMT>
<FITID>19000728-2.99904IOF-COMPRANOEXTERIOR</FITID>
<FITID>20140728-2.99904IOF-COMPRANOEXTERIOR</FITID>
<MEMO>IOF - COMPRA NO EXTERIOR </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000728</DTPOSTED>
<DTPOSTED>20140728</DTPOSTED>
<TRNAMT>-57.85</TRNAMT>
<FITID>19000728-57.85PAYPALCACHORROQUENTE4029357733</FITID>
<FITID>20140728-57.85PAYPALCACHORROQUENTE4029357733</FITID>
<MEMO>PAYPAL CACHORRO QUENTE 4029357733 </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000729</DTPOSTED>
<DTPOSTED>20140729</DTPOSTED>
<TRNAMT>-3.69</TRNAMT>
<FITID>19000729-3.69IOF-COMPRANOEXTERIOR</FITID>
<FITID>20140729-3.69IOF-COMPRANOEXTERIOR</FITID>
<MEMO>IOF - COMPRA NO EXTERIOR </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000730</DTPOSTED>
<DTPOSTED>20140730</DTPOSTED>
<TRNAMT>-16.9</TRNAMT>
<FITID>19000730-16.9NETFLIX.COMSAOPAULO</FITID>
<FITID>20140730-16.9NETFLIX.COMSAOPAULO</FITID>
<MEMO>NETFLIX.COM SAO PAULO </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000730</DTPOSTED>
<DTPOSTED>20140730</DTPOSTED>
<TRNAMT>-65.0</TRNAMT>
<FITID>19000730-65.0AGROPECUARIAVERDESCA</FITID>
<FITID>20140730-65.0AGROPECUARIAVERDESCA</FITID>
<MEMO>AGROPECUARIA VERDES CA </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000807</DTPOSTED>
<DTPOSTED>20140807</DTPOSTED>
<TRNAMT>-29.9</TRNAMT>
<FITID>19000807-29.9CONTAAZULJOINVILLE</FITID>
<FITID>20140807-29.9CONTAAZULJOINVILLE</FITID>
<MEMO>CONTA AZUL JOINVILLE </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000626</DTPOSTED>
<DTPOSTED>20140626</DTPOSTED>
<TRNAMT>-352.0</TRNAMT>
<FITID>19000626-352.0LLLLLLLLLLLLPARC02/03FLORIANOPOLI</FITID>
<FITID>20140626-352.0LLLLLLLLLLLLPARC02/03FLORIANOPOLI</FITID>
<MEMO>LLLLLLLLLLLL PARC 02/03 FLORIANOPOLI </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19001004</DTPOSTED>
<DTPOSTED>20131004</DTPOSTED>
<TRNAMT>-141.58</TRNAMT>
<FITID>19001004-141.58ASDASDASDASDAPARC11/12FARROUPILHA</FITID>
<FITID>20131004-141.58ASDASDASDASDAPARC11/12FARROUPILHA</FITID>
<MEMO>ASDASDASDASDA PARC 11/12 FARROUPILHA </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000719</DTPOSTED>
<DTPOSTED>20140719</DTPOSTED>
<TRNAMT>-163.9</TRNAMT>
<FITID>19000719-163.9GOLTRANSPPARC02/02SAOPAULO</FITID>
<FITID>20140719-163.9GOLTRANSPPARC02/02SAOPAULO</FITID>
<MEMO>GOL TRAN SP PARC 02/02 SAO PAULO </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000826</DTPOSTED>
<DTPOSTED>20140826</DTPOSTED>
<TRNAMT>-3.0</TRNAMT>
<FITID>19000826-3.0PROTECAOOUROSET/2014</FITID>
<FITID>20140826-3.0PROTECAOOUROSET/2014</FITID>
<MEMO>PROTECAO OURO SET/2014 </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000815</DTPOSTED>
<DTPOSTED>20140815</DTPOSTED>
<TRNAMT>-3.95</TRNAMT>
<FITID>19000815-3.95AJUSTEADEBITOVAR.CAMBIALCOMPRAEX</FITID>
<FITID>20140815-3.95AJUSTEADEBITOVAR.CAMBIALCOMPRAEX</FITID>
<MEMO>AJUSTE A DEBITO VAR.CAMBIAL COMPRA EX </MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>19000826</DTPOSTED>
<DTPOSTED>20140826</DTPOSTED>
<TRNAMT>-15.0</TRNAMT>
<FITID>19000826-15.0ANUIDADEDIFERENCIADATIT-PARC03/06</FITID>
<FITID>20140826-15.0ANUIDADEDIFERENCIADATIT-PARC03/06</FITID>
<MEMO>ANUIDADE DIFERENCIADA TIT-PARC 03/06 </MEMO>
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>0</BALAMT>
<DTASOF>20140901</DTASOF>
<DTASOF>20141125</DTASOF>
</LEDGERBAL>
</STMTRS>
</STMTTRNRS>
Expand Down
36 changes: 33 additions & 3 deletions bbvisa2ofx/test/txtparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unittest
from bbvisa2ofx.txtparser import TxtParser
from bbvisa2ofx.bbvisa2ofx import convert
import os
import os, datetime

class Test(unittest.TestCase):
file_path = os.path.dirname(os.path.abspath(__file__))+"/exemploFaturaCartao.txt";
Expand All @@ -18,12 +18,42 @@ def setUp(self):
self.parser = TxtParser(fTxt);

def testParseTransactionLine(self):
self.parser.dueDate = datetime.datetime(2011,12,25)
parsedLine = self.parser.parseTransactionLine('11/08 PGTO DEBITO CONTA 3333 000006037 200 211 -1.000,00 0,00')
self.assertEquals(parsedLine['date'],'19000811')
self.assertEquals(parsedLine['fitid'],'190008111000.0PGTODEBITOCONTA3333000006037200')
self.assertEquals(parsedLine['date'],'20110811')
self.assertEquals(parsedLine['fitid'],'201108111000.0PGTODEBITOCONTA3333000006037200')
self.assertEquals(parsedLine['value'],1000.00)
self.assertEquals(parsedLine['desc'],'PGTO DEBITO CONTA 3333 000006037 200 ')

def testParseValueFromTransactionLine(self):
line = '30/07 NETFLIX.COM SAO PAULO BR 16,90 0,00'
value = self.parser.parseValueFromTransactionLine(line)

self.assertEquals(value, -16.90)

def testParseValueFromTransactionLine_ConvertingDollarToReal(self):
line = '25/07 Atlassian Sydney AU 0,00 20,00'
self.parser.exchangeRate = 2 #force exchangeRate
value = self.parser.parseValueFromTransactionLine(line)

self.assertEquals(value, -40.00)

def testParseDateFromTransactionLine_fromSameYear(self):
line = '25/02 Atlassian Sydney AU 0,00 20,00'
self.parser.dueDate = datetime.datetime(2011,07,25)

date = self.parser.parseDateFromTransactionLine(line)
self.assertEquals(date,'20110225')

def testParseDateFromTransactionLine_guessingYearBefore(self):
'''
mesmo mes do vencimento, sugerindo ano anterior
'''
line = '25/07 Atlassian Sydney AU 0,00 20,00'
self.parser.dueDate = datetime.datetime(2011,07,25)

date = self.parser.parseDateFromTransactionLine(line)
self.assertEquals(date,'20100725')

def testParse(self):
self.parser.parse()
Expand Down
Loading

0 comments on commit 4d59eda

Please sign in to comment.