From 4810d1fa2d1d8cbc02de93d958dd73c77493a843 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 21 Nov 2016 16:52:50 +0530 Subject: [PATCH] patch for rename autoname field --- erpnext/patches.txt | 1 + erpnext/patches/v7_0/update_autoname_field.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 erpnext/patches/v7_0/update_autoname_field.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5f8531d1a3..30e8e038f7 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -349,3 +349,4 @@ erpnext.patches.v7_0.set_base_amount_in_invoice_payment_table erpnext.patches.v7_1.update_invoice_status erpnext.patches.v7_0.po_status_issue_for_pr_return erpnext.patches.v7_1.update_missing_salary_component_type +erpnext.patches.v7_0.update_autoname_field \ No newline at end of file diff --git a/erpnext/patches/v7_0/update_autoname_field.py b/erpnext/patches/v7_0/update_autoname_field.py new file mode 100644 index 0000000000..bfa9b281df --- /dev/null +++ b/erpnext/patches/v7_0/update_autoname_field.py @@ -0,0 +1,14 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + doctypes = frappe.db.sql(""" select name, autoname from `tabDocType` + where autoname like 'field:%' and allow_rename = 1""", as_dict=1) + + for doctype in doctypes: + fieldname = doctype.autoname.split(":")[1] + if fieldname: + frappe.db.sql(""" update `tab%s` set %s = name """%(doctype.name, fieldname)) \ No newline at end of file