[IMP] account_loan: Fix rounding issues
This commit is contained in:
parent
7afbbbd5ba
commit
6d29b2fad1
@ -276,7 +276,7 @@ class AccountLoan(models.Model):
|
|||||||
for record in self:
|
for record in self:
|
||||||
if record.loan_type == 'fixed-annuity':
|
if record.loan_type == 'fixed-annuity':
|
||||||
record.fixed_amount = - record.currency_id.round(numpy.pmt(
|
record.fixed_amount = - record.currency_id.round(numpy.pmt(
|
||||||
record.rate_period / 100,
|
record.loan_rate() / 100,
|
||||||
record.fixed_periods,
|
record.fixed_periods,
|
||||||
record.fixed_loan_amount,
|
record.fixed_loan_amount,
|
||||||
-record.residual_amount
|
-record.residual_amount
|
||||||
@ -307,8 +307,12 @@ class AccountLoan(models.Model):
|
|||||||
@api.depends('rate', 'method_period', 'rate_type')
|
@api.depends('rate', 'method_period', 'rate_type')
|
||||||
def _compute_rate_period(self):
|
def _compute_rate_period(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
record.rate_period = record.compute_rate(
|
record.rate_period = record.loan_rate()
|
||||||
record.rate, record.rate_type, record.method_period)
|
|
||||||
|
def loan_rate(self):
|
||||||
|
return self.compute_rate(
|
||||||
|
self.rate, self.rate_type, self.method_period
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends('journal_id', 'company_id')
|
@api.depends('journal_id', 'company_id')
|
||||||
def _compute_currency(self):
|
def _compute_currency(self):
|
||||||
|
@ -161,7 +161,7 @@ class AccountLoanLine(models.Model):
|
|||||||
return self.loan_id.fixed_amount
|
return self.loan_id.fixed_amount
|
||||||
if self.loan_type == 'fixed-annuity':
|
if self.loan_type == 'fixed-annuity':
|
||||||
return self.currency_id.round(- numpy.pmt(
|
return self.currency_id.round(- numpy.pmt(
|
||||||
self.rate / 100,
|
self.loan_id.loan_rate() / 100,
|
||||||
self.loan_id.periods - self.sequence + 1,
|
self.loan_id.periods - self.sequence + 1,
|
||||||
self.pending_principal_amount,
|
self.pending_principal_amount,
|
||||||
-self.loan_id.residual_amount
|
-self.loan_id.residual_amount
|
||||||
@ -174,13 +174,23 @@ class AccountLoanLine(models.Model):
|
|||||||
'Amount cannot be recomputed if moves or invoices exists '
|
'Amount cannot be recomputed if moves or invoices exists '
|
||||||
'already'
|
'already'
|
||||||
))
|
))
|
||||||
if not self.loan_id.round_on_end:
|
if (
|
||||||
|
self.sequence == self.loan_id.periods and
|
||||||
|
self.loan_id.round_on_end and
|
||||||
|
self.loan_type == 'fixed-annuity'
|
||||||
|
):
|
||||||
self.interests_amount = self.currency_id.round(
|
self.interests_amount = self.currency_id.round(
|
||||||
self.pending_principal_amount * self.rate / 100)
|
self.loan_id.fixed_amount - self.pending_principal_amount +
|
||||||
|
self.loan_id.residual_amount
|
||||||
|
)
|
||||||
|
self.payment_amount = self.currency_id.round(self.compute_amount())
|
||||||
|
elif not self.loan_id.round_on_end:
|
||||||
|
self.interests_amount = self.currency_id.round(
|
||||||
|
self.pending_principal_amount * self.loan_id.loan_rate() / 100)
|
||||||
self.payment_amount = self.currency_id.round(self.compute_amount())
|
self.payment_amount = self.currency_id.round(self.compute_amount())
|
||||||
else:
|
else:
|
||||||
self.interests_amount = (
|
self.interests_amount = (
|
||||||
self.pending_principal_amount * self.rate / 100)
|
self.pending_principal_amount * self.loan_id.loan_rate() / 100)
|
||||||
self.payment_amount = self.compute_amount()
|
self.payment_amount = self.compute_amount()
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
@ -92,9 +92,9 @@ class TestLoan(TransactionCase):
|
|||||||
loan.round_on_end = True
|
loan.round_on_end = True
|
||||||
loan.compute_lines()
|
loan.compute_lines()
|
||||||
line_1 = loan.line_ids.filtered(lambda r: r.sequence == 1)
|
line_1 = loan.line_ids.filtered(lambda r: r.sequence == 1)
|
||||||
line_end = loan.line_ids.filtered(lambda r: r.sequence == 60)
|
for line in loan.line_ids:
|
||||||
self.assertNotAlmostEqual(
|
self.assertAlmostEqual(
|
||||||
line_1.payment_amount, line_end.payment_amount, 2)
|
line_1.payment_amount, line.payment_amount, 2)
|
||||||
loan.loan_type = 'fixed-principal'
|
loan.loan_type = 'fixed-principal'
|
||||||
loan.compute_lines()
|
loan.compute_lines()
|
||||||
line_1 = loan.line_ids.filtered(lambda r: r.sequence == 1)
|
line_1 = loan.line_ids.filtered(lambda r: r.sequence == 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user