[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:
|
||||
if record.loan_type == 'fixed-annuity':
|
||||
record.fixed_amount = - record.currency_id.round(numpy.pmt(
|
||||
record.rate_period / 100,
|
||||
record.loan_rate() / 100,
|
||||
record.fixed_periods,
|
||||
record.fixed_loan_amount,
|
||||
-record.residual_amount
|
||||
@ -307,8 +307,12 @@ class AccountLoan(models.Model):
|
||||
@api.depends('rate', 'method_period', 'rate_type')
|
||||
def _compute_rate_period(self):
|
||||
for record in self:
|
||||
record.rate_period = record.compute_rate(
|
||||
record.rate, record.rate_type, record.method_period)
|
||||
record.rate_period = record.loan_rate()
|
||||
|
||||
def loan_rate(self):
|
||||
return self.compute_rate(
|
||||
self.rate, self.rate_type, self.method_period
|
||||
)
|
||||
|
||||
@api.depends('journal_id', 'company_id')
|
||||
def _compute_currency(self):
|
||||
|
@ -161,7 +161,7 @@ class AccountLoanLine(models.Model):
|
||||
return self.loan_id.fixed_amount
|
||||
if self.loan_type == 'fixed-annuity':
|
||||
return self.currency_id.round(- numpy.pmt(
|
||||
self.rate / 100,
|
||||
self.loan_id.loan_rate() / 100,
|
||||
self.loan_id.periods - self.sequence + 1,
|
||||
self.pending_principal_amount,
|
||||
-self.loan_id.residual_amount
|
||||
@ -174,13 +174,23 @@ class AccountLoanLine(models.Model):
|
||||
'Amount cannot be recomputed if moves or invoices exists '
|
||||
'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.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())
|
||||
else:
|
||||
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()
|
||||
|
||||
@api.multi
|
||||
|
@ -92,9 +92,9 @@ class TestLoan(TransactionCase):
|
||||
loan.round_on_end = True
|
||||
loan.compute_lines()
|
||||
line_1 = loan.line_ids.filtered(lambda r: r.sequence == 1)
|
||||
line_end = loan.line_ids.filtered(lambda r: r.sequence == 60)
|
||||
self.assertNotAlmostEqual(
|
||||
line_1.payment_amount, line_end.payment_amount, 2)
|
||||
for line in loan.line_ids:
|
||||
self.assertAlmostEqual(
|
||||
line_1.payment_amount, line.payment_amount, 2)
|
||||
loan.loan_type = 'fixed-principal'
|
||||
loan.compute_lines()
|
||||
line_1 = loan.line_ids.filtered(lambda r: r.sequence == 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user