From 5bbe823106eb032be4dfbc7924735e77d24a83ca Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Aug 2015 18:59:25 +0530 Subject: [PATCH] [patch] Fix outstanding amount for original invoice for return entry --- .../accounts/doctype/journal_entry/journal_entry.py | 6 +++--- erpnext/controllers/sales_and_purchase_return.py | 4 +++- erpnext/patches/v5_4/fix_invoice_outstanding.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 erpnext/patches/v5_4/fix_invoice_outstanding.py diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 4847718602..f0630ce91c 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -554,17 +554,17 @@ def get_outstanding(args): against_jv_amount = flt(against_jv_amount[0][0]) if against_jv_amount else 0 return { - "credit" if against_jv_amount > 0 else "debit": abs(against_jv_amount) + ("credit" if against_jv_amount > 0 else "debit"): abs(against_jv_amount) } elif args.get("doctype") == "Sales Invoice": outstanding_amount = flt(frappe.db.get_value("Sales Invoice", args["docname"], "outstanding_amount")) return { - "credit" if outstanding_amount > 0 else "debit": abs(outstanding_amount) + ("credit" if outstanding_amount > 0 else "debit"): abs(outstanding_amount) } elif args.get("doctype") == "Purchase Invoice": outstanding_amount = flt(frappe.db.get_value("Purchase Invoice", args["docname"], "outstanding_amount")) return { - "debit" if outstanding_amount > 0 else "credit": abs(outstanding_amount) + ("debit" if outstanding_amount > 0 else "credit"): abs(outstanding_amount) } @frappe.whitelist() diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 6e88bfb0d5..46a5e22dec 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -136,7 +136,9 @@ def make_return_doc(doctype, source_name, target_doc=None): "doctype": doctype + " Item", "fields": { "purchase_order": "purchase_order", - "purchase_receipt": "purchase_receipt" + "purchase_receipt": "purchase_receipt", + "serial_no": "serial_no", + "batch_no": "batch_no" }, "postprocess": update_item }, diff --git a/erpnext/patches/v5_4/fix_invoice_outstanding.py b/erpnext/patches/v5_4/fix_invoice_outstanding.py new file mode 100644 index 0000000000..81b8f2c2df --- /dev/null +++ b/erpnext/patches/v5_4/fix_invoice_outstanding.py @@ -0,0 +1,12 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt + +def execute(): + return_entries = frappe.get_list("Sales Invoice", filters={"is_return": 1, "docstatus": 1}, + fields=["debit_to", "customer", "return_against"]) + for d in return_entries: + update_outstanding_amt(d.debit_to, "Customer", d.customer, "Sales Invoice", d.return_against) \ No newline at end of file