Credit limit fixes
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 2f60dca..e067c70 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -165,7 +165,7 @@
# If outstanding greater than credit limit and not authorized person raise exception
if credit_limit > 0 and flt(total_outstanding) > credit_limit \
and not self.get_authorized_user():
- throw(_("{0} Credit limit {0} crossed").format(_(credit_limit_from), credit_limit))
+ throw(_("{0} Credit limit {1} crossed").format(_(credit_limit_from), credit_limit))
def validate_due_date(self, posting_date, due_date):
credit_days = (self.credit_days or frappe.db.get_value("Company", self.company, "credit_days"))
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index dd58758..e758dd1 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -151,7 +151,7 @@
cumulated_tax_fraction += tax.tax_fraction_for_current_item
- if cumulated_tax_fraction and not self.discount_amount_applied:
+ if cumulated_tax_fraction and not self.discount_amount_applied and item.qty:
item.base_amount = flt((item.amount * self.conversion_rate) /
(1 + cumulated_tax_fraction), self.precision("base_amount", item))
@@ -308,14 +308,23 @@
customer_account = frappe.db.get_value("Account", {"company": self.company,
"master_name": self.customer}, "name")
if customer_account:
- total_outstanding = frappe.db.sql("""select
+ invoice_outstanding = frappe.db.sql("""select
sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry` where account = %s""", customer_account)
- total_outstanding = total_outstanding[0][0] if total_outstanding else 0
+ invoice_outstanding = flt(invoice_outstanding[0][0]) if invoice_outstanding else 0
- outstanding_including_current = flt(total_outstanding) + flt(grand_total)
- frappe.get_doc('Account', customer_account).run_method("check_credit_limit",
- outstanding_including_current)
+ ordered_amount_to_be_billed = frappe.db.sql("""
+ select sum(grand_total*(100 - ifnull(per_billed, 0))/100)
+ from `tabSales Order`
+ where customer=%s and docstatus = 1
+ and ifnull(per_billed, 0) < 100 and status != 'Stopped'""", self.customer)
+
+ ordered_amount_to_be_billed = flt(ordered_amount_to_be_billed[0][0]) \
+ if ordered_amount_to_be_billed else 0.0
+
+ total_outstanding = invoice_outstanding + ordered_amount_to_be_billed
+
+ frappe.get_doc('Account', customer_account).check_credit_limit(total_outstanding)
def validate_max_discount(self):
for d in self.get(self.fname):
@@ -330,6 +339,9 @@
reserved_warehouse = ""
reserved_qty_for_main_item = 0
+ if not d.qty:
+ frappe.throw(_("Row {0}: Qty is mandatory").format(d.idx))
+
if self.doctype == "Sales Order":
if (frappe.db.get_value("Item", d.item_code, "is_stock_item") == 'Yes' or
self.has_sales_bom(d.item_code)) and not d.warehouse: