cic: correctly get the accounting amount and support coming transactions
This commit is contained in:
parent
1495017546
commit
19ffa9ab59
2 changed files with 65 additions and 7 deletions
|
|
@ -25,8 +25,8 @@ from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
|||
from weboob.capabilities.bank import Transfer, TransferError
|
||||
|
||||
from .pages import LoginPage, LoginErrorPage, AccountsPage, UserSpacePage, EmptyPage, \
|
||||
OperationsPage, CardPage, NoOperationsPage, InfoPage, TransfertPage, \
|
||||
ChangePasswordPage, VerifCodePage
|
||||
OperationsPage, CardPage, ComingPage, NoOperationsPage, InfoPage, \
|
||||
TransfertPage, ChangePasswordPage, VerifCodePage
|
||||
|
||||
|
||||
__all__ = ['CICBrowser']
|
||||
|
|
@ -44,6 +44,7 @@ class CICBrowser(BaseBrowser):
|
|||
'https://www.cic.fr/.*/fr/banque/situation_financiere.cgi': AccountsPage,
|
||||
'https://www.cic.fr/.*/fr/banque/espace_personnel.aspx': UserSpacePage,
|
||||
'https://www.cic.fr/.*/fr/banque/mouvements.cgi.*': OperationsPage,
|
||||
'https://www.cic.fr/.*/fr/banque/mvts_instance.cgi.*': ComingPage,
|
||||
'https://www.cic.fr/.*/fr/banque/nr/nr_devbooster.aspx.*': OperationsPage,
|
||||
'https://www.cic.fr/.*/fr/banque/operations_carte\.cgi.*': CardPage,
|
||||
'https://www.cic.fr/.*/fr/banque/CR/arrivee\.asp.*': NoOperationsPage,
|
||||
|
|
@ -126,6 +127,11 @@ class CICBrowser(BaseBrowser):
|
|||
elif last_debit is None:
|
||||
last_debit = (tr.date - timedelta(days=10)).month
|
||||
|
||||
coming_link = self.page.get_coming_link()
|
||||
if coming_link is not None:
|
||||
for tr in self.list_operations(coming_link):
|
||||
transactions.append(tr)
|
||||
|
||||
month = 0
|
||||
for card_link in account._card_links:
|
||||
v = urlsplit(card_link)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from urlparse import urlparse, parse_qs
|
|||
from decimal import Decimal
|
||||
import re
|
||||
|
||||
from weboob.tools.browser import BasePage, BrowserIncorrectPassword
|
||||
from weboob.tools.browser import BasePage, BrowserIncorrectPassword, BrokenPageError
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||
|
|
@ -106,6 +106,19 @@ class AccountsPage(BasePage):
|
|||
account._link_id = link
|
||||
account._card_links = []
|
||||
|
||||
# Find accounting amount
|
||||
page = self.browser.get_document(self.browser.openurl(link))
|
||||
coming = self.find_amount(page, u"Opérations à venir")
|
||||
accounting = self.find_amount(page, u"Solde comptable")
|
||||
|
||||
if account is not None and accounting + (coming or Decimal('0')) != balance:
|
||||
self.logger.warning('%s + %s != %s' % (accounting, coming, balance))
|
||||
|
||||
if accounting is not None:
|
||||
balance = accounting
|
||||
|
||||
if coming is not None:
|
||||
account.coming = coming
|
||||
account.balance = balance
|
||||
account.currency = currency
|
||||
|
||||
|
|
@ -113,6 +126,14 @@ class AccountsPage(BasePage):
|
|||
|
||||
return accounts.itervalues()
|
||||
|
||||
def find_amount(self, page, title):
|
||||
try:
|
||||
td = page.xpath(u'//th[contains(text(), "%s")]/../td' % title)[0]
|
||||
except IndexError:
|
||||
return None
|
||||
else:
|
||||
return Decimal(FrenchTransaction.clean_amount(td.text))
|
||||
|
||||
|
||||
class Transaction(FrenchTransaction):
|
||||
PATTERNS = [(re.compile('^VIR(EMENT)? (?P<text>.*)'), FrenchTransaction.TYPE_TRANSFER),
|
||||
|
|
@ -156,11 +177,14 @@ class OperationsPage(BasePage):
|
|||
if parts[0].startswith('PAIEMENT CB'):
|
||||
parts.reverse()
|
||||
|
||||
operation.parse(date=tds[0].text,
|
||||
raw=u' '.join(parts))
|
||||
date = tds[0].text
|
||||
vdate = tds[1].text if len(tds) >= 5 else None
|
||||
raw = u' '.join(parts)
|
||||
|
||||
credit = u''.join([txt.strip() for txt in tds[-1].itertext()])
|
||||
debit = u''.join([txt.strip() for txt in tds[-2].itertext()])
|
||||
operation.parse(date=date, vdate=vdate, raw=raw)
|
||||
|
||||
credit = self.parser.tocleanstring(tds[-1])
|
||||
debit = self.parser.tocleanstring(tds[-2])
|
||||
operation.set_amount(credit, debit)
|
||||
yield operation
|
||||
|
||||
|
|
@ -194,6 +218,34 @@ class OperationsPage(BasePage):
|
|||
|
||||
return True
|
||||
|
||||
def get_coming_link(self):
|
||||
try:
|
||||
a = self.parser.select(self.document, u'//a[contains(text(), "Opérations à venir")]', 1, 'xpath')
|
||||
except BrokenPageError:
|
||||
return None
|
||||
else:
|
||||
return a.attrib['href']
|
||||
|
||||
|
||||
class ComingPage(OperationsPage):
|
||||
def get_history(self):
|
||||
index = 0
|
||||
for tr in self.document.xpath('//table[@class="liste"]/tbody/tr'):
|
||||
tds = tr.findall('td')
|
||||
if len(tds) < 3:
|
||||
continue
|
||||
|
||||
tr = Transaction(index)
|
||||
|
||||
date = self.parser.tocleanstring(tds[0])
|
||||
raw = self.parser.tocleanstring(tds[1])
|
||||
amount = self.parser.tocleanstring(tds[-1])
|
||||
|
||||
tr.parse(date=date, raw=raw)
|
||||
tr.set_amount(amount)
|
||||
tr._is_coming = True
|
||||
yield tr
|
||||
|
||||
|
||||
class CardPage(OperationsPage):
|
||||
def get_history(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue