patch: move credit limit in customer to child table
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 07b8ee6..2af1269 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -632,3 +632,4 @@
 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
\ No newline at end of file
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
new file mode 100644
index 0000000..510d79f
--- /dev/null
+++ b/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2019, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	''' Move credit limit and bypass credit limit to the child table of customer credit limit '''
+	frappe.reload_doc("Selling", "doctype", "Customer Credit Limit")
+	frappe.reload_doc("Selling", "doctype", "Customer")
+
+	if frappe.db.a_row_exists("Customer Credit Limit"):
+		return
+
+	move_credit_limit_to_child_table()
+
+def move_credit_limit_to_child_table():
+	''' maps data from old field to the new field in the child table '''
+
+	credit_limit_data = frappe.db.sql(''' SELECT
+		name, credit_limit,
+		bypass_credit_limit_check_against_sales_order
+		FROM `tabCustomer`''', as_dict=1)
+
+	default_company = frappe.db.get_single_value("Global Defaults", "default_company")
+
+	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
+		})
+		customer.save()
\ No newline at end of file