[creditmut] internal transfer implemented

This commit is contained in:
Julien Veyssier 2012-02-04 16:56:35 +01:00
commit 9305df412d
3 changed files with 80 additions and 4 deletions

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.bank import ICapBank, AccountNotFound
from weboob.capabilities.bank import ICapBank, AccountNotFound, Recipient, Account
from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.tools.value import ValueBackendPassword
@ -62,3 +62,25 @@ class CreditMutuelBackend(BaseBackend, ICapBank):
def iter_history(self, account):
for history in self.browser.get_history(account):
yield history
def iter_transfer_recipients(self, ignored):
for account in self.browser.get_accounts_list().itervalues():
recipient = Recipient()
recipient.id = account.id
recipient.label = account.label
yield recipient
def transfer(self, account, to, amount, reason=None):
if isinstance(account, Account):
account = account.id
try:
assert account.isdigit()
assert to.isdigit()
amount = float(amount)
except (AssertionError, ValueError):
raise AccountNotFound()
with self.browser:
return self.browser.transfer(account, to, amount, reason)

View file

@ -19,8 +19,10 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from weboob.capabilities.bank import Transfer, TransferError
from datetime import datetime
from .pages import LoginPage, LoginErrorPage, AccountsPage, UserSpacePage, OperationsPage, InfoPage
from .pages import LoginPage, LoginErrorPage, AccountsPage, UserSpacePage, OperationsPage, InfoPage, TransfertPage
__all__ = ['CreditMutuelBrowser']
@ -35,7 +37,8 @@ class CreditMutuelBrowser(BaseBrowser):
'https://www.creditmutuel.fr/.*/fr/banque/situation_financiere.cgi': AccountsPage,
'https://www.creditmutuel.fr/.*/fr/banque/espace_personnel.aspx': UserSpacePage,
'https://www.creditmutuel.fr/.*/fr/banque/mouvements.cgi.*' : OperationsPage,
'https://www.creditmutuel.fr/.*/fr/banque/BAD.*' : InfoPage
'https://www.creditmutuel.fr/.*/fr/banque/BAD.*' : InfoPage,
'https://www.creditmutuel.fr/.*/fr/banque/.*Vir.*' : TransfertPage
}
def __init__(self, *args, **kwargs):
@ -49,7 +52,6 @@ class CreditMutuelBrowser(BaseBrowser):
def home(self):
return self.location('https://www.creditmutuel.fr/groupe/fr/index.html')
def login(self):
assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring)
@ -111,6 +113,55 @@ class CreditMutuelBrowser(BaseBrowser):
return l_ret
def transfer(self, account, to, amount, reason=None):
# access the transfer page
transfert_url = 'WI_VPLV_VirUniSaiCpt.asp?RAZ=ALL&Cat=6&PERM=N&CHX=A'
self.location('https://%s/%s/fr/banque/%s'%(self.DOMAIN, self.currentSubBank, transfert_url))
# fill the form
self.select_form(name='FormVirUniSaiCpt')
self['IDB'] = [account[-1]]
self['ICR'] = [to[-1]]
self['MTTVIR'] = '%s' % str(amount).replace('.',',')
if reason != None:
self['LIBDBT'] = reason
self['LIBCRT'] = reason
self.submit()
# look for known errors
content = unicode(self.response().get_data(), self.ENCODING)
insufficient_amount_message = u'Montant insuffisant.'
maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'
if content.find(insufficient_amount_message) != -1:
raise TransferError('The amount you tried to transfer is too low.')
if content.find(maximum_allowed_balance_message) != -1:
raise TransferError('The maximum allowed balance for the target account has been / would be reached.')
# look for the known "all right" message
ready_for_transfer_message = u'Confirmez un virement entre vos comptes'
if not content.find(ready_for_transfer_message):
raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)
# submit the confirmation form
self.select_form(name='FormVirUniCnf')
submit_date = datetime.now()
self.submit()
# look for the known "everything went well" message
content = unicode(self.response().get_data(), self.ENCODING)
transfer_ok_message = u'Votre virement a été exécuté ce jour'
if not content.find(transfer_ok_message):
raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)
# We now have to return a Transfer object
transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
transfer.amount = amount
transfer.origin = account
transfer.recipient = to
transfer.date = submit_date
return transfer
#def get_coming_operations(self, account):
# if not self.is_on_page(AccountComing) or self.page.account.id != account.id:

View file

@ -35,6 +35,9 @@ class LoginErrorPage(BasePage):
class InfoPage(BasePage):
pass
class TransfertPage(BasePage):
pass
class UserSpacePage(BasePage):
pass