Commit 62231324 authored by Frédéric Lépy's avatar Frédéric Lépy Committed by Romain Bignon
Browse files

[cmb] Added conditions when scraping json

Json keys may differ depending on the loan type, so I have added conditions to better handle all cases
Closes: 434889@redmine
parent 731e8c87
......@@ -203,19 +203,39 @@ def obj_id(self):
obj_label = Dict('libelle')
obj_currency = u'EUR'
obj_type = Account.TYPE_LOAN
obj_total_amount = Dict('montantEmprunte')
obj_next_payment_amount = Dict('montantProchaineEcheance')
def obj_total_amount(self):
# Json key change depending on loan type, consumer credit or revolving credit
if 'montantEmprunte' in self.page.text:
return Dict('montantEmprunte')(self)
else:
return Dict('montantUtilise')(self)
# Key not always available, when revolving credit not yet consummed
obj_next_payment_amount = Dict('montantProchaineEcheance', default=NotAvailable)
# obj_rate = can't find the info on website except pdf :(
# Dates scrapped are timestamp, to remove last '000' we divide by 1000
# Dates scraped are timestamp, to remove last '000' we divide by 1000
def obj_maturity_date(self):
return dt.date.fromtimestamp(Dict('dateFin')(self)/1000)
# Key not always available, when revolving credit not yet consummed
if 'dateFin' in self.page.text:
return dt.date.fromtimestamp(Dict('dateFin')(self)/1000)
else:
return NotAvailable
def obj_next_payment_date(self):
return dt.date.fromtimestamp(Dict('dateProchaineEcheance')(self)/1000)
# Key not always available, when revolving credit not yet consummed
if 'dateProchaineEcheance' in self.page.text:
return dt.date.fromtimestamp(Dict('dateProchaineEcheance')(self)/1000)
else:
return NotAvailable
def obj_balance(self):
return -abs(CleanDecimal().filter(Dict('montantRestant', default=None)(self) or Dict('montantDisponible')(self)))
return -abs(CleanDecimal().filter(Dict('montantRestant', default=None)(self) or Dict('montantUtilise')(self)))
# only for revolving loans
obj_available_amount = CleanDecimal(Dict('montantDisponible', default=NotAvailable))
class Transaction(FrenchTransaction):
......@@ -262,7 +282,7 @@ class item(ItemElement):
class FromTimestamp(Filter):
def filter(self, timestamp):
return dt.fromtimestamp(int(timestamp[:-3])).date()
return dt.date.fromtimestamp(int(timestamp[:-3]))
obj_date = FromTimestamp(Dict('dateOperation'))
obj_raw = Transaction.Raw(Dict('libelleCourt'))
......
......@@ -248,8 +248,8 @@ class Loan(Account):
insurance_label = StringField('Label of the insurance')
total_amount = DecimalField('Total amount loaned')
available_amount = DecimalField('Amount available')
used_amount = DecimalField('Amount already used')
available_amount = DecimalField('Amount available') # only makes sense for revolving credit
used_amount = DecimalField('Amount already used') # only makes sense for revolving credit
subscription_date = DateField('Date of subscription of the loan')
maturity_date = DateField('Estimated end date of the loan')
......
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