mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-09 16:21:19 +00:00
Journal voucher debit != credit #fraction issue
This commit is contained in:
@@ -140,13 +140,13 @@ cur_frm.cscript.update_totals = function(doc) {
|
|||||||
var td=0.0; var tc =0.0;
|
var td=0.0; var tc =0.0;
|
||||||
var el = doc.entries || [];
|
var el = doc.entries || [];
|
||||||
for(var i in el) {
|
for(var i in el) {
|
||||||
td += flt(el[i].debit, 2);
|
td += flt(el[i].debit, precision("debit", el[i]));
|
||||||
tc += flt(el[i].credit, 2);
|
tc += flt(el[i].credit, precision("credit", el[i]));
|
||||||
}
|
}
|
||||||
var doc = locals[doc.doctype][doc.name];
|
var doc = locals[doc.doctype][doc.name];
|
||||||
doc.total_debit = td;
|
doc.total_debit = td;
|
||||||
doc.total_credit = tc;
|
doc.total_credit = tc;
|
||||||
doc.difference = flt((td - tc), 2);
|
doc.difference = flt((td - tc), precision("difference"));
|
||||||
refresh_many(['total_debit','total_credit','difference']);
|
refresh_many(['total_debit','total_credit','difference']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,18 +120,21 @@ class JournalVoucher(AccountsController):
|
|||||||
if flt(d.credit > 0): d.against_account = ", ".join(list(set(accounts_debited)))
|
if flt(d.credit > 0): d.against_account = ", ".join(list(set(accounts_debited)))
|
||||||
|
|
||||||
def validate_debit_and_credit(self):
|
def validate_debit_and_credit(self):
|
||||||
self.total_debit, self.total_credit = 0, 0
|
self.total_debit, self.total_credit, self.difference = 0, 0, 0
|
||||||
|
|
||||||
for d in self.get("entries"):
|
for d in self.get("entries"):
|
||||||
if d.debit and d.credit:
|
if d.debit and d.credit:
|
||||||
frappe.throw(_("You cannot credit and debit same account at the same time"))
|
frappe.throw(_("You cannot credit and debit same account at the same time"))
|
||||||
|
|
||||||
self.total_debit = flt(self.total_debit) + flt(d.debit)
|
self.total_debit = flt(self.total_debit) + flt(d.debit, self.precision("debit", "entries"))
|
||||||
self.total_credit = flt(self.total_credit) + flt(d.credit)
|
self.total_credit = flt(self.total_credit) + flt(d.credit, self.precision("credit", "entries"))
|
||||||
|
|
||||||
if abs(self.total_debit-self.total_credit) > 0.001:
|
self.difference = flt(self.total_debit, self.precision("total_debit")) - \
|
||||||
|
flt(self.total_credit, self.precision("total_credit"))
|
||||||
|
|
||||||
|
if self.difference:
|
||||||
frappe.throw(_("Total Debit must be equal to Total Credit. The difference is {0}")
|
frappe.throw(_("Total Debit must be equal to Total Credit. The difference is {0}")
|
||||||
.format(self.total_debit - self.total_credit))
|
.format(self.difference))
|
||||||
|
|
||||||
def create_remarks(self):
|
def create_remarks(self):
|
||||||
r = []
|
r = []
|
||||||
@@ -254,8 +257,8 @@ class JournalVoucher(AccountsController):
|
|||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": d.account,
|
"account": d.account,
|
||||||
"against": d.against_account,
|
"against": d.against_account,
|
||||||
"debit": d.debit,
|
"debit": flt(d.debit, self.precision("debit", "entries")),
|
||||||
"credit": d.credit,
|
"credit": flt(d.credit, self.precision("credit", "entries")),
|
||||||
"against_voucher_type": ((d.against_voucher and "Purchase Invoice")
|
"against_voucher_type": ((d.against_voucher and "Purchase Invoice")
|
||||||
or (d.against_invoice and "Sales Invoice")
|
or (d.against_invoice and "Sales Invoice")
|
||||||
or (d.against_jv and "Journal Voucher")),
|
or (d.against_jv and "Journal Voucher")),
|
||||||
@@ -279,7 +282,7 @@ class JournalVoucher(AccountsController):
|
|||||||
msgprint(_("'Entries' cannot be empty"), raise_exception=True)
|
msgprint(_("'Entries' cannot be empty"), raise_exception=True)
|
||||||
else:
|
else:
|
||||||
flag, self.total_debit, self.total_credit = 0, 0, 0
|
flag, self.total_debit, self.total_credit = 0, 0, 0
|
||||||
diff = flt(self.difference, 2)
|
diff = flt(self.difference, self.precision("difference"))
|
||||||
|
|
||||||
# If any row without amount, set the diff on that row
|
# If any row without amount, set the diff on that row
|
||||||
for d in self.get('entries'):
|
for d in self.get('entries'):
|
||||||
@@ -298,45 +301,44 @@ class JournalVoucher(AccountsController):
|
|||||||
elif diff<0:
|
elif diff<0:
|
||||||
jd.debit = abs(diff)
|
jd.debit = abs(diff)
|
||||||
|
|
||||||
# Set the total debit, total credit and difference
|
self.validate_debit_and_credit()
|
||||||
for d in self.get('entries'):
|
|
||||||
self.total_debit += flt(d.debit, 2)
|
|
||||||
self.total_credit += flt(d.credit, 2)
|
|
||||||
|
|
||||||
self.difference = flt(self.total_debit, 2) - flt(self.total_credit, 2)
|
|
||||||
|
|
||||||
def get_outstanding_invoices(self):
|
def get_outstanding_invoices(self):
|
||||||
self.set('entries', [])
|
self.set('entries', [])
|
||||||
total = 0
|
total = 0
|
||||||
for d in self.get_values():
|
for d in self.get_values():
|
||||||
total += flt(d[2])
|
total += flt(d.outstanding_amount, self.precision("credit", "entries"))
|
||||||
jd = self.append('entries', {})
|
jd1 = self.append('entries', {})
|
||||||
jd.account = cstr(d[1])
|
jd1.account = d.account
|
||||||
|
|
||||||
if self.write_off_based_on == 'Accounts Receivable':
|
if self.write_off_based_on == 'Accounts Receivable':
|
||||||
jd.credit = flt(d[2])
|
jd1.credit = flt(d.outstanding_amount, self.precision("credit", "entries"))
|
||||||
jd.against_invoice = cstr(d[0])
|
jd1.against_invoice = cstr(d.name)
|
||||||
elif self.write_off_based_on == 'Accounts Payable':
|
elif self.write_off_based_on == 'Accounts Payable':
|
||||||
jd.debit = flt(d[2])
|
jd1.debit = flt(d.outstanding_amount, self.precision("debit", "entries"))
|
||||||
jd.against_voucher = cstr(d[0])
|
jd1.against_voucher = cstr(d.name)
|
||||||
jd.save(1)
|
|
||||||
jd = self.append('entries', {})
|
jd2 = self.append('entries', {})
|
||||||
if self.write_off_based_on == 'Accounts Receivable':
|
if self.write_off_based_on == 'Accounts Receivable':
|
||||||
jd.debit = total
|
jd2.debit = total
|
||||||
elif self.write_off_based_on == 'Accounts Payable':
|
elif self.write_off_based_on == 'Accounts Payable':
|
||||||
jd.credit = total
|
jd2.credit = total
|
||||||
jd.save(1)
|
|
||||||
|
self.validate_debit_and_credit()
|
||||||
|
|
||||||
|
|
||||||
def get_values(self):
|
def get_values(self):
|
||||||
cond = (flt(self.write_off_amount) > 0) and \
|
cond = " and outstanding_amount <= {0}".format(self.write_off_amount) \
|
||||||
' and outstanding_amount <= '+ self.write_off_amount or ''
|
if flt(self.write_off_amount) > 0 else ""
|
||||||
|
|
||||||
if self.write_off_based_on == 'Accounts Receivable':
|
if self.write_off_based_on == 'Accounts Receivable':
|
||||||
return frappe.db.sql("""select name, debit_to, outstanding_amount
|
return frappe.db.sql("""select name, debit_to as account, outstanding_amount
|
||||||
from `tabSales Invoice` where docstatus = 1 and company = %s
|
from `tabSales Invoice` where docstatus = 1 and company = %s
|
||||||
and outstanding_amount > 0 %s""" % ('%s', cond), self.company)
|
and outstanding_amount > 0 %s""" % ('%s', cond), self.company, as_dict=True)
|
||||||
elif self.write_off_based_on == 'Accounts Payable':
|
elif self.write_off_based_on == 'Accounts Payable':
|
||||||
return frappe.db.sql("""select name, credit_to, outstanding_amount
|
return frappe.db.sql("""select name, credit_to as account, outstanding_amount
|
||||||
from `tabPurchase Invoice` where docstatus = 1 and company = %s
|
from `tabPurchase Invoice` where docstatus = 1 and company = %s
|
||||||
and outstanding_amount > 0 %s""" % ('%s', cond), self.company)
|
and outstanding_amount > 0 %s""" % ('%s', cond), self.company, as_dict=True)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_default_bank_cash_account(company, voucher_type):
|
def get_default_bank_cash_account(company, voucher_type):
|
||||||
|
|||||||
Reference in New Issue
Block a user