fix: multiple fixes
This commit is contained in:
parent
dcd5be0d07
commit
b3e5d11e1d
@ -632,4 +632,4 @@ execute:frappe.reload_doc('desk', 'doctype','dashboard_chart')
|
||||
erpnext.patches.v12_0.add_default_dashboards
|
||||
erpnext.patches.v12_0.remove_bank_remittance_custom_fields
|
||||
erpnext.patches.v12_0.generate_leave_ledger_entries
|
||||
erpnext.patches.v12_0.move_credit_limit_to_customer_credit_limit
|
||||
erpnext.patches.v12_0.move_credit_limit_to_customer_credit_limit #
|
@ -19,16 +19,17 @@ def move_credit_limit_to_child_table():
|
||||
|
||||
credit_limit_data = frappe.db.sql(''' SELECT
|
||||
name, credit_limit,
|
||||
bypass_credit_limit_check_against_sales_order
|
||||
bypass_credit_limit_check_at_sales_order
|
||||
FROM `tabCustomer`''', as_dict=1)
|
||||
|
||||
default_company = frappe.db.get_single_value("Global Defaults", "default_company")
|
||||
companies = frappe.get_all("Company", 'name')
|
||||
|
||||
for customer in credit_limit_data:
|
||||
customer = frappe.get_doc("Customer", customer.name)
|
||||
customer.append("credit_limit", {
|
||||
'credit_limit': customer.credit_limit,
|
||||
'bypass_credit_limit_check': customer.bypass_credit_limit_check_against_sales_order,
|
||||
'company': default_company
|
||||
})
|
||||
for company in companies:
|
||||
customer.append("credit_limit_reference", {
|
||||
'credit_limit': customer.credit_limit,
|
||||
'bypass_credit_limit_check': customer.bypass_credit_limit_check_at_sales_order,
|
||||
'company': company.name
|
||||
})
|
||||
customer.save()
|
@ -50,7 +50,7 @@
|
||||
"accounts",
|
||||
"credit_limit_section",
|
||||
"payment_terms",
|
||||
"credit_limit",
|
||||
"credit_limit_reference",
|
||||
"more_info",
|
||||
"customer_details",
|
||||
"column_break_45",
|
||||
@ -344,13 +344,6 @@
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Credit Limit and Payment Terms"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "credit_limit",
|
||||
"fieldtype": "Table",
|
||||
"label": "Credit Limit",
|
||||
"options": "Customer Credit Limit"
|
||||
},
|
||||
{
|
||||
"fieldname": "payment_terms",
|
||||
"fieldtype": "Link",
|
||||
@ -464,12 +457,19 @@
|
||||
"print_hide": 1,
|
||||
"read_only": 1,
|
||||
"report_hide": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "credit_limit_reference",
|
||||
"fieldtype": "Table",
|
||||
"label": "Credit Limit",
|
||||
"options": "Customer Credit Limit"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-user",
|
||||
"idx": 363,
|
||||
"image_field": "image",
|
||||
"modified": "2019-08-28 17:38:09.709688",
|
||||
"modified": "2019-08-30 18:03:13.332934",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "Customer",
|
||||
@ -550,6 +550,7 @@
|
||||
"quick_entry": 1,
|
||||
"search_fields": "customer_name,customer_group,territory, mobile_no,primary_address",
|
||||
"show_name_in_global_search": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "ASC",
|
||||
"title_field": "customer_name",
|
||||
"track_changes": 1
|
||||
|
@ -167,11 +167,17 @@ class Customer(TransactionBase):
|
||||
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):
|
||||
if self.get("__islocal") or not self.credit_limit:
|
||||
if self.get("__islocal") or not self.credit_limit_reference:
|
||||
return
|
||||
|
||||
company_record = [c.company for c in self.credit_limit_reference]
|
||||
|
||||
for limit in frappe.get_all("Customer Credit Limit", {'parent': self.name}, ["credit_limit", "company"]):
|
||||
outstanding_amt = get_customer_outstanding(self.name, limit.company)
|
||||
company_record.append(limit.company)
|
||||
if company_record.count(limit.company) >2:
|
||||
frappe.throw(_("Credit limit is already defined for the Company {0}").format(limit.company, self.name))
|
||||
|
||||
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))
|
||||
|
||||
@ -322,14 +328,18 @@ def get_credit_limit(customer, company):
|
||||
|
||||
if customer:
|
||||
credit_record = frappe.db.sql("""SELECT
|
||||
customer_group,
|
||||
credit_limit
|
||||
c.customer_group,
|
||||
ccl.credit_limit
|
||||
FROM `tabCustomer`c , `tabCustomer Credit Limit` ccl
|
||||
WHERE
|
||||
c.name = ccl.parent
|
||||
""", as_dict=1)
|
||||
c.name = %s
|
||||
AND c.name = ccl.parent
|
||||
AND ccl.company = %s
|
||||
""", (customer, company), as_dict=1)
|
||||
|
||||
if not credit_record.credit_limit:
|
||||
credit_limit = credit_record.credit_limit
|
||||
|
||||
if not credit_limit:
|
||||
credit_limit = frappe.get_cached_value("Customer Group", credit_record.customer_group, "credit_limit")
|
||||
|
||||
if not credit_limit:
|
||||
|
@ -25,7 +25,7 @@ class TestCustomer(unittest.TestCase):
|
||||
make_test_records('Item')
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', 0.0)
|
||||
frappe.db.set_value("Customer", {'parent': '_Test Customer', 'company': '_Test Company'}, 'credit_limit', 0.0)
|
||||
|
||||
def test_party_details(self):
|
||||
from erpnext.accounts.party import get_party_details
|
||||
@ -226,7 +226,7 @@ class TestCustomer(unittest.TestCase):
|
||||
make_sales_order(qty=item_qty)
|
||||
|
||||
if credit_limit == 0.0:
|
||||
frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', outstanding_amt - 50.0)
|
||||
frappe.db.set_value("Customer", {'parent': '_Test Customer', 'company': '_Test Company'}, 'credit_limit', outstanding_amt - 50.0)
|
||||
|
||||
# Sales Order
|
||||
so = make_sales_order(do_not_submit=True)
|
||||
@ -241,7 +241,7 @@ class TestCustomer(unittest.TestCase):
|
||||
self.assertRaises(frappe.ValidationError, si.submit)
|
||||
|
||||
if credit_limit > outstanding_amt:
|
||||
frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', credit_limit)
|
||||
frappe.db.set_value("Customer", {'parent': '_Test Customer', 'company': '_Test Company'}, 'credit_limit', credit_limit)
|
||||
|
||||
# Makes Sales invoice from Sales Order
|
||||
so.save(ignore_permissions=True)
|
||||
@ -252,7 +252,7 @@ class TestCustomer(unittest.TestCase):
|
||||
def test_customer_credit_limit_on_change(self):
|
||||
outstanding_amt = self.get_customer_outstanding_amount()
|
||||
customer = frappe.get_doc("Customer", '_Test Customer')
|
||||
customer.credit_limit = flt(outstanding_amt - 100)
|
||||
customer.credit_limit_reference['credit_limit'] = flt(outstanding_amt - 100)
|
||||
self.assertRaises(frappe.ValidationError, customer.save)
|
||||
|
||||
def test_customer_payment_terms(self):
|
||||
|
@ -10,8 +10,9 @@ QUnit.test("test_sales_order_with_bypass_credit_limit_check", function(assert) {
|
||||
() => frappe.quick_entry.dialog.$wrapper.find('.edit-full').click(),
|
||||
() => frappe.timeout(1),
|
||||
() => cur_frm.set_value("customer_name", "Test Customer 10"),
|
||||
() => cur_frm.set_value("credit_limit", 100.00),
|
||||
() => cur_frm.set_value("bypass_credit_limit_check_at_sales_order", 1),
|
||||
() => cur_frm.add_child('credit_limit_reference', {
|
||||
'credit_limit': 1000,
|
||||
'bypass_credit_limit_check': 1}),
|
||||
// save form
|
||||
() => cur_frm.save(),
|
||||
() => frappe.timeout(1),
|
||||
|
@ -10,8 +10,10 @@ QUnit.test("test_sales_order_without_bypass_credit_limit_check", function(assert
|
||||
() => frappe.quick_entry.dialog.$wrapper.find('.edit-full').click(),
|
||||
() => frappe.timeout(1),
|
||||
() => cur_frm.set_value("customer_name", "Test Customer 11"),
|
||||
() => cur_frm.set_value("credit_limit", 100.00),
|
||||
() => cur_frm.set_value("bypass_credit_limit_check_at_sales_order", 0),
|
||||
() => cur_frm.add_child('credit_limit_reference', {
|
||||
'credit_limit': 1000,
|
||||
'company': '_Test Company',
|
||||
'bypass_credit_limit_check': 1}),
|
||||
// save form
|
||||
() => cur_frm.save(),
|
||||
() => frappe.timeout(1),
|
||||
|
Loading…
x
Reference in New Issue
Block a user