From a8de61e24bc68ef1f39a8f168b6b996cc358aeb8 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 17 Sep 2015 17:02:48 +0530 Subject: [PATCH 01/14] [fix] Multi currency patch --- erpnext/patches/v6_0/multi_currency.py | 53 ++++++++++++++++---------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/erpnext/patches/v6_0/multi_currency.py b/erpnext/patches/v6_0/multi_currency.py index 2b53134c05..979e03e2f2 100644 --- a/erpnext/patches/v6_0/multi_currency.py +++ b/erpnext/patches/v6_0/multi_currency.py @@ -9,8 +9,9 @@ def execute(): for dt in ("Account", "GL Entry", "Journal Entry", "Journal Entry Account", "Sales Invoice", "Purchase Invoice", "Customer", "Supplier"): frappe.reload_doctype(dt) - - for company in frappe.get_all("Company", fields=["name", "default_currency", "default_receivable_account"]): + + company_list = frappe.get_all("Company", fields=["name", "default_currency", "default_receivable_account"]) + for company in company_list: # update currency in account and gl entry as per company currency frappe.db.sql("""update `tabAccount` set account_currency = %s @@ -63,30 +64,40 @@ def execute(): company=%s """, (company.default_currency, company.name)) - # Set party account if default currency of party other than company's default currency - for dt in ("Customer", "Supplier"): - parties = frappe.get_all(dt) - for p in parties: + # Set party account if default currency of party other than company's default currency + for dt in ("Customer", "Supplier"): + parties = frappe.get_all(dt) + for p in parties: + party = frappe.get_doc(dt, p.name) + + for company in company_list: # Get party GL Entries party_gle = frappe.db.get_value("GL Entry", {"party_type": dt, "party": p.name, - "company": company.name}, ["account", "account_currency"], as_dict=True) - - party = frappe.get_doc(dt, p.name) - + "company": company.name}, ["account", "account_currency", "name"], as_dict=True) + # set party account currency - if party_gle or not party.party_account_currency: + if party_gle: + party.party_account_currency = party_gle.account_currency + elif not party.party_account_currency: party.party_account_currency = company.default_currency # Add default receivable /payable account if not exists # and currency is other than company currency + party_accounts = [] if party.party_account_currency and party.party_account_currency != company.default_currency: - party_account_exists = False + party_account_exists_for_company = False for d in party.get("accounts"): if d.company == company.name: - party_account_exists = True - break - - if not party_account_exists: + account_currency = frappe.db.get_value("Account", d.account, "account_currency") + if account_currency == party.party_account_currency: + party_accounts.append({ + "company": d.company, + "account": d.account + }) + party_account_exists_for_company = True + break + + if not party_account_exists_for_company: party_account = None if party_gle: party_account = party_gle.account @@ -95,12 +106,12 @@ def execute(): company.default_receivable_account, "account_currency") if default_receivable_account_currency != company.default_currency: party_account = company.default_receivable_account - + if party_account: - party.append("accounts", { + party_accounts.append({ "company": company.name, "account": party_account }) - - party.flags.ignore_mandatory = True - party.save() \ No newline at end of file + party.set("accounts", party_accounts) + party.flags.ignore_mandatory = True + party.save() \ No newline at end of file From c439b87ccc78ed44594738648524a6df2019c4f3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 17:28:39 +0530 Subject: [PATCH 02/14] [hotfix] multicurrency patch --- erpnext/patches/v6_0/multi_currency.py | 51 +++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/erpnext/patches/v6_0/multi_currency.py b/erpnext/patches/v6_0/multi_currency.py index 979e03e2f2..127734434e 100644 --- a/erpnext/patches/v6_0/multi_currency.py +++ b/erpnext/patches/v6_0/multi_currency.py @@ -6,84 +6,84 @@ import frappe def execute(): # Reload doctype - for dt in ("Account", "GL Entry", "Journal Entry", + for dt in ("Account", "GL Entry", "Journal Entry", "Journal Entry Account", "Sales Invoice", "Purchase Invoice", "Customer", "Supplier"): frappe.reload_doctype(dt) - + company_list = frappe.get_all("Company", fields=["name", "default_currency", "default_receivable_account"]) for company in company_list: - + # update currency in account and gl entry as per company currency - frappe.db.sql("""update `tabAccount` set account_currency = %s + frappe.db.sql("""update `tabAccount` set account_currency = %s where ifnull(account_currency, '') = '' and company=%s""", (company.default_currency, company.name)) - + # update newly introduced field's value in sales / purchase invoice frappe.db.sql(""" - update + update `tabSales Invoice` - set + set base_paid_amount=paid_amount, base_write_off_amount=write_off_amount, party_account_currency=%s where company=%s """, (company.default_currency, company.name)) - + frappe.db.sql(""" - update + update `tabPurchase Invoice` - set + set base_write_off_amount=write_off_amount, party_account_currency=%s where company=%s """, (company.default_currency, company.name)) - + # update exchange rate, debit/credit in account currency in Journal Entry frappe.db.sql(""" update `tabJournal Entry Account` jea - set exchange_rate=1, + set exchange_rate=1, debit_in_account_currency=debit, credit_in_account_currency=credit, account_type=(select account_type from `tabAccount` where name=jea.account) """) - + frappe.db.sql(""" update `tabJournal Entry Account` jea, `tabJournal Entry` je set account_currency=%s where jea.parent = je.name and je.company=%s """, (company.default_currency, company.name)) - + # update debit/credit in account currency in GL Entry frappe.db.sql(""" update `tabGL Entry` - set + set debit_in_account_currency=debit, credit_in_account_currency=credit, account_currency=%s where company=%s """, (company.default_currency, company.name)) - + # Set party account if default currency of party other than company's default currency for dt in ("Customer", "Supplier"): parties = frappe.get_all(dt) for p in parties: party = frappe.get_doc(dt, p.name) - + party_accounts = [] + for company in company_list: # Get party GL Entries - party_gle = frappe.db.get_value("GL Entry", {"party_type": dt, "party": p.name, + party_gle = frappe.db.get_value("GL Entry", {"party_type": dt, "party": p.name, "company": company.name}, ["account", "account_currency", "name"], as_dict=True) - + # set party account currency if party_gle: party.party_account_currency = party_gle.account_currency elif not party.party_account_currency: party.party_account_currency = company.default_currency - # Add default receivable /payable account if not exists + # Add default receivable /payable account if not exists # and currency is other than company currency - party_accounts = [] if party.party_account_currency and party.party_account_currency != company.default_currency: party_account_exists_for_company = False for d in party.get("accounts"): @@ -96,22 +96,23 @@ def execute(): }) party_account_exists_for_company = True break - + if not party_account_exists_for_company: party_account = None if party_gle: party_account = party_gle.account else: - default_receivable_account_currency = frappe.db.get_value("Account", + default_receivable_account_currency = frappe.db.get_value("Account", company.default_receivable_account, "account_currency") if default_receivable_account_currency != company.default_currency: party_account = company.default_receivable_account - + if party_account: party_accounts.append({ "company": company.name, "account": party_account }) + party.set("accounts", party_accounts) party.flags.ignore_mandatory = True - party.save() \ No newline at end of file + party.save() From ba0bf9e13dbbb0e473a5eb19b35f202784b74f03 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 17:36:05 +0530 Subject: [PATCH 03/14] [hotfix] multicurrency patch --- erpnext/patches/v6_0/multi_currency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/patches/v6_0/multi_currency.py b/erpnext/patches/v6_0/multi_currency.py index 127734434e..242df94258 100644 --- a/erpnext/patches/v6_0/multi_currency.py +++ b/erpnext/patches/v6_0/multi_currency.py @@ -66,7 +66,7 @@ def execute(): # Set party account if default currency of party other than company's default currency for dt in ("Customer", "Supplier"): - parties = frappe.get_all(dt) + parties = frappe.get_all(dt, filters={"docstatus": 0}) for p in parties: party = frappe.get_doc(dt, p.name) party_accounts = [] From d20120e649d814d37a4e5ee6387c6be6c72faf3e Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 17:46:37 +0530 Subject: [PATCH 04/14] [fix] remove duplicate newsletter subscribers --- erpnext/patches.txt | 3 ++- erpnext/patches/v6_2/__init__.py | 1 + erpnext/patches/v6_2/remove_newsletter_duplicates.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v6_2/__init__.py create mode 100644 erpnext/patches/v6_2/remove_newsletter_duplicates.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ffb7a21b5f..98c6f457f4 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -206,4 +206,5 @@ execute:frappe.db.set_value("Stock Settings", None, "automatically_set_serial_no execute:frappe.db.sql("""update `tabProject` set percent_complete=round(percent_complete, 2) where percent_complete is not null""") erpnext.patches.v6_0.fix_outstanding_amount erpnext.patches.v6_0.fix_planned_qty -erpnext.patches.v6_0.multi_currency \ No newline at end of file +erpnext.patches.v6_0.multi_currency +erpnext.patches.v6_2.remove_newsletter_duplicates diff --git a/erpnext/patches/v6_2/__init__.py b/erpnext/patches/v6_2/__init__.py new file mode 100644 index 0000000000..baffc48825 --- /dev/null +++ b/erpnext/patches/v6_2/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/erpnext/patches/v6_2/remove_newsletter_duplicates.py b/erpnext/patches/v6_2/remove_newsletter_duplicates.py new file mode 100644 index 0000000000..4f25c95777 --- /dev/null +++ b/erpnext/patches/v6_2/remove_newsletter_duplicates.py @@ -0,0 +1,12 @@ +import frappe + +def execute(): + duplicates = frappe.db.sql("""select newsletter_list, email, count(name) + from `tabNewsletter List Subscriber` + group by newsletter_list, email + having count(name) > 1""") + + # delete all duplicates except 1 + for newsletter_list, email, count in duplicates: + frappe.db.sql("""delete from `tabNewsletter List Subscriber` + where newsletter_list=%s and email=%s limit %s""", (newsletter_list, email, count-1)) From a69682c4e05f33d9a33ec13290ea365272764ac1 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 18:27:36 +0530 Subject: [PATCH 05/14] [hotfix] create customer contact and address from lead only on create --- erpnext/selling/doctype/customer/customer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 6b67c88702..7fe14596ee 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -31,8 +31,9 @@ class Customer(TransactionBase): def validate_mandatory(self): if frappe.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.naming_series: frappe.throw(_("Series is mandatory"), frappe.MandatoryError) - + def validate(self): + self.flags.is_new_doc = self.is_new() self.validate_mandatory() validate_accounting_currency(self) validate_party_account(self) @@ -76,7 +77,9 @@ class Customer(TransactionBase): self.update_lead_status() self.update_address() self.update_contact() - self.create_lead_address_contact() + + if self.flags.is_new_doc: + self.create_lead_address_contact() def validate_name_with_customer_group(self): if frappe.db.exists("Customer Group", self.name): @@ -131,7 +134,7 @@ def get_dashboard_info(customer): billing_this_year = frappe.db.sql(""" select sum(ifnull(debit_in_account_currency, 0)) - sum(ifnull(credit_in_account_currency, 0)) from `tabGL Entry` - where voucher_type='Sales Invoice' and party_type = 'Customer' + where voucher_type='Sales Invoice' and party_type = 'Customer' and party=%s and fiscal_year = %s""", (customer, frappe.db.get_default("fiscal_year"))) From 8adb5f3e3234820391e088c24e37fe37860f097f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 17 Sep 2015 18:40:35 +0530 Subject: [PATCH 06/14] Update journal_entry.py --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index cb12969112..11bf3847d1 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -551,7 +551,7 @@ def get_payment_entry_from_purchase_invoice(purchase_invoice): """Returns new Journal Entry document as dict for given Purchase Invoice""" pi = frappe.get_doc("Purchase Invoice", purchase_invoice) - exchange_rate = get_exchange_rate(pi.debit_to, pi.party_account_currency, pi.company, + exchange_rate = get_exchange_rate(pi.credit_to, pi.party_account_currency, pi.company, pi.doctype, pi.name) jv = get_payment_entry(pi) From ce6b61b41e7508a93461b62bcbe3f91ba4f031d5 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 19:01:27 +0530 Subject: [PATCH 07/14] [fix] customer naming series validation and patch to fix missing default taxes and lead --- erpnext/patches.txt | 1 + .../fix_missing_default_taxes_and_lead.py | 25 +++++++++++++++++++ erpnext/selling/doctype/customer/customer.py | 8 +++--- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 erpnext/patches/v6_2/fix_missing_default_taxes_and_lead.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 98c6f457f4..e20aab0b2e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -208,3 +208,4 @@ erpnext.patches.v6_0.fix_outstanding_amount erpnext.patches.v6_0.fix_planned_qty erpnext.patches.v6_0.multi_currency erpnext.patches.v6_2.remove_newsletter_duplicates +erpnext.patches.v6_2.fix_missing_default_taxes_and_lead diff --git a/erpnext/patches/v6_2/fix_missing_default_taxes_and_lead.py b/erpnext/patches/v6_2/fix_missing_default_taxes_and_lead.py new file mode 100644 index 0000000000..9c16f63798 --- /dev/null +++ b/erpnext/patches/v6_2/fix_missing_default_taxes_and_lead.py @@ -0,0 +1,25 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + # remove missing default taxes + for customer in frappe.db.sql_list("""select name from `tabCustomer` + where ifnull(default_taxes_and_charges, '')!='' and not exists ( + select name from `tabSales Taxes and Charges Template` where name=`tabCustomer`.default_taxes_and_charges + )"""): + c = frappe.get_doc("Customer", customer) + c.default_taxes_and_charges = None + c.save() + + for supplier in frappe.db.sql_list("""select name from `tabSupplier` + where ifnull(default_taxes_and_charges, '')!='' and not exists ( + select name from `tabPurchase Taxes and Charges Template` where name=`tabSupplier`.default_taxes_and_charges + )"""): + c = frappe.get_doc("Supplier", supplier) + c.default_taxes_and_charges = None + c.save() + + # remove missing lead + for customer in frappe.db.sql_list("""select name from `tabCustomer` + where ifnull(lead_name, '')!='' and not exists (select name from `tabLead` where name=`tabCustomer`.lead_name)"""): + frappe.db.set_value("Customer", customer, "lead_name", None) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 7fe14596ee..b060fba3c6 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -26,15 +26,13 @@ class Customer(TransactionBase): if cust_master_name == 'Customer Name': self.name = self.customer_name else: - self.name = make_autoname(self.naming_series+'.#####') + if not self.naming_series: + frappe.throw(_("Series is mandatory"), frappe.MandatoryError) - def validate_mandatory(self): - if frappe.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.naming_series: - frappe.throw(_("Series is mandatory"), frappe.MandatoryError) + self.name = make_autoname(self.naming_series+'.#####') def validate(self): self.flags.is_new_doc = self.is_new() - self.validate_mandatory() validate_accounting_currency(self) validate_party_account(self) From df8efce36f751aa92e2c52563c30a7c53f821e5b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 20:29:15 +0530 Subject: [PATCH 08/14] [hotfix] set_balance_in_account_currency --- erpnext/controllers/accounts_controller.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index ceb993096a..7a4a0df6b0 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -236,8 +236,10 @@ class AccountsController(TransactionBase): .format(account, _(" or ").join(valid_currency))) def set_balance_in_account_currency(self, gl_dict, account_currency=None): - if (not self.get("conversion_rate") and self.doctype!="Journal Entry" - and account_currency!=self.company_currency): + if self.doctype=="Journal Entry": + return + + if (not self.get("conversion_rate") and account_currency!=self.company_currency): frappe.throw(_("Account: {0} with currency: {1} can not be selected") .format(gl_dict.account, account_currency)) From 20fd360a63f773f69f97b2631de4c0b850405709 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 20:36:19 +0530 Subject: [PATCH 09/14] [hotfix] journal entry - get balance --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 11bf3847d1..6857c61a61 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -386,6 +386,7 @@ class JournalEntry(AccountsController): # If any row without amount, set the diff on that row if diff: + blank_row = None for d in self.get('accounts'): if not d.credit_in_account_currency and not d.debit_in_account_currency and diff != 0: blank_row = d From a48d7541586cf3667debf7a4a4f724449871c242 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 17 Sep 2015 19:38:11 +0530 Subject: [PATCH 10/14] [fix] minor issue --- erpnext/accounts/doctype/journal_entry/journal_entry.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 383b4b620d..a98130bfc4 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -350,6 +350,9 @@ frappe.ui.form.on("Journal Entry Account", { account: function(frm, dt, dn) { var d = locals[dt][dn]; if(d.account) { + if(!frm.doc.company) frappe.throw(__("Please select Company first")); + if(!frm.doc.posting_date) frappe.throw(__("Please select Posting Date first")); + return frappe.call({ method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_account_balance_and_party_type", args: { From 40759c284cec3da56da642fe7a79bbd52eac1a17 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 20:51:41 +0530 Subject: [PATCH 11/14] Revert "[hotfix] set_balance_in_account_currency" This reverts commit 9acd6a2629ba0b0eb7d4612bfd46af6dd78d3b38. --- erpnext/controllers/accounts_controller.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 7a4a0df6b0..ceb993096a 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -236,10 +236,8 @@ class AccountsController(TransactionBase): .format(account, _(" or ").join(valid_currency))) def set_balance_in_account_currency(self, gl_dict, account_currency=None): - if self.doctype=="Journal Entry": - return - - if (not self.get("conversion_rate") and account_currency!=self.company_currency): + if (not self.get("conversion_rate") and self.doctype!="Journal Entry" + and account_currency!=self.company_currency): frappe.throw(_("Account: {0} with currency: {1} can not be selected") .format(gl_dict.account, account_currency)) From b8b8de7a497b78dc22c155f3d3135ee0bb8ae28d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Sep 2015 21:07:04 +0530 Subject: [PATCH 12/14] [hotfix] multicurrency gl entry --- erpnext/controllers/accounts_controller.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index ceb993096a..f66b425ee9 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -219,14 +219,13 @@ class AccountsController(TransactionBase): if not account_currency: account_currency = frappe.db.get_value("Account", gl_dict.account, "account_currency") - self.validate_account_currency(gl_dict.account, account_currency) - gl_dict = self.set_balance_in_account_currency(gl_dict, account_currency) + if self.doctype != "Journal Entry": + self.validate_account_currency(gl_dict.account, account_currency) + self.set_balance_in_account_currency(gl_dict, account_currency) return gl_dict def validate_account_currency(self, account, account_currency=None): - if self.doctype == "Journal Entry": - return valid_currency = [self.company_currency] if self.get("currency") and self.currency != self.company_currency: valid_currency.append(self.currency) @@ -236,8 +235,7 @@ class AccountsController(TransactionBase): .format(account, _(" or ").join(valid_currency))) def set_balance_in_account_currency(self, gl_dict, account_currency=None): - if (not self.get("conversion_rate") and self.doctype!="Journal Entry" - and account_currency!=self.company_currency): + if (not self.get("conversion_rate") and account_currency!=self.company_currency): frappe.throw(_("Account: {0} with currency: {1} can not be selected") .format(gl_dict.account, account_currency)) @@ -253,8 +251,6 @@ class AccountsController(TransactionBase): gl_dict.credit_in_account_currency = gl_dict.credit if account_currency==self.company_currency \ else flt(gl_dict.credit / (self.get("conversion_rate")), 2) - return gl_dict - def clear_unallocated_advances(self, childtype, parentfield): self.set(parentfield, self.get(parentfield, {"allocated_amount": ["not in", [0, None, ""]]})) From e4dfeb651fe7386521d452e92ddf3b7caa89d503 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 21 Sep 2015 19:28:59 +0530 Subject: [PATCH 13/14] [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): From 5b649521d19c4aa5e4d50b4897632eb26e69af8c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 22 Sep 2015 08:35:46 +0530 Subject: [PATCH 14/14] [fix] Get outstanding invoices in Payment Reconciliation and Payment Tool --- .../payment_reconciliation/payment_reconciliation.py | 8 ++++++-- erpnext/accounts/doctype/payment_tool/payment_tool.py | 2 +- erpnext/accounts/utils.py | 10 ++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index 09bd7d2cc8..743df3704d 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -70,7 +70,7 @@ class PaymentReconciliation(Document): non_reconciled_invoices = [] dr_or_cr = "debit" if self.party_type == "Customer" else "credit" cond = self.check_condition(dr_or_cr) - + invoice_list = frappe.db.sql(""" select voucher_no, voucher_type, posting_date, @@ -79,8 +79,12 @@ class PaymentReconciliation(Document): `tabGL Entry` where party_type = %(party_type)s and party = %(party)s - and voucher_type != "Journal Entry" and account = %(account)s and {dr_or_cr} > 0 {cond} + and (CASE + WHEN voucher_type = 'Journal Entry' + THEN ifnull(against_voucher, '') = '' + ELSE 1=1 + END) group by voucher_type, voucher_no """.format(**{ "cond": cond, diff --git a/erpnext/accounts/doctype/payment_tool/payment_tool.py b/erpnext/accounts/doctype/payment_tool/payment_tool.py index eedf69fe5d..b02214c847 100644 --- a/erpnext/accounts/doctype/payment_tool/payment_tool.py +++ b/erpnext/accounts/doctype/payment_tool/payment_tool.py @@ -71,7 +71,7 @@ def get_outstanding_vouchers(args): # Get all outstanding sales /purchase invoices outstanding_invoices = get_outstanding_invoices(amount_query, args.get("party_account"), - args.get("party_type"), args.get("party"), with_journal_entry=False) + args.get("party_type"), args.get("party")) # Get all SO / PO which are not fully billed or aginst which full advance not paid orders_to_be_billed = get_orders_to_be_billed(args.get("party_type"), args.get("party"), diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 04084ed0e8..645c91c8f7 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -397,7 +397,7 @@ def get_stock_rbnb_difference(posting_date, company): # Amount should be credited return flt(stock_rbnb) + flt(sys_bal) -def get_outstanding_invoices(amount_query, account, party_type, party, with_journal_entry=True): +def get_outstanding_invoices(amount_query, account, party_type, party): all_outstanding_vouchers = [] outstanding_voucher_list = frappe.db.sql(""" select @@ -407,6 +407,11 @@ def get_outstanding_invoices(amount_query, account, party_type, party, with_jour `tabGL Entry` where account = %s and party_type=%s and party=%s and {amount_query} > 0 + and (CASE + WHEN voucher_type = 'Journal Entry' + THEN ifnull(against_voucher, '') = '' + ELSE 1=1 + END) group by voucher_type, voucher_no """.format(amount_query = amount_query), (account, party_type, party), as_dict = True) @@ -425,9 +430,6 @@ def get_outstanding_invoices(amount_query, account, party_type, party, with_jour payment_amount = -1*payment_amount[0][0] if payment_amount else 0 precision = frappe.get_precision("Sales Invoice", "outstanding_amount") - if not with_journal_entry and d.voucher_type=="Journal Entry": - continue - if d.invoice_amount > payment_amount: all_outstanding_vouchers.append({