remove lot of fucking shit and keep card transactions in separate card accounts
This commit is contained in:
parent
9e61376aa6
commit
78f6127f9e
3 changed files with 14 additions and 73 deletions
|
|
@ -98,8 +98,8 @@ class BredBrowser(Browser):
|
|||
|
||||
return None
|
||||
|
||||
def iter_transactions(self, id, is_coming=None):
|
||||
numero_compte, numero_poste = id.split('.')
|
||||
def get_history(self, account):
|
||||
numero_compte, numero_poste = account.id.split('.')
|
||||
data = {'typeDemande': 'recherche',
|
||||
'motRecherche': '',
|
||||
'numero_compte': numero_compte,
|
||||
|
|
@ -113,16 +113,4 @@ class BredBrowser(Browser):
|
|||
self.location('https://www.%s.fr/Andromede/Ecriture' % self.website, urllib.urlencode(data))
|
||||
|
||||
assert self.is_on_page(TransactionsPage)
|
||||
return self.page.get_history(is_coming)
|
||||
|
||||
def get_history(self, account):
|
||||
for tr in self.iter_transactions(account.id):
|
||||
yield tr
|
||||
|
||||
for tr in self.get_card_operations(account):
|
||||
yield tr
|
||||
|
||||
def get_card_operations(self, account):
|
||||
for id in account._card_links:
|
||||
for tr in self.iter_transactions(id, True):
|
||||
yield tr
|
||||
return self.page.get_history()
|
||||
|
|
|
|||
|
|
@ -66,12 +66,4 @@ class BredModule(Module, CapBank):
|
|||
|
||||
def iter_history(self, account):
|
||||
with self.browser:
|
||||
transactions = list(self.browser.get_history(account))
|
||||
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
||||
return [tr for tr in transactions if not tr._is_coming]
|
||||
|
||||
def iter_coming(self, account):
|
||||
with self.browser:
|
||||
transactions = list(self.browser.get_card_operations(account))
|
||||
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
||||
return [tr for tr in transactions if tr._is_coming]
|
||||
return self.browser.get_history(account)
|
||||
|
|
|
|||
|
|
@ -135,8 +135,6 @@ class BredBasePage(Page):
|
|||
|
||||
class AccountsPage(BredBasePage):
|
||||
def get_list(self):
|
||||
accounts = []
|
||||
|
||||
for tr in self.document.xpath('//table[@class="compteTable"]/tr'):
|
||||
if not tr.attrib.get('class', '').startswith('ligne_'):
|
||||
continue
|
||||
|
|
@ -153,21 +151,19 @@ class AccountsPage(BredBasePage):
|
|||
|
||||
a = cols[0].find('a')
|
||||
if a is None:
|
||||
# this line is a cards line. attach it on the first account.
|
||||
if len(accounts) == 0:
|
||||
self.logger.warning('There is a card link but no accounts!')
|
||||
continue
|
||||
|
||||
for a in cols[0].xpath('.//li/a'):
|
||||
args = self.js2args(a.attrib['href'])
|
||||
if not 'numero_compte' in args or not 'numero_poste' in args:
|
||||
self.logger.warning('Card link with strange args: %s' % args)
|
||||
continue
|
||||
|
||||
accounts[0]._card_links.append('%s.%s' % (args['numero_compte'], args['numero_poste']))
|
||||
if not accounts[0].coming:
|
||||
accounts[0].coming = Decimal('0.0')
|
||||
accounts[0].coming += amount
|
||||
account = Account()
|
||||
account.id = '%s.%s' % (args['numero_compte'], args['numero_poste'])
|
||||
account.label = u'Carte %s' % self.parser.tocleanstring(a)
|
||||
account.balance = amount
|
||||
account.type = account.TYPE_CARD
|
||||
account.currency = [account.get_currency(txt) for txt in cols[-1].itertext() if len(txt.strip()) > 0][0]
|
||||
yield account
|
||||
continue
|
||||
|
||||
args = self.js2args(a.attrib['href'])
|
||||
|
|
@ -181,10 +177,7 @@ class AccountsPage(BredBasePage):
|
|||
account.label = to_unicode(a.attrib.get('alt', a.text.strip()))
|
||||
account.balance = amount
|
||||
account.currency = [account.get_currency(txt) for txt in cols[-1].itertext() if len(txt.strip()) > 0][0]
|
||||
account._card_links = []
|
||||
accounts.append(account)
|
||||
|
||||
return accounts
|
||||
yield account
|
||||
|
||||
|
||||
class Transaction(FrenchTransaction):
|
||||
|
|
@ -208,14 +201,7 @@ class Transaction(FrenchTransaction):
|
|||
|
||||
|
||||
class TransactionsPage(Page):
|
||||
def get_history(self, is_coming=None):
|
||||
last_debit = None
|
||||
transactions = []
|
||||
|
||||
# check if it's a card page, so by default transactions are not yet debited.
|
||||
if len(self.document.xpath('//div[@class="scrollTbody"]/table//th')) == 6 and is_coming is None:
|
||||
is_coming = True
|
||||
|
||||
def get_history(self):
|
||||
for tr in self.document.xpath('//div[@class="scrollTbody"]/table//tr'):
|
||||
cols = tr.findall('td')
|
||||
|
||||
|
|
@ -229,12 +215,6 @@ class TransactionsPage(Page):
|
|||
date = self.parser.tocleanstring(cols[0])
|
||||
label = self.parser.tocleanstring(col_label)
|
||||
|
||||
# always strip card debits transactions. if we are on a card page, all next
|
||||
# transactions will be probably already debited.
|
||||
if label.startswith('DEBIT MENSUEL '):
|
||||
is_coming = False
|
||||
continue
|
||||
|
||||
t = Transaction(col_label.attrib.get('id', ''))
|
||||
|
||||
# an optional tooltip on page contain the second part of the transaction label.
|
||||
|
|
@ -256,23 +236,4 @@ class TransactionsPage(Page):
|
|||
credit = self.parser.tocleanstring(cols[-1])
|
||||
t.set_amount(credit, debit)
|
||||
|
||||
if 'CUMUL DES DEPENSES CARTES BANCAIRES REGLEES' in t.raw:
|
||||
if last_debit is None:
|
||||
last_debit = t.date
|
||||
continue
|
||||
|
||||
t._is_coming = bool(is_coming)
|
||||
|
||||
# If this is a card, get the right debit date (rdate is already set
|
||||
# with the operation date with t.parse())
|
||||
if is_coming is not None:
|
||||
t.date = t.parse_date(self.parser.tocleanstring(cols[-3]))
|
||||
|
||||
transactions.append(t)
|
||||
|
||||
if last_debit is not None and is_coming is True:
|
||||
for tr in transactions:
|
||||
if tr.date <= last_debit.replace(day=1):
|
||||
tr._is_coming = False
|
||||
|
||||
return iter(transactions)
|
||||
yield t
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue