deprecated bulk rename tool
This commit is contained in:
parent
76ec66dd65
commit
dbe31be55c
7
erpnext/patches/july_2012/deprecate_bulk_rename.py
Normal file
7
erpnext/patches/july_2012/deprecate_bulk_rename.py
Normal file
@ -0,0 +1,7 @@
|
||||
def execute():
|
||||
import webnotes
|
||||
from webnotes.model import delete_doc
|
||||
delete_doc('DocType', 'Bulk Rename Tool')
|
||||
webnotes.conn.commit()
|
||||
webnotes.conn.sql("drop table `tabBulk Rename Tool`")
|
||||
webnotes.conn.begin()
|
@ -506,4 +506,9 @@ patch_list = [
|
||||
'patch_file': 'remove_event_role_owner_match',
|
||||
'description': "Remove Owner match from Event DocType's Permissions"
|
||||
},
|
||||
{
|
||||
'patch_module': 'patches.july_2012',
|
||||
'patch_file': 'deprecate_bulk_rename',
|
||||
'description': "Remove Bulk Rename Tool"
|
||||
},
|
||||
]
|
@ -49,10 +49,6 @@
|
||||
<b><a href="#!Form/Rename Tool/Rename Tool">Rename Master</a></b><br>
|
||||
<span class="help">Rename a single master record</span>
|
||||
</p>
|
||||
<p>
|
||||
<b><a href="#!List/Bulk Rename Tool">Rename Many</a></b><br>
|
||||
<span class="help">Rename by uploading a csv file</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="setup-column">
|
||||
<h3>Email and Notifications</h3>
|
||||
|
@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
@ -1,100 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Please edit this list and import only required elements
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
|
||||
from webnotes.model import db_exists
|
||||
from webnotes.model.doc import Document, addchild, getchildren, make_autoname
|
||||
from webnotes.model.doclist import getlist, copy_doclist
|
||||
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
|
||||
from webnotes import session, form, is_testing, msgprint, errprint
|
||||
|
||||
set = webnotes.conn.set
|
||||
sql = webnotes.conn.sql
|
||||
get_value = webnotes.conn.get_value
|
||||
in_transaction = webnotes.conn.in_transaction
|
||||
convert_to_lists = webnotes.conn.convert_to_lists
|
||||
|
||||
# -----------------------------------------------------------------------------------------
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
# bulk rename
|
||||
def do_rename(self):
|
||||
import csv
|
||||
data = csv.reader(self.get_csv_data().splitlines())
|
||||
|
||||
updated = 0
|
||||
|
||||
msgprint(self.doc.rename_doctype)
|
||||
|
||||
if self.doc.rename_doctype == 'Account':
|
||||
for line in data:
|
||||
if len(line)==2:
|
||||
rec = sql("select tc.abbr, ta.name from `tabAccount` ta, `tabCompany` tc where ta.company = tc.name and ta.account_name = %s", line[0], as_dict=1)
|
||||
if rec:
|
||||
new_name = line[1] + ' - ' + rec[0]['abbr']
|
||||
|
||||
webnotes.conn.begin()
|
||||
webnotes.model.rename(self.doc.rename_doctype, rec[0]['name'], new_name)
|
||||
sql("update `tabAccount` set account_name = '%s' where name = '%s'" %(line[1],new_name))
|
||||
webnotes.conn.commit()
|
||||
|
||||
updated += 1
|
||||
else:
|
||||
msgprint("[Ignored] Incorrect format: %s" % str(line))
|
||||
else:
|
||||
for line in data:
|
||||
if len(line)==2:
|
||||
|
||||
webnotes.conn.begin()
|
||||
|
||||
obj = get_obj(self.doc.rename_doctype, line[0])
|
||||
if hasattr(obj, 'on_rename'):
|
||||
obj.on_rename(line[1],line[0])
|
||||
|
||||
webnotes.model.rename(self.doc.rename_doctype, line[0], line[1])
|
||||
|
||||
webnotes.conn.commit()
|
||||
|
||||
updated += 1
|
||||
else:
|
||||
msgprint("[Ignored] Incorrect format: %s" % str(line))
|
||||
|
||||
|
||||
msgprint("<b>%s</b> items updated" % updated)
|
||||
|
||||
# Update CSV data
|
||||
def get_csv_data(self):
|
||||
if not self.doc.file_list:
|
||||
msgprint("File not attached!")
|
||||
raise Exception
|
||||
|
||||
fid = self.doc.file_list.split(',')[1]
|
||||
|
||||
from webnotes.utils import file_manager
|
||||
fn, content = file_manager.get_file(fid)
|
||||
|
||||
# NOTE: Don't know why this condition exists
|
||||
if not isinstance(content, basestring) and hasattr(content, 'tostring'):
|
||||
content = content.tostring()
|
||||
|
||||
return content
|
@ -1,126 +0,0 @@
|
||||
# DocType, Bulk Rename Tool
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-03-27 14:36:46',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-03-27 14:45:46',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all DocType
|
||||
{
|
||||
'_last_update': u'1322549701',
|
||||
'allow_attach': 1,
|
||||
'autoname': u'field:rename_doctype',
|
||||
'colour': u'White:FFF',
|
||||
'default_print_format': u'Standard',
|
||||
'doctype': 'DocType',
|
||||
'is_submittable': 1,
|
||||
'module': u'Utilities',
|
||||
'name': '__common__',
|
||||
'section_style': u'Simple',
|
||||
'show_in_menu': 0,
|
||||
'version': 8
|
||||
},
|
||||
|
||||
# These values are common for all DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'name': '__common__',
|
||||
'parent': u'Bulk Rename Tool',
|
||||
'parentfield': u'fields',
|
||||
'parenttype': u'DocType'
|
||||
},
|
||||
|
||||
# These values are common for all DocPerm
|
||||
{
|
||||
'doctype': u'DocPerm',
|
||||
'name': '__common__',
|
||||
'parent': u'Bulk Rename Tool',
|
||||
'parentfield': u'permissions',
|
||||
'parenttype': u'DocType',
|
||||
'read': 1,
|
||||
'role': u'System Manager'
|
||||
},
|
||||
|
||||
# DocType, Bulk Rename Tool
|
||||
{
|
||||
'doctype': 'DocType',
|
||||
'name': u'Bulk Rename Tool'
|
||||
},
|
||||
|
||||
# DocPerm
|
||||
{
|
||||
'create': 1,
|
||||
'doctype': u'DocPerm',
|
||||
'permlevel': 0,
|
||||
'submit': 1,
|
||||
'write': 1
|
||||
},
|
||||
|
||||
# DocPerm
|
||||
{
|
||||
'doctype': u'DocPerm',
|
||||
'permlevel': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'rename_doctype',
|
||||
'fieldtype': u'Data',
|
||||
'label': u'Rename DocType',
|
||||
'options': u'Suggest',
|
||||
'permlevel': 0,
|
||||
'reqd': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'file_list',
|
||||
'fieldtype': u'Text',
|
||||
'hidden': 1,
|
||||
'label': u'File List',
|
||||
'no_copy': 1,
|
||||
'permlevel': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'rename',
|
||||
'fieldtype': u'Button',
|
||||
'label': u'Rename',
|
||||
'options': u'do_rename',
|
||||
'permlevel': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'depends_on': u'eval:doc.amended_from',
|
||||
'description': u'The date at which current entry is corrected in the system.',
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'amendment_date',
|
||||
'fieldtype': u'Date',
|
||||
'label': u'Amendment Date',
|
||||
'no_copy': 1,
|
||||
'permlevel': 0,
|
||||
'print_hide': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'amended_from',
|
||||
'fieldtype': u'Link',
|
||||
'label': u'Amended From',
|
||||
'no_copy': 1,
|
||||
'options': u'Sales Invoice',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user