From e05656963aeebe240e908c72c93a04b12c4a1bc3 Mon Sep 17 00:00:00 2001 From: shreyas Date: Wed, 19 Oct 2016 15:59:21 +0530 Subject: [PATCH] [Minor] Do not allow change in credit limit --- erpnext/selling/doctype/customer/customer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index e29169604e..18bd4432bd 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -69,6 +69,7 @@ class Customer(TransactionBase): self.flags.old_lead = self.lead_name validate_party_accounts(self) self.status = get_party_status(self) + self.validate_credit_limit_on_change() def on_update(self): self.validate_name_with_customer_group() @@ -125,6 +126,15 @@ class Customer(TransactionBase): if frappe.db.exists("Customer Group", self.name): frappe.throw(_("A Customer Group exists with same name please change the Customer name or rename the Customer Group"), frappe.NameError) + def validate_credit_limit_on_change(self): + customer = frappe.get_doc('Customer', self.name) + companies = [c.name for c in frappe.get_all("Company")] + + for company in companies: + outstanding_amt = get_customer_outstanding(customer.name, company) + if flt(self.credit_limit) < outstanding_amt: + frappe.throw(_("New credit limit is less than current outstanding amount for the customer. Credit limit has to be atleast {0}").format(outstanding_amt)) + def delete_customer_address(self): addresses = frappe.db.sql("""select name, lead from `tabAddress` where customer=%s""", (self.name,))