From dcd5be0d07cefc317b35124dd7ea6112645a68d4 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 29 Aug 2019 20:53:51 +0530 Subject: [PATCH] patch: move credit limit in customer to child table --- erpnext/patches.txt | 1 + ...e_credit_limit_to_customer_credit_limit.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 07b8ee6ab4..2af12698c5 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -632,3 +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 \ 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 0000000000..510d79f23d --- /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