sort entries by value date (taken for Transaction.date)

This commit is contained in:
Romain Bignon 2013-07-28 18:49:18 +02:00
commit efa39af957
2 changed files with 22 additions and 4 deletions

View file

@ -38,6 +38,7 @@ class BanquePopulaire(BaseBrowser):
'https://[^/]+/cyber/internet/StartTask.do\?taskInfoOID=accueilSynthese.*': AccountsPage,
'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=SOLDE.*': TransactionsPage,
'https://[^/]+/cyber/internet/Page.do\?.*': TransactionsPage,
'https://[^/]+/cyber/internet/Sort.do\?.*': TransactionsPage,
'https://[^/]+/s3f-web/indispo.*': UnavailablePage,
'https://[^/]+/portailinternet/_layouts/Ibp.Cyi.Layouts/RedirectSegment.aspx.*': RedirectPage,
'https://[^/]+/portailinternet/Catalogue/Segments/.*.aspx\?vary=(?P<vary>.*)': HomePage,
@ -103,6 +104,11 @@ class BanquePopulaire(BaseBrowser):
account = self.get_account(account.id)
self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(account._params))
# Sort by values dates (see comment in TransactionsPage.get_history)
self.select_form(predicate=lambda form: form.attrs.get('id', '') == 'myForm')
self.form.action = self.absurl('/cyber/internet/Sort.do?property=tbl1&sortBlocId=blc2&columnName=dateValeur')
self.submit()
while True:
assert self.is_on_page(TransactionsPage)

View file

@ -283,6 +283,13 @@ class TransactionsPage(BasePage):
return params
COL_COMPTA_DATE = 0
COL_LABEL = 1
COL_REF = 2
COL_OP_DATE = 3
COL_VALUE_DATE = 4
COL_DEBIT = -2
COL_CREDIT = -1
def get_history(self):
for tr in self.document.xpath('//table[@id="tbl1"]/tbody/tr'):
tds = tr.findall('td')
@ -292,10 +299,15 @@ class TransactionsPage(BasePage):
t = Transaction(tr.attrib['id'].split('_', 1)[1])
date = u''.join([txt.strip() for txt in tds[4].itertext()])
raw = u' '.join([txt.strip() for txt in tds[1].itertext()])
debit = u''.join([txt.strip() for txt in tds[-2].itertext()])
credit = u''.join([txt.strip() for txt in tds[-1].itertext()])
# XXX We currently take the *value* date, but it will probably
# necessary to use the *operation* one.
# Default sort on website is by compta date, so in browser.py we
# change the sort on value date.
date = self.parser.tocleanstring(tds[self.COL_VALUE_DATE])
raw = self.parser.tocleanstring(tds[self.COL_LABEL])
debit = self.parser.tocleanstring(tds[self.COL_DEBIT])
credit = self.parser.tocleanstring(tds[self.COL_CREDIT])
t.parse(date, re.sub(r'[ ]+', ' ', raw))
t.set_amount(credit, debit)
yield t