From daf6cbaeb560b1a3a396662686828024bb51dca0 Mon Sep 17 00:00:00 2001 From: Guillaume Risbourg Date: Fri, 27 Dec 2019 14:03:10 +0100 Subject: [PATCH] [cragr] Include company name in accounts name Currently, account labels have no informations on who the accounts belongs to. For Organization connections with accounts belonging to different organization this caused multiple accounts with the same label but no way to identify which organization it belonged to. --- modules/cragr/api/browser.py | 2 -- modules/cragr/api/pages.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/cragr/api/browser.py b/modules/cragr/api/browser.py index c8a1e38c4f..3d7f475099 100644 --- a/modules/cragr/api/browser.py +++ b/modules/cragr/api/browser.py @@ -272,7 +272,6 @@ def iter_accounts(self): card._contract = contract deferred_cards[card.id] = card - main_account.owner_type = self.page.get_owner_type() main_account._contract = contract else: main_account = None @@ -281,7 +280,6 @@ def iter_accounts(self): accounts_list = list(self.page.iter_accounts()) for account in accounts_list: account._contract = contract - account.owner_type = self.page.get_owner_type() ''' Other accounts have no balance in the main JSON, so we must get all the (_id_element_contrat, balance) pairs in the account_details JSON. diff --git a/modules/cragr/api/pages.py b/modules/cragr/api/pages.py index c647597e94..61a23764d4 100644 --- a/modules/cragr/api/pages.py +++ b/modules/cragr/api/pages.py @@ -264,7 +264,19 @@ class get_main_account(ItemElement): obj_id = CleanText(Dict('comptePrincipal/numeroCompte')) obj_number = CleanText(Dict('comptePrincipal/numeroCompte')) - obj_label = CleanText(Dict('comptePrincipal/libelleProduit')) + + def obj_owner_type(self): + return self.page.get_owner_type() + + def obj_label(self): + if Field('owner_type')(self) == AccountOwnerType.PRIVATE: + # All the accounts have the same owner if it is private, + # so adding the owner in the libelle is useless. + return CleanText(Dict('comptePrincipal/libelleProduit'))(self) + return Format('%s %s', + CleanText(Dict('comptePrincipal/libelleProduit')), + CleanText(Dict('comptePrincipal/libellePartenaireBam')), + )(self) def obj_balance(self): balance = Dict('comptePrincipal/solde', default=NotAvailable)(self) @@ -333,7 +345,6 @@ def obj_id(self): return CleanText(Dict('numeroCompte'))(self) obj_number = CleanText(Dict('numeroCompte')) - obj_label = CleanText(Dict('libelleProduit')) obj_currency = CleanCurrency(Dict('idDevise')) obj__index = Dict('index') obj__category = Coalesce( @@ -344,6 +355,19 @@ def obj_id(self): obj__fam_product_code = CleanText(Dict('codeFamilleProduitBam')) obj__fam_contract_code = CleanText(Dict('codeFamilleContratBam')) + def obj_owner_type(self): + return self.page.get_owner_type() + + def obj_label(self): + if Field('owner_type')(self) == AccountOwnerType.PRIVATE: + # All the accounts have the same owner if it is private, + # so adding the owner in the libelle is useless. + return CleanText(Dict('libelleProduit'))(self) + return Format('%s %s', + CleanText(Dict('libelleProduit')), + CleanText(Dict('libellePartenaireBam')), + )(self) + def obj_type(self): if CleanText(Dict('libelleUsuelProduit'))(self) in ('HABITATION',): # No need to log warning for "assurance" accounts -- GitLab