fix: grid view of customer credit limit
This commit is contained in:
parent
5755d2d32f
commit
c059bc3e36
@ -167,13 +167,12 @@ class Customer(TransactionBase):
|
|||||||
frappe.throw(_("A Customer Group exists with same name please change the Customer name or rename the Customer Group"), frappe.NameError)
|
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):
|
def validate_credit_limit_on_change(self):
|
||||||
if self.get("__islocal") or not self.credit_limit \
|
if self.get("__islocal") or not self.credit_limit:
|
||||||
or self.credit_limit == frappe.db.get_value("Customer", self.name, "credit_limit"):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
for company in frappe.get_all("Company"):
|
for limit in frappe.get_all("Customer Credit Limit", {'parent': self.name}, ["credit_limit", "company"]):
|
||||||
outstanding_amt = get_customer_outstanding(self.name, company.name)
|
outstanding_amt = get_customer_outstanding(self.name, limit.company)
|
||||||
if flt(self.credit_limit) < outstanding_amt:
|
if flt(limit.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))
|
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 on_trash(self):
|
def on_trash(self):
|
||||||
@ -322,11 +321,16 @@ def get_credit_limit(customer, company):
|
|||||||
credit_limit = None
|
credit_limit = None
|
||||||
|
|
||||||
if customer:
|
if customer:
|
||||||
credit_limit, customer_group = frappe.get_cached_value("Customer",
|
credit_record = frappe.db.sql("""SELECT
|
||||||
customer, ["credit_limit", "customer_group"])
|
customer_group,
|
||||||
|
credit_limit
|
||||||
|
FROM `tabCustomer`c , `tabCustomer Credit Limit` ccl
|
||||||
|
WHERE
|
||||||
|
c.name = ccl.parent
|
||||||
|
""", as_dict=1)
|
||||||
|
|
||||||
if not credit_limit:
|
if not credit_record.credit_limit:
|
||||||
credit_limit = frappe.get_cached_value("Customer Group", customer_group, "credit_limit")
|
credit_limit = frappe.get_cached_value("Customer Group", credit_record.customer_group, "credit_limit")
|
||||||
|
|
||||||
if not credit_limit:
|
if not credit_limit:
|
||||||
credit_limit = frappe.get_cached_value('Company', company, "credit_limit")
|
credit_limit = frappe.get_cached_value('Company', company, "credit_limit")
|
||||||
|
|||||||
@ -4,13 +4,14 @@
|
|||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"credit_limit",
|
"company",
|
||||||
"bypass_credit_limit_check",
|
|
||||||
"column_break_2",
|
"column_break_2",
|
||||||
"company"
|
"credit_limit",
|
||||||
|
"bypass_credit_limit_check"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
|
"columns": 4,
|
||||||
"fieldname": "credit_limit",
|
"fieldname": "credit_limit",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@ -21,6 +22,7 @@
|
|||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"columns": 4,
|
||||||
"fieldname": "company",
|
"fieldname": "company",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@ -31,11 +33,12 @@
|
|||||||
"default": "0",
|
"default": "0",
|
||||||
"fieldname": "bypass_credit_limit_check",
|
"fieldname": "bypass_credit_limit_check",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Bypass credit limit_check"
|
"label": "Bypass credit limit_check"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2019-08-29 18:27:10.323287",
|
"modified": "2019-08-29 20:46:36.073953",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Customer Credit Limit",
|
"name": "Customer Credit Limit",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user