From b4263a41c6751e1e1f90dc5d4008ed50ef8f5a24 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 1 Apr 2019 19:11:34 +0530 Subject: [PATCH 1/2] fix: Validate gl entry debit/credit as per field's precision --- erpnext/accounts/doctype/gl_entry/gl_entry.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 5c76799e4ea..3b2f5db78d1 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -56,7 +56,7 @@ class GLEntry(Document): .format(self.voucher_type, self.voucher_no, self.account)) # Zero value transaction is not allowed - if not (flt(self.debit) or flt(self.credit)): + if not (flt(self.debit, self.precision("debit")) or flt(self.credit, self.precision("credit"))): frappe.throw(_("{0} {1}: Either debit or credit amount is required for {2}") .format(self.voucher_type, self.voucher_no, self.account)) @@ -216,17 +216,23 @@ def validate_frozen_account(account, adv_adj=None): def update_against_account(voucher_type, voucher_no): entries = frappe.db.get_all("GL Entry", filters={"voucher_type": voucher_type, "voucher_no": voucher_no}, - fields=["name", "party", "against", "debit", "credit", "account"]) + fields=["name", "party", "against", "debit", "credit", "account", "company"]) + + if not entries: + return + company_currency = erpnext.get_company_currency(entries[0].company) + precision = get_field_precision(frappe.get_meta("GL Entry") + .get_field("debit"), company_currency) accounts_debited, accounts_credited = [], [] for d in entries: - if flt(d.debit > 0): accounts_debited.append(d.party or d.account) - if flt(d.credit) > 0: accounts_credited.append(d.party or d.account) + if flt(d.debit, precision) > 0: accounts_debited.append(d.party or d.account) + if flt(d.credit, precision) > 0: accounts_credited.append(d.party or d.account) for d in entries: - if flt(d.debit > 0): + if flt(d.debit, precision) > 0: new_against = ", ".join(list(set(accounts_credited))) - if flt(d.credit > 0): + if flt(d.credit, precision) > 0: new_against = ", ".join(list(set(accounts_debited))) if d.against != new_against: From b1f3f04d7140bcf570ab1eb4c441c5a888a0e6f5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 3 Apr 2019 12:30:25 +0530 Subject: [PATCH 2/2] fix: Validate gl entry debit/credit as per field's precision --- erpnext/accounts/doctype/gl_entry/gl_entry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 3b2f5db78d1..e719167e784 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -6,6 +6,7 @@ import frappe, erpnext from frappe import _ from frappe.utils import flt, fmt_money, getdate, formatdate from frappe.model.document import Document +from frappe.model.meta import get_field_precision from erpnext.accounts.party import validate_party_gle_currency, validate_party_frozen_disabled from erpnext.accounts.utils import get_account_currency from erpnext.accounts.utils import get_fiscal_year