[fix] against account in general ledger will show party
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index 138cf23..3d306fb 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -127,7 +127,7 @@
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 @@
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 7bf6c56..489d488 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -81,7 +81,7 @@
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 @@
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 @@
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 @@
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 660b221..50a79ec 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -164,7 +164,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 87f723d..604370b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -503,7 +503,7 @@
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 @@
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 @@
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 @@
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 @@
@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 725e020..b21d31b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -169,4 +169,5 @@
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 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/v5_1/__init__.py
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 0000000..f0b57d9
--- /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))