test: create customer credit limit on change
diff --git a/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py b/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py
index 6f59b46..ca01c60 100644
--- a/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py
+++ b/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py
@@ -29,7 +29,7 @@
 	companies = frappe.get_all("Company", 'name')
 
 	for record in credit_limit_record:
-		customer = frappe.get_doc("Customer", customer.name)
+		customer = frappe.get_doc("Customer", record.name)
 		for company in companies:
 			customer.append("credit_limit_reference", {
 				'credit_limit': record.credit_limit,
diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py
index e5771b2..35d1b2c 100644
--- a/erpnext/selling/doctype/customer/test_customer.py
+++ b/erpnext/selling/doctype/customer/test_customer.py
@@ -252,7 +252,10 @@
 	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_reference[0].credit_limit = flt(outstanding_amt - 100)
+		customer.append('credit_limit_reference', {'credit_limit': flt(outstanding_amt - 100), 'company': '_Test Company'})
+
+		''' define new credit limit for same company '''
+		customer.append('credit_limit_reference', {'credit_limit': flt(outstanding_amt - 100), 'company': '_Test Company'})
 		self.assertRaises(frappe.ValidationError, customer.save)
 
 	def test_customer_payment_terms(self):