fix: Loan write off precision issue
This commit is contained in:
parent
2ad015450e
commit
dd94587ef8
@ -142,6 +142,7 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.is_term_loan",
|
||||
"fieldname": "paid_principal_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Paid Principal Amount",
|
||||
@ -177,7 +178,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-11-06 13:22:40.197916",
|
||||
"modified": "2020-11-07 05:49:25.448875",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Loan Management",
|
||||
"name": "Loan Interest Accrual",
|
||||
|
@ -4,6 +4,12 @@
|
||||
{% include 'erpnext/loan_management/loan_common.js' %};
|
||||
|
||||
frappe.ui.form.on('Loan Write Off', {
|
||||
loan: function(frm) {
|
||||
frm.trigger('show_pending_principal_amount');
|
||||
},
|
||||
onload: function(frm) {
|
||||
frm.trigger('show_pending_principal_amount');
|
||||
},
|
||||
refresh: function(frm) {
|
||||
frm.set_query('write_off_account', function(){
|
||||
return {
|
||||
@ -14,5 +20,17 @@ frappe.ui.form.on('Loan Write Off', {
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
show_pending_principal_amount: function(frm) {
|
||||
if (frm.doc.loan && frm.doc.docstatus === 0) {
|
||||
frappe.db.get_value('Loan', frm.doc.loan, ['total_payment', 'total_interest_payable',
|
||||
'total_principal_paid', 'written_off_amount'], function(values) {
|
||||
frm.set_df_property('write_off_amount', 'description',
|
||||
"Pending principal amount is " + cstr(flt(values.total_payment - values.total_interest_payable
|
||||
- values.total_principal_paid - values.written_off_amount, 2)));
|
||||
frm.refresh_field('write_off_amount');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -5,7 +5,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe, erpnext
|
||||
from frappe import _
|
||||
from frappe.utils import getdate, flt
|
||||
from frappe.utils import getdate, flt, cint
|
||||
from erpnext.controllers.accounts_controller import AccountsController
|
||||
from erpnext.accounts.general_ledger import make_gl_entries
|
||||
|
||||
@ -19,10 +19,12 @@ class LoanWriteOff(AccountsController):
|
||||
self.cost_center = erpnext.get_default_cost_center(self.company)
|
||||
|
||||
def validate_write_off_amount(self):
|
||||
precision = cint(frappe.db.get_default("currency_precision")) or 2
|
||||
total_payment, principal_paid, interest_payable, written_off_amount = frappe.get_value("Loan", self.loan,
|
||||
['total_payment', 'total_principal_paid','total_interest_payable', 'written_off_amount'])
|
||||
|
||||
pending_principal_amount = flt(total_payment) - flt(interest_payable) - flt(principal_paid) - flt(written_off_amount)
|
||||
pending_principal_amount = flt(flt(total_payment) - flt(interest_payable) - flt(principal_paid) - flt(written_off_amount),
|
||||
precision)
|
||||
|
||||
if self.write_off_amount > pending_principal_amount:
|
||||
frappe.throw(_("Write off amount cannot be greater than pending principal amount"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user