Commit f8afc178 authored by Sylvie Ye's avatar Sylvie Ye Committed by Romain Bignon

[cragr] fix iter recipient

* Some user can have 2 internal accounts with same iban, skip it
* Avoid iter recipient for some account types
parent a198639c
......@@ -563,6 +563,10 @@ class CragrAPI(LoginBrowser):
@need_login
def iter_transfer_recipients(self, account, transfer_space_info=None):
if account.type in (account.TYPE_CARD, account.TYPE_LOAN, account.TYPE_LIFE_INSURANCE,
account.TYPE_PEA, account.TYPE_CONSUMER_CREDIT, account.TYPE_REVOLVING_CREDIT, ):
return
# avoid to call `get_account_transfer_space_info()` several time
if transfer_space_info:
space, operation, referer = transfer_space_info
......@@ -574,12 +578,16 @@ class CragrAPI(LoginBrowser):
if not self.page.is_sender_account(account.id):
return
for index, internal_rcpt in enumerate(self.page.iter_internal_recipient(account_id=account.id)):
internal_rcpt._index = index
yield internal_rcpt
# can't use 'ignore_duplicate' in DictElement because we need the 'index' to do transfer
seen = set()
seen.add(account.iban)
for index, internal_rcpt in enumerate(self.page.iter_internal_recipient()):
internal_rcpt._index = index
if internal_rcpt._is_recipient and (internal_rcpt.iban not in seen):
seen.add(internal_rcpt.iban)
yield internal_rcpt
for index, external_rcpt in enumerate(self.page.iter_external_recipient()):
external_rcpt._index = index
if external_rcpt.iban not in seen:
......
......@@ -27,7 +27,7 @@ from weboob.capabilities.bank import (
Account, Recipient, Transfer, TransferBankError,
)
from weboob.browser.filters.standard import (
CleanDecimal, Env, Date, CleanText,
CleanDecimal, Date, CleanText,
)
from weboob.browser.filters.json import Dict
......@@ -59,10 +59,12 @@ class RecipientsPage(LoggedPage, JsonPage):
@method
class iter_internal_recipient(DictElement):
def store(self, obj):
return obj
class item(ItemElement):
def condition(self):
return Dict('recipientOfTransfert', default=None)(self) and \
Env('account_id')(self) != Dict('accountNumber', default=None)(self)
return Dict('accountNumber', default=None)(self)
klass = Recipient
......@@ -71,6 +73,7 @@ class RecipientsPage(LoggedPage, JsonPage):
obj_iban = Dict('ibanCode')
obj_category = 'Interne'
obj_enabled_at = date.today()
obj__is_recipient = Dict('recipientOfTransfert', default=False)
@method
class iter_external_recipient(DictElement):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment