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