correctly set cards' Transaction.date to the debit date
This commit is contained in:
parent
09444f5f43
commit
2a071a2ec6
1 changed files with 14 additions and 5 deletions
|
|
@ -174,13 +174,14 @@ class CardsPage(BasePage):
|
||||||
def get_history(self, date_guesser):
|
def get_history(self, date_guesser):
|
||||||
seen = set()
|
seen = set()
|
||||||
lines = self.document.xpath('(//table[@class="ca-table"])[2]/tr')
|
lines = self.document.xpath('(//table[@class="ca-table"])[2]/tr')
|
||||||
for line in lines[1:]: # first line is balance
|
debit_date = None
|
||||||
|
for i, line in enumerate(lines):
|
||||||
is_balance = line.xpath('./td/@class="cel-texte cel-neg"')
|
is_balance = line.xpath('./td/@class="cel-texte cel-neg"')
|
||||||
|
|
||||||
[date, label, _, amount] = [self.parser.tocleanstring(td)
|
[date, label, _, amount] = [self.parser.tocleanstring(td)
|
||||||
for td in line.xpath('./td')]
|
for td in line.xpath('./td')]
|
||||||
|
|
||||||
t = Transaction(0)
|
t = Transaction(i)
|
||||||
t.set_amount(amount)
|
t.set_amount(amount)
|
||||||
t.label = t.raw = label
|
t.label = t.raw = label
|
||||||
|
|
||||||
|
|
@ -189,14 +190,22 @@ class CardsPage(BasePage):
|
||||||
if not m:
|
if not m:
|
||||||
raise BrokenPageError('Unable to read card balance in history: %r' % label)
|
raise BrokenPageError('Unable to read card balance in history: %r' % label)
|
||||||
|
|
||||||
t.date = parse_french_date(m.group(1))
|
debit_date = parse_french_date(m.group(1))
|
||||||
|
|
||||||
|
# Skip the first line because it is balance
|
||||||
|
if i == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
t.date = t.rdate = debit_date
|
||||||
|
|
||||||
|
# Consider the second one as a positive amount to reset balance to 0.
|
||||||
t.amount = -t.amount
|
t.amount = -t.amount
|
||||||
else:
|
else:
|
||||||
day, month = map(int, date.split('/', 1))
|
day, month = map(int, date.split('/', 1))
|
||||||
t.date = date_guesser.guess_date(day, month)
|
t.rdate = date_guesser.guess_date(day, month)
|
||||||
|
t.date = debit_date
|
||||||
|
|
||||||
t.type = t.TYPE_CARD
|
t.type = t.TYPE_CARD
|
||||||
t.rdate = t.date
|
|
||||||
try:
|
try:
|
||||||
t.id = t.unique_id(seen)
|
t.id = t.unique_id(seen)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue