From e4dfeb651fe7386521d452e92ddf3b7caa89d503 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 21 Sep 2015 19:28:59 +0530 Subject: [PATCH] [optimization] get balance on --- erpnext/accounts/doctype/gl_entry/gl_entry.json | 4 ++-- .../accounts/doctype/journal_entry/journal_entry.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json index b4ec8beeb9..1cd722021e 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.json +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json @@ -330,7 +330,7 @@ "read_only": 0, "report_hide": 0, "reqd": 0, - "search_index": 0, + "search_index": 1, "set_only_once": 0, "unique": 0 }, @@ -511,7 +511,7 @@ "is_submittable": 0, "issingle": 0, "istable": 0, - "modified": "2015-09-11 15:51:26", + "modified": "2015-09-21 15:51:26", "modified_by": "Administrator", "module": "Accounts", "name": "GL Entry", diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 6857c61a61..ff5b37cd6c 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -476,9 +476,18 @@ class JournalEntry(AccountsController): frappe.throw("Accounts table cannot be blank.") def set_account_and_party_balance(self): + account_balance = {} + party_balance = {} for d in self.get("accounts"): - d.account_balance = get_balance_on(account=d.account, date=self.posting_date) - d.party_balance = get_balance_on(party_type=d.party_type, party=d.party, date=self.posting_date) + if d.account not in account_balance: + account_balance[d.account] = get_balance_on(account=d.account, date=self.posting_date) + + if (d.party_type, d.party) not in party_balance: + party_balance[(d.party_type, d.party)] = get_balance_on(party_type=d.party_type, + party=d.party, date=self.posting_date) + + d.account_balance = account_balance[d.account] + d.party_balance = party_balance[(d.party_type, d.party)] @frappe.whitelist() def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):