Add Customer Credit Balance Report, minor changes
diff --git a/erpnext/selling/report/customer_credit_balance/__init__.py b/erpnext/selling/report/customer_credit_balance/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/selling/report/customer_credit_balance/__init__.py
diff --git a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.js b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.js
new file mode 100644
index 0000000..90254ad
--- /dev/null
+++ b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.js
@@ -0,0 +1,21 @@
+// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Customer Credit Balance"] = {
+ "filters": [
+ {
+ "fieldname":"company",
+ "label": __("Company"),
+ "fieldtype": "Link",
+ "options": "Company",
+ "reqd": 1,
+ "default": frappe.defaults.get_user_default("company")
+ },
+ {
+ "fieldname":"customer",
+ "label": __("Customer"),
+ "fieldtype": "Link",
+ "options": "Customer"
+ }
+ ]
+}
diff --git a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.json b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.json
new file mode 100644
index 0000000..94ea416
--- /dev/null
+++ b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.json
@@ -0,0 +1,17 @@
+{
+ "add_total_row": 0,
+ "apply_user_permissions": 1,
+ "creation": "2014-10-06 15:19:31.578162",
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "is_standard": "Yes",
+ "modified": "2014-10-06 15:19:37.578616",
+ "modified_by": "Administrator",
+ "module": "Selling",
+ "name": "Customer Credit Balance",
+ "owner": "Administrator",
+ "ref_doctype": "Customer",
+ "report_name": "Customer Credit Balance",
+ "report_type": "Script Report"
+}
\ No newline at end of file
diff --git a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py
new file mode 100644
index 0000000..9bc14ac
--- /dev/null
+++ b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py
@@ -0,0 +1,54 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import flt
+from erpnext.selling.doctype.customer.customer import get_customer_outstanding, get_credit_limit
+
+def execute(filters=None):
+ if not filters: filters = {}
+ #Check if customer id is according to naming series or customer name
+ customer_naming_type = frappe.db.get_value("Selling Settings", None, "cust_master_name")
+ columns = get_columns(customer_naming_type)
+
+ data = []
+
+ customer_list = get_details(filters)
+
+ for d in customer_list:
+ row = []
+ outstanding_amt = get_customer_outstanding(d.name, filters.get("company"))
+ credit_limit = get_credit_limit(d.name, filters.get("company"))
+ bal = flt(credit_limit) - flt(outstanding_amt)
+
+ if customer_naming_type == "Naming Series":
+ row = [d.name, d.customer_name, credit_limit, outstanding_amt, bal]
+ else:
+ row = [d.name, credit_limit, outstanding_amt, bal]
+
+ if credit_limit:
+ data.append(row)
+
+ return columns, data
+
+def get_columns(customer_naming_type):
+ columns = [
+ _("Customer") + ":Link/Customer:120", _("Credit Limit") + ":Currency:120",
+ _("Outstanding Amt") + ":Currency:100", _("Credit Balance") + ":Currency:120"
+ ]
+
+ if customer_naming_type == "Naming Series":
+ columns.insert(1, _("Customer Name") + ":Data:120")
+
+ return columns
+
+def get_details(filters):
+ conditions = ""
+
+ if filters.get("customer"):
+ conditions += " where name = %(customer)s"
+
+ return frappe.db.sql("""select name, customer_name from `tabCustomer` %s"""
+ % conditions, filters, as_dict=1)