diff --git a/modules/boursorama/browser.py b/modules/boursorama/browser.py index 9fee667a614d5ead9ec4f01f1fa50bbaaefd8463..a6810e9f77e5d1c463c19c5fceb4e4444203668b 100644 --- a/modules/boursorama/browser.py +++ b/modules/boursorama/browser.py @@ -40,6 +40,7 @@ TransferInvalidEmitter, TransferInvalidLabel, TransferInvalidRecipient, AddRecipientStep, Rate, TransferBankError, AccountOwnership, RecipientNotFound, AddRecipientTimeout, TransferDateType, Emitter, TransactionType, + AddRecipientBankError, ) from weboob.capabilities.base import empty, find_object from weboob.capabilities.contact import Advisor @@ -770,26 +771,46 @@ def execute_transfer(self, transfer, **kwargs): @need_login def init_new_recipient(self, recipient): - self.recipient_form = None # so it is reset when a new recipient is added + # so it is reset when a new recipient is added + self.recipient_form = None # get url + # If an account was provided for the recipient, use it + # otherwise use the first checking account available account = None for account in self.get_accounts_list(): - if account.url: + if not account.url: + continue + if recipient.origin_account_id is None: + if account.type == Account.TYPE_CHECKING: + break + elif account.id == recipient.origin_account_id: break - - suffix = 'virements/comptes-externes/nouveau' - if account.url.endswith('/'): - target = account.url + suffix else: - target = account.url + '/' + suffix + raise AddRecipientBankError(message="Compte ne permettant pas l'ajout de bénéficiaires") + + try: + self.go_recipients_list(account.url, account.id) + except AccountNotFound: + raise AddRecipientBankError(message="Compte ne permettant pas d'emettre des virements") + + assert ( + self.recipients_page.is_here() + or self.new_transfer_wizard.is_here() + ), 'Should be on recipients page' + if not self.page.is_new_recipient_allowed(): + raise AddRecipientBankError(message="Compte ne permettant pas l'ajout de bénéficiaires") + + target = '%s/virements/comptes-externes/nouveau' % account.url.rstrip('/') self.location(target) + assert self.page.is_characteristics(), 'Not on the page to add recipients.' # fill recipient form self.page.submit_recipient(recipient) - recipient.origin_account_id = account.id + if recipient.origin_account_id is None: + recipient.origin_account_id = account.id # confirm sending sms assert self.page.is_confirm_send_sms(), 'Cannot reach the page asking to send a sms.' @@ -804,7 +825,8 @@ def init_new_recipient(self, recipient): self.recipient_form['account_url'] = account.url raise AddRecipientStep(recipient, Value('otp_sms', label='Veuillez saisir le code recu par sms')) - # if the add recipient is restarted after the sms has been confirmed recently, the sms step is not presented again + # if the add recipient is restarted after the sms has been confirmed recently, + # the sms step is not presented again return self.rcpt_after_sms(recipient, account.url) def new_recipient(self, recipient, **kwargs): @@ -814,8 +836,9 @@ def new_recipient(self, recipient, **kwargs): # validating the sms code directly adds the recipient account_url = self.send_recipient_form(kwargs['otp_sms']) return self.rcpt_after_sms(recipient, account_url) + # step 3 of new_recipient (not always used) - elif 'otp_email' in kwargs: + if 'otp_email' in kwargs: account_url = self.send_recipient_form(kwargs['otp_email']) return self.check_and_update_recipient(recipient, account_url) diff --git a/modules/boursorama/pages.py b/modules/boursorama/pages.py index 6dcf5499d81080a8afea1c4f1eec7faca9741760..3fe9dfe85e974a32c9cf7296d26af6624fb76e5c 100644 --- a/modules/boursorama/pages.py +++ b/modules/boursorama/pages.py @@ -40,7 +40,7 @@ MapIn, Lower, Base, ) from weboob.browser.filters.json import Dict -from weboob.browser.filters.html import Attr, Link, TableCell +from weboob.browser.filters.html import Attr, HasElement, Link, TableCell from weboob.capabilities.bank import ( Account as BaseAccount, Recipient, Transfer, TransferDateType, AccountNotFound, AddRecipientBankError, TransferInvalidAmount, Loan, AccountOwnership, @@ -1292,6 +1292,9 @@ def submit_recipient(self, tempid): form['CreditAccount[creditAccountKey]'] = tempid form.submit() + def is_new_recipient_allowed(self): + return True + class NewTransferWizard(LoggedPage, HTMLPage): def get_errors(self): @@ -1385,6 +1388,13 @@ def submit_recipient(self, tempid): form.submit() + def is_new_recipient_allowed(self): + try: + self.get_form(name='CreditAccount') + except FormNotFound: + return False + return HasElement('//input[@id="CreditAccount_newBeneficiary"]')(self.doc) + # STEP 3 - # If using existing recipient: select the amount # If new beneficiary: select if new recipient is own account or third party one