diff --git a/modules/bp/browser.py b/modules/bp/browser.py index a9146fcaaf372efc3c0d2e9f94d560be0557a2dc..ce876898a4f533c655549fef8b5d4818cb4d16e9 100644 --- a/modules/bp/browser.py +++ b/modules/bp/browser.py @@ -222,6 +222,11 @@ def get_accounts_list(self): if 'CreditRenouvelable' not in account.url: for loan in self.page.iter_loans(): accounts.append(loan) + student_loan = self.page.get_student_loan() + if student_loan: + # Number of headers and item elements are the same + assert len(student_loan._heads) == len(student_loan._items) + accounts.append(student_loan) else: for loan in self.page.iter_revolving_loans(): accounts.append(loan) @@ -270,7 +275,6 @@ def get_history(self, account): if account.type in (account.TYPE_PEA, account.TYPE_MARKET): self.go_linebourse(account) - return self.linebourse.iter_history(account.id) if account.type == Account.TYPE_LOAN: diff --git a/modules/bp/pages/accountlist.py b/modules/bp/pages/accountlist.py index 2299c9965902bab326a735c13559e2a580b7c094..15218487d489249e79548c0f92792ffaf388d89a 100644 --- a/modules/bp/pages/accountlist.py +++ b/modules/bp/pages/accountlist.py @@ -174,7 +174,7 @@ def obj_url(self): @method class iter_loans(TableElement): - head_xpath = '//table[@id="pret"]/thead//th' + head_xpath = '//table[@id="pret" or @class="dataNum"]/thead//th' item_xpath = '//table[@id="pret"]/tbody/tr' col_label = u'Numéro du prêt' @@ -190,6 +190,8 @@ class item_loans(ItemElement): klass = Loan def condition(self): + if CleanText(TableCell('balance'))(self) != u'Prêt non débloqué': + return bool(not self.xpath('//caption[contains(text(), "Période de franchise du")]')) return CleanText(TableCell('balance'))(self) != u'Prêt non débloqué' def load_details(self): @@ -248,6 +250,57 @@ def obj_url(self): obj__has_cards = False + @method + class get_student_loan(ItemElement): + klass = Loan + + def condition(self): + return bool(self.xpath('//caption[contains(text(), "Période de franchise du")]')) + + # get all table headers + def obj__heads(self): + heads_xpath = '//table[@class="dataNum"]/thead//th' + return [CleanText('.')(head) for head in self.xpath(heads_xpath)] + + # get all table elements + def obj__items(self): + items_xpath = '//table[@class="dataNum"]/tbody//td' + return [CleanText('.')(item) for item in self.xpath(items_xpath)] + + def get_element(self, header_name): + for index, head in enumerate(Field('_heads')(self)): + if header_name in head: + return Field('_items')(self)[index] + assert False + + obj_id = Regexp(CleanText('//select[@id="numOffrePretSelection"]/option[@selected="selected"]'), r'(\d+)') + obj_type = Account.TYPE_LOAN + obj__has_cards = False + + def obj_total_amount(self): + return CleanDecimal(replace_dots=True).filter(self.get_element('Montant initial')) + + def obj_label(self): + return Regexp(CleanText('//h2[@class="title-level2"]'), r'([\w ]+)', flags=re.U)(self) + + def obj_balance(self): + return -CleanDecimal(replace_dots=True).filter(self.get_element('Capital restant')) + + def obj_maturity_date(self): + return Date(dayfirst=True).filter(self.get_element('Date derni')) + + def obj_duration(self): + return CleanDecimal().filter(self.get_element("de l'amortissement")) + + def obj_next_payment_date(self): + return Date(dayfirst=True).filter(self.get_element('Date de prochaine')) + + def obj_next_payment_amount(self): + return CleanDecimal(replace_dots=True).filter(self.get_element('Montant prochaine')) + + def obj_url(self): + return self.page.url + class Advisor(LoggedPage, MyHTMLPage): @method