From 3556916a18a2a53f249b679b3044810e156d00b1 Mon Sep 17 00:00:00 2001 From: houssine Date: Mon, 5 Oct 2020 13:54:16 +0200 Subject: [PATCH] [FIX] convert loan term from month to year --- easy_my_coop_loan/models/loan.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/easy_my_coop_loan/models/loan.py b/easy_my_coop_loan/models/loan.py index 0e686c5..e3fd267 100644 --- a/easy_my_coop_loan/models/loan.py +++ b/easy_my_coop_loan/models/loan.py @@ -178,7 +178,8 @@ class LoanIssue(models.Model): accrued_interest = 0 accrued_net_interest = 0 accrued_taxes = 0 - for year in range(1, int(self.loan_term) + 1): + loan_term = self.loan_term / 12 + for year in range(1, int(loan_term) + 1): interest = accrued_amount * (line.loan_issue_id.rate / 100) accrued_amount += interest taxes_amount = interest * (self.taxes_rate / 100) @@ -200,6 +201,15 @@ class LoanIssue(models.Model): def compute_loan_interest(self): self.ensure_one() + if not (self.loan_term / 12).is_integer(): + # TODO Handle this case + raise NotImplementedError( + _( + "Calculation on non entire year " + "hasn't been implemented yet" + ) + ) + if self.interest_payment == "end": due_date = self.term_date else: @@ -217,12 +227,3 @@ class LoanIssue(models.Model): } self.get_interest_vals(line, vals) - rounded_term = int(self.loan_term) - if self.loan_term - rounded_term > 0: - # TODO Handle this case - raise NotImplementedError( - _( - "Calculation on non entire year " - "hasn't been implemented yet" - ) - )