From 6b35ea873bbf48349ce0352e9b31cbd55b5fa0ae Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 1 Jul 2015 12:25:18 +0530 Subject: [PATCH 1/3] [fix] against account in general ledger will show party --- erpnext/accounts/doctype/gl_entry/gl_entry.py | 21 ++++++++++- .../doctype/journal_entry/journal_entry.py | 12 +++--- .../purchase_invoice/purchase_invoice.py | 16 ++++---- .../doctype/sales_invoice/sales_invoice.py | 10 ++--- erpnext/patches.txt | 3 +- erpnext/patches/v5_1/__init__.py | 0 erpnext/patches/v5_1/fix_against_account.py | 37 +++++++++++++++++++ 7 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 erpnext/patches/v5_1/__init__.py create mode 100644 erpnext/patches/v5_1/fix_against_account.py diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 138cf23d38..3d306fb8d5 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -127,7 +127,7 @@ def update_outstanding_amt(account, party_type, party, against_voucher_type, aga against_voucher_amount = flt(frappe.db.sql(""" select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) from `tabGL Entry` where voucher_type = 'Journal Entry' and voucher_no = %s - and account = %s and ifnull(party_type, '')=%s and ifnull(party, '')=%s + and account = %s and ifnull(party_type, '')=%s and ifnull(party, '')=%s and ifnull(against_voucher, '') = ''""", (against_voucher, account, cstr(party_type), cstr(party)))[0][0]) @@ -158,3 +158,22 @@ def validate_frozen_account(account, adv_adj=None): frappe.throw(_("Account {0} is frozen").format(account)) elif frozen_accounts_modifier not in frappe.get_roles(): frappe.throw(_("Not authorized to edit frozen Account {0}").format(account)) + +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"]) + + 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) + + for d in entries: + if flt(d.debit > 0): + new_against = ", ".join(list(set(accounts_credited))) + if flt(d.credit > 0): + new_against = ", ".join(list(set(accounts_debited))) + + if d.against != new_against: + frappe.db.set_value("GL Entry", d.name, "against", new_against) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 7bf6c56dc5..489d4889a1 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -81,7 +81,7 @@ class JournalEntry(AccountsController): frappe.throw(_("Row {0}: Party Type and Party is only applicable against Receivable / Payable account").format(d.idx)) def check_credit_limit(self): - customers = list(set([d.party for d in self.get("accounts") + customers = list(set([d.party for d in self.get("accounts") if d.party_type=="Customer" and d.party and flt(d.debit) > 0])) if customers: from erpnext.selling.doctype.customer.customer import check_credit_limit @@ -243,8 +243,8 @@ class JournalEntry(AccountsController): def set_against_account(self): accounts_debited, accounts_credited = [], [] for d in self.get("accounts"): - if flt(d.debit > 0): accounts_debited.append(d.account) - if flt(d.credit) > 0: accounts_credited.append(d.account) + 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) for d in self.get("accounts"): if flt(d.debit > 0): d.against_account = ", ".join(list(set(accounts_credited))) @@ -274,9 +274,9 @@ class JournalEntry(AccountsController): r.append(_('Reference #{0} dated {1}').format(self.cheque_no, formatdate(self.cheque_date))) else: msgprint(_("Please enter Reference date"), raise_exception=frappe.MandatoryError) - + company_currency = get_company_currency(self.company) - + for d in self.get('accounts'): if d.against_invoice and d.credit: r.append(_("{0} against Sales Invoice {1}").format(fmt_money(flt(d.credit), currency = company_currency), \ @@ -426,7 +426,7 @@ class JournalEntry(AccountsController): def validate_expense_claim(self): for d in self.accounts: if d.against_expense_claim: - sanctioned_amount, reimbursed_amount = frappe.db.get_value("Expense Claim", + sanctioned_amount, reimbursed_amount = frappe.db.get_value("Expense Claim", d.against_expense_claim, ("total_sanctioned_amount", "total_amount_reimbursed")) pending_amount = flt(sanctioned_amount) - flt(reimbursed_amount) if d.debit > pending_amount: diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 660b221e7b..50a79ec01b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -164,7 +164,7 @@ class PurchaseInvoice(BuyingController): elif item.expense_account not in against_accounts: # if no auto_accounting_for_stock or not a stock item against_accounts.append(item.expense_account) - + self.against_expense_account = ",".join(against_accounts) def po_required(self): @@ -271,7 +271,7 @@ class PurchaseInvoice(BuyingController): gl_entries.append( self.get_gl_dict({ "account": tax.account_head, - "against": self.credit_to, + "against": self.supplier, "debit": tax.add_deduct_tax == "Add" and tax.base_tax_amount_after_discount_amount or 0, "credit": tax.add_deduct_tax == "Deduct" and tax.base_tax_amount_after_discount_amount or 0, "remarks": self.remarks, @@ -295,7 +295,7 @@ class PurchaseInvoice(BuyingController): gl_entries.append( self.get_gl_dict({ "account": item.expense_account, - "against": self.credit_to, + "against": self.supplier, "debit": item.base_net_amount, "remarks": self.remarks, "cost_center": item.cost_center @@ -315,7 +315,7 @@ class PurchaseInvoice(BuyingController): gl_entries.append( self.get_gl_dict({ "account": stock_received_but_not_billed, - "against": self.credit_to, + "against": self.supplier, "debit": flt(item.item_tax_amount, self.precision("item_tax_amount", item)), "remarks": self.remarks or "Accounting Entry for Stock" }) @@ -341,7 +341,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict({ "account": expenses_included_in_valuation, "cost_center": cost_center, - "against": self.credit_to, + "against": self.supplier, "credit": applicable_amount, "remarks": self.remarks or "Accounting Entry for Stock" }) @@ -355,7 +355,7 @@ class PurchaseInvoice(BuyingController): gl_entries.append( self.get_gl_dict({ "account": self.write_off_account, - "against": self.credit_to, + "against": self.supplier, "credit": flt(self.write_off_amount), "remarks": self.remarks, "cost_center": self.write_off_cost_center @@ -374,7 +374,7 @@ class PurchaseInvoice(BuyingController): self.update_billing_status_for_zero_amount_refdoc("Purchase Order") self.make_gl_entries_on_cancel() self.update_project() - + def update_project(self): project_list = [] for d in self.items: @@ -384,7 +384,7 @@ class PurchaseInvoice(BuyingController): project.update_purchase_costing() project.save() project_list.append(d.project_name) - + def validate_supplier_invoice(self): if self.bill_date: if getdate(self.bill_date) > getdate(self.posting_date): diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 87f723d4f8..604370b326 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -503,7 +503,7 @@ class SalesInvoice(SellingController): gl_entries.append( self.get_gl_dict({ "account": tax.account_head, - "against": self.debit_to, + "against": self.customer, "credit": flt(tax.base_tax_amount_after_discount_amount), "remarks": self.remarks, "cost_center": tax.cost_center @@ -517,7 +517,7 @@ class SalesInvoice(SellingController): gl_entries.append( self.get_gl_dict({ "account": item.income_account, - "against": self.debit_to, + "against": self.customer, "credit": item.base_net_amount, "remarks": self.remarks, "cost_center": item.cost_center @@ -548,7 +548,7 @@ class SalesInvoice(SellingController): gl_entries.append( self.get_gl_dict({ "account": self.cash_bank_account, - "against": self.debit_to, + "against": self.customer, "debit": self.paid_amount, "remarks": self.remarks, }) @@ -572,7 +572,7 @@ class SalesInvoice(SellingController): gl_entries.append( self.get_gl_dict({ "account": self.write_off_account, - "against": self.debit_to, + "against": self.customer, "debit": self.write_off_amount, "remarks": self.remarks, "cost_center": self.write_off_cost_center @@ -587,7 +587,7 @@ def get_list_context(context=None): @frappe.whitelist() def get_bank_cash_account(mode_of_payment, company): - account = frappe.db.get_value("Mode of Payment Account", + account = frappe.db.get_value("Mode of Payment Account", {"parent": mode_of_payment, "company": company}, "default_account") if not account: frappe.msgprint(_("Please set default Cash or Bank account in Mode of Payment {0}").format(mode_of_payment)) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 725e020888..b21d31b5c8 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -169,4 +169,5 @@ erpnext.patches.v5_0.update_material_transferred_for_manufacturing_again erpnext.patches.v5_0.index_on_account_and_gl_entry execute:frappe.db.sql("""delete from `tabProject Task`""") erpnext.patches.v5_0.item_variants -erpnext.patches.v5_0.update_item_desc_in_invoice \ No newline at end of file +erpnext.patches.v5_0.update_item_desc_in_invoice +erpnext.patches.v5_1.fix_against_account diff --git a/erpnext/patches/v5_1/__init__.py b/erpnext/patches/v5_1/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/patches/v5_1/fix_against_account.py b/erpnext/patches/v5_1/fix_against_account.py new file mode 100644 index 0000000000..f0b57d9b59 --- /dev/null +++ b/erpnext/patches/v5_1/fix_against_account.py @@ -0,0 +1,37 @@ +from __future__ import unicode_literals + +import frappe + +from erpnext.accounts.doctype.gl_entry.gl_entry import update_against_account + +def execute(): + from_date = "2015-01-01" + + for doc in frappe.get_all("Journal Entry", + filters={"creation": (">", from_date), "docstatus": "1"}): + + # update in gl_entry + update_against_account("Journal Entry", doc.name) + + # update in jv + doc = frappe.get_doc("Journal Entry", doc.name) + doc.set_against_account() + doc.db_update() + + for doc in frappe.get_all("Sales Invoice", + filters={"creation": (">", from_date), "docstatus": "1"}, + fields=["name", "customer"]): + + frappe.db.sql("""update `tabGL Entry` set against=%s + where voucher_type='Sales Invoice' and voucher_no=%s + and credit > 0 and ifnull(party, '')=''""", + (doc.customer, doc.name)) + + for doc in frappe.get_all("Purchase Invoice", + filters={"creation": (">", from_date), "docstatus": "1"}, + fields=["name", "supplier"]): + + frappe.db.sql("""update `tabGL Entry` set against=%s + where voucher_type='Purchase Invoice' and voucher_no=%s + and debit > 0 and ifnull(party, '')=''""", + (doc.supplier, doc.name)) From 0b0ec3536c151fdbf8fe83533ee82531fcfbdc20 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 1 Jul 2015 12:28:37 +0530 Subject: [PATCH 2/3] [change-log] added --- erpnext/change_log/current/v5_1_0.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 erpnext/change_log/current/v5_1_0.md diff --git a/erpnext/change_log/current/v5_1_0.md b/erpnext/change_log/current/v5_1_0.md new file mode 100644 index 0000000000..852fa075bd --- /dev/null +++ b/erpnext/change_log/current/v5_1_0.md @@ -0,0 +1 @@ +- Against account in General Ledger will show Party instead of Account (which is not useful) From 2cd02af80aa82899f660048d0986558e82702bdd Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 1 Jul 2015 12:29:41 +0530 Subject: [PATCH 3/3] [fix] patch date --- erpnext/patches/v5_1/fix_against_account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/patches/v5_1/fix_against_account.py b/erpnext/patches/v5_1/fix_against_account.py index f0b57d9b59..a62c15b7d1 100644 --- a/erpnext/patches/v5_1/fix_against_account.py +++ b/erpnext/patches/v5_1/fix_against_account.py @@ -5,7 +5,7 @@ import frappe from erpnext.accounts.doctype.gl_entry.gl_entry import update_against_account def execute(): - from_date = "2015-01-01" + from_date = "2015-05-01" for doc in frappe.get_all("Journal Entry", filters={"creation": (">", from_date), "docstatus": "1"}):