From c7614174d062e713fae1b0b057afb46b1622e0bb Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 13 Aug 2020 09:18:59 +0530 Subject: [PATCH] fix: cannot change customer fields if credit exhausted (#22838) * fix: cannot change customer fields if credit exhausted * fix: order based on company * fix: sort current limits w.r.t company before compare * fix: CustomerCreditLimit Object is not subscriptable --- erpnext/selling/doctype/customer/customer.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index ca62488a8c..93d4832173 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -184,6 +184,14 @@ class Customer(TransactionBase): def validate_credit_limit_on_change(self): if self.get("__islocal") or not self.credit_limits: return + + past_credit_limits = [d.credit_limit + for d in frappe.db.get_all("Customer Credit Limit", filters={'parent': self.name}, fields=["credit_limit"], order_by="company")] + + current_credit_limits = [d.credit_limit for d in sorted(self.credit_limits, key=lambda k: k.company)] + + if past_credit_limits == current_credit_limits: + return company_record = [] for limit in self.credit_limits: