Rename Tool updates

This commit is contained in:
Ravi Dey 2011-07-01 13:50:34 +05:30
parent c1c54c9400
commit 94a332a8ab
9 changed files with 667 additions and 595 deletions
accounts/doctype/account
crm/doctype/customer
patches
setup/doctype/company
srm/doctype/supplier
tools/doctype/rename_tool

@ -72,6 +72,7 @@ cur_frm.fields_dict['master_name'].get_query=function(doc){
else alert("Please select master type");
}
/*
// Get customer/supplier address
// -----------------------------------------
cur_frm.cscript.master_name = function(doc,cdt,cdn){
@ -79,6 +80,7 @@ cur_frm.cscript.master_name = function(doc,cdt,cdn){
get_server_fields('get_address','','',doc,cdt,cdn);
}
}
*/
// parent account get query
// -----------------------------------------

@ -260,3 +260,16 @@ class DocType:
def on_restore(self):
# rebuild tree
self.update_nsm_model()
# on rename
# ---------
def on_rename(self,newdn,olddn):
company_abbr = sql("select tc.abbr from `tabAccount` ta, `tabCompany` tc where ta.company = tc.name and ta.name=%s", olddn)[0][0]
newdnchk = newdn.split(" - ")
if newdnchk[-1].lower() != company_abbr.lower():
msgprint("Please add company abbreviation <b>%s</b>" %(company_abbr), raise_exception=1)
else:
account_name = " - ".join(newdnchk[:-1])
sql("update `tabAccount` set account_name = '%s' where name = '%s'" %(account_name,olddn))

@ -13,7 +13,6 @@ convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
class DocType:
def __init__(self, doc, doclist=[]):
self.doc = doc
@ -23,7 +22,6 @@ class DocType:
def autoname(self):
cust_master_name = get_defaults().get('cust_master_name')
if cust_master_name == 'Customer Name':
# filter out bad characters in name
#cust = self.doc.customer_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
cust = self.doc.customer_name
@ -35,7 +33,6 @@ class DocType:
raise Exception
else:
self.doc.name = cust
else:
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
@ -164,7 +161,7 @@ class DocType:
#create address and contact from lead
def create_lead_address_contact(self):
if self.doc.lead_name:
details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, contact_no, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1)
details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, phone, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1)
d = Document('Address')
d.address_line1 = details[0]['address_line1']
d.address_line2 = details[0]['address_line2']
@ -174,7 +171,7 @@ class DocType:
d.state = details[0]['state']
d.fax = details[0]['fax']
d.email_id = details[0]['email_id']
d.phone = details[0]['contact_no']
d.phone = details[0]['phone']
d.customer = self.doc.name
d.customer_name = self.doc.customer_name
d.is_primary_address = 1
@ -187,8 +184,8 @@ class DocType:
c = Document('Contact')
c.first_name = details[0]['lead_name']
c.email_id = details[0]['email_id']
c.phone = details[0]['contact_no']
c.phone = details[0]['contact_no']
c.phone = details[0]['phone']
c.mobile_no = details[0]['mobile_no']
c.customer = self.doc.name
c.customer_name = self.doc.customer_name
c.is_primary_contact = 1
@ -228,3 +225,33 @@ class DocType:
self.delete_customer_contact()
if self.doc.lead_name:
sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
# on rename
# ---------
def on_rename(self,newdn,olddn):
#update customer_name if not naming series
if get_defaults().get('cust_master_name') == 'Customer Name':
update_fields = [
('Customer', 'name'),
('Address', 'customer'),
('Contact', 'customer'),
('Customer Issue', 'customer'),
('Delivery Note', 'customer'),
('Enquiry', 'customer'),
('Installation Note', 'customer'),
('Maintenance Schedule', 'customer'),
('Maintenance Visit', 'customer'),
('Project', 'customer'),
('Quotation', 'customer'),
('Receivable Voucher', 'customer'),
('Sales Order', 'customer'),
('Serial No', 'customer'),
('Shipping Address', 'customer'),
('Stock Entry', 'customer'),
('Support Ticket', 'customer'),
('Ticket', 'customer')]
for rec in update_fields:
sql("update `tab%s` set customer_name = '%s' where %s = '%s'" %(rec[0],newdn,rec[1],olddn))
#update master_name in doctype account
sql("update `tabAccount` set master_name = '%s', master_type = 'Customer' where master_name = '%s'" %(newdn,olddn))

@ -1,6 +1,6 @@
# REMEMBER to update this
# ========================
last_patch = 305
last_patch = 306
#-------------------------------------------
@ -1187,9 +1187,9 @@ def execute(patch_no):
reload_doc('payroll', 'doctype', 'salary_structure')
reload_doc('payroll', 'doctype', 'salary_slip')
elif patch_no == 298:
sql("update `tabDocField` set options = 'Link:Company' where parent = 'Attendance' and fieldname = 'company'")
sql("update `tabDocField` set options = 'Link:Company' where parent = 'Expense Voucher' and fieldname = 'company'")
sql("update `tabDocField` set options = 'Link:Company' where parent = 'Appraisal' and fieldname = 'company'")
sql("update `tabDocField` set options = 'link:Company' where parent = 'Attendance' and fieldname = 'company'")
sql("update `tabDocField` set options = 'link:Company' where parent = 'Expense Voucher' and fieldname = 'company'")
sql("update `tabDocField` set options = 'link:Company' where parent = 'Appraisal' and fieldname = 'company'")
elif patch_no == 299:
sql("update `tabDocPerm` set `match` = NULL where parent = 'Employee' and role = 'Employee'")
elif patch_no == 300:
@ -1207,3 +1207,9 @@ def execute(patch_no):
reload_doc('setup', 'doctype', 'company')
elif patch_no == 305:
sql("update `tabDocField` set options = 'link:Company' where options='link:Company' and fieldname='company' and fieldtype='Select'")
elif patch_no == 306:
sql("update `tabDocField` set options = '\nAccount\nCompany\nCustomer\nSupplier\nEmployee\nWarehouse\nItem' where parent = 'Rename Tool' and fieldname = 'select_doctype'")
sql("update `tabDocField` set options = 'link:Item' where parent = 'Raw Materials Supplied' and fieldname = 'po_item'")
sql("update `tabDocField` set options = 'Sales Order' where parent = 'Indent Detail' and fieldname = 'sales_order_no'")
sql("update `tabDocField` set options = 'link:Company', fieldtype = 'Select' where parent = 'Stock Ledger Entry' and fieldname = 'company'")
reload_doc('tools', 'doctype', 'rename_tool')

@ -244,3 +244,8 @@ class DocType:
get_obj('Cost Center', each[0]).on_restore()
msgprint("Company restored. All the accounts and cost centers related to this company also restored.")
# on rename
# ---------
def on_rename(self,newdn,olddn):
sql("update `tabCompany` set company_name = '%s' where name = '%s'" %(newdn,olddn))

@ -1,6 +1,6 @@
[
{
'_last_update': '1309168616',
'_last_update': '1309506817',
'allow_attach': None,
'allow_copy': None,
'allow_email': None,
@ -29,7 +29,7 @@
'istable': None,
'max_attachments': None,
'menu_index': None,
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'module': 'Setup',
'name': 'Company',
@ -53,7 +53,7 @@
'subject': None,
'tag_fields': None,
'use_template': None,
'version': 91
'version': 92
},
{
'amend': 0,
@ -65,7 +65,7 @@
'execute': None,
'idx': 1,
'match': None,
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'PERM00119',
'owner': 'Administrator',
@ -79,8 +79,8 @@
'write': 1
},
{
'amend': 1,
'cancel': 1,
'amend': 0,
'cancel': 0,
'create': 1,
'creation': '2010-08-08 17:08:55',
'docstatus': 0,
@ -88,7 +88,7 @@
'execute': None,
'idx': 2,
'match': None,
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'PERM00120',
'owner': 'Administrator',
@ -103,17 +103,17 @@
},
{
'amend': None,
'cancel': None,
'cancel': 0,
'create': None,
'creation': '2011-06-29 18:02:47',
'creation': '2010-08-08 17:08:55',
'docstatus': 0,
'doctype': 'DocPerm',
'execute': None,
'idx': 3,
'match': None,
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'PERM00859',
'name': 'PERM00121',
'owner': 'Administrator',
'parent': 'Company',
'parentfield': 'permissions',
@ -127,7 +127,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-29 17:48:40',
'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': 'Please Enter Company Name and Abbr and save the document. Once saved Accounting Settings will be populated automatically',
@ -140,9 +140,9 @@
'idx': 1,
'in_filter': None,
'label': 'Details',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL05478',
'name': 'FL05650',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -176,7 +176,7 @@
'idx': 2,
'in_filter': None,
'label': 'Company',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00695',
'no_column': None,
@ -212,7 +212,7 @@
'idx': 3,
'in_filter': None,
'label': 'Abbr',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00696',
'no_column': None,
@ -248,7 +248,7 @@
'idx': 4,
'in_filter': None,
'label': 'Address',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00697',
'no_column': None,
@ -271,7 +271,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-04-19 17:40:13',
'creation': '2011-04-19 18:48:56',
'default': None,
'depends_on': None,
'description': None,
@ -284,9 +284,9 @@
'idx': 5,
'in_filter': None,
'label': 'Default Currency',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': '000003935',
'name': '000031318',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -307,7 +307,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-29 17:48:40',
'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': None,
@ -320,9 +320,9 @@
'idx': 6,
'in_filter': None,
'label': None,
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL05479',
'name': 'FL05651',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -356,7 +356,7 @@
'idx': 7,
'in_filter': None,
'label': 'Phone No',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00699',
'no_column': None,
@ -392,7 +392,7 @@
'idx': 8,
'in_filter': None,
'label': 'Email',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00700',
'no_column': None,
@ -428,7 +428,7 @@
'idx': 9,
'in_filter': None,
'label': 'Fax',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00701',
'no_column': None,
@ -464,7 +464,7 @@
'idx': 10,
'in_filter': None,
'label': 'Website',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00702',
'no_column': None,
@ -487,7 +487,7 @@
{
'allow_on_submit': None,
'colour': 'White:FFF',
'creation': '2011-06-29 17:48:40',
'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': 'Company registration numbers for your reference. Example: VAT Registration Numbers etc.',
@ -500,9 +500,9 @@
'idx': 11,
'in_filter': None,
'label': 'Registration Info',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL05480',
'name': 'FL05652',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -536,7 +536,7 @@
'idx': 12,
'in_filter': None,
'label': 'Registration Details',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00704',
'no_column': None,
@ -559,7 +559,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-29 17:48:40',
'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': 'eval:!doc.__islocal',
'description': None,
@ -572,9 +572,9 @@
'idx': 13,
'in_filter': None,
'label': 'Accounting Settings',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL05481',
'name': 'FL05653',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -608,7 +608,7 @@
'idx': 14,
'in_filter': None,
'label': 'Default Bank Account',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00706',
'no_column': None,
@ -644,7 +644,7 @@
'idx': 15,
'in_filter': None,
'label': 'Receivables Group',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00707',
'no_column': None,
@ -680,7 +680,7 @@
'idx': 16,
'in_filter': None,
'label': 'Payables Group',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00708',
'no_column': None,
@ -703,7 +703,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-29 17:48:40',
'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': None,
@ -716,9 +716,9 @@
'idx': 17,
'in_filter': None,
'label': None,
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL05482',
'name': 'FL05654',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -752,7 +752,7 @@
'idx': 18,
'in_filter': None,
'label': 'If Yearly Budget Exceeded',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00710',
'no_column': None,
@ -788,7 +788,7 @@
'idx': 19,
'in_filter': None,
'label': 'If Monthly Budget Exceeded',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00711',
'no_column': None,
@ -824,7 +824,7 @@
'idx': 20,
'in_filter': None,
'label': 'Credit Days',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00712',
'no_column': None,
@ -860,7 +860,7 @@
'idx': 21,
'in_filter': None,
'label': 'Credit Limit',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00713',
'no_column': None,
@ -896,7 +896,7 @@
'idx': 22,
'in_filter': None,
'label': 'Trash Reason',
'modified': '2011-06-29 18:02:47',
'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00716',
'no_column': None,

@ -16,7 +16,6 @@ convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
class DocType:
def __init__(self, doc, doclist=[]):
self.doc = doc
@ -146,3 +145,23 @@ class DocType:
def on_trash(self):
self.delete_supplier_address()
self.delete_supplier_contact()
# on rename
# ---------
def on_rename(self,newdn,olddn):
#update supplier_name if not naming series
if get_defaults().get('supp_master_name') == 'Supplier Name':
update_fields = [
('Supplier', 'name'),
('Address', 'supplier'),
('Contact', 'supplier'),
('Payable Voucher', 'supplier'),
('Purchase Order', 'supplier'),
('Purchase Receipt', 'supplier'),
('Serial No', 'supplier'),
('Supplier Quotation', 'supplier')]
for rec in update_fields:
sql("update `tab%s` set supplier_name = '%s' where %s = '%s'" %(rec[0],newdn,rec[1],olddn))
#update master_name in doctype account
sql("update `tabAccount` set master_name = '%s', master_type = 'Supplier' where master_name = '%s'" %(newdn,olddn))

@ -12,9 +12,9 @@ class DocType:
# call on_rename method if exists
obj = get_obj(self.doc.select_doctype, self.doc.document_to_rename)
if hasattr(obj, 'on_rename'):
obj.on_rename(self.doc.new_name)
obj.on_rename(self.doc.new_name,self.doc.document_to_rename)
# rename the document
webnotes.model.rename(self.doc.select_doctype, self.doc.document_to_rename, self.doc.new_name)
webnotes.msgprint("Item renamed successfully")
webnotes.msgprint("Successfully renamed "+self.doc.select_doctype+" : '"+self.doc.document_to_rename+"' to <b>"+self.doc.new_name+"</b>")

@ -1,6 +1,6 @@
[
{
'_last_update': '1308739509',
'_last_update': '1309348691',
'allow_attach': None,
'allow_copy': None,
'allow_email': 1,
@ -13,7 +13,7 @@
'client_script_core': None,
'client_string': None,
'colour': 'White:FFF',
'creation': '2011-06-23 11:03:25',
'creation': '2011-06-22 18:42:33',
'description': None,
'docstatus': 0,
'doctype': 'DocType',
@ -29,7 +29,7 @@
'istable': None,
'max_attachments': None,
'menu_index': None,
'modified': '2011-06-23 11:03:25',
'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
'module': 'Tools',
'name': 'Rename Tool',
@ -53,21 +53,21 @@
'subject': None,
'tag_fields': None,
'use_template': None,
'version': 6
'version': 7
},
{
'amend': None,
'cancel': None,
'create': 1,
'creation': '2011-06-23 11:03:25',
'creation': '2011-06-22 18:42:33',
'docstatus': 0,
'doctype': 'DocPerm',
'execute': None,
'idx': 1,
'match': None,
'modified': '2011-06-23 11:03:25',
'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
'name': 'PERM00859',
'name': 'PERM00833',
'owner': 'Administrator',
'parent': 'Rename Tool',
'parentfield': 'permissions',
@ -80,8 +80,8 @@
},
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-23 11:03:25',
'colour': 'White:FFF',
'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@ -94,14 +94,14 @@
'idx': 1,
'in_filter': None,
'label': 'Select DocType',
'modified': '2011-06-23 11:03:25',
'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
'name': 'FL05599',
'name': 'FL05557',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
'oldfieldtype': None,
'options': 'link:DocType',
'options': '\nAccount\nCompany\nCustomer\nSupplier\nEmployee\nWarehouse\nItem',
'owner': 'Administrator',
'parent': 'Rename Tool',
'parentfield': 'fields',
@ -117,7 +117,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-23 11:03:25',
'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@ -130,9 +130,9 @@
'idx': 2,
'in_filter': None,
'label': 'Document to rename',
'modified': '2011-06-23 11:03:25',
'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
'name': 'FL05600',
'name': 'FL05558',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -153,7 +153,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-23 11:03:25',
'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@ -166,9 +166,9 @@
'idx': 3,
'in_filter': None,
'label': 'New Name',
'modified': '2011-06-23 11:03:25',
'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
'name': 'FL05601',
'name': 'FL05559',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@ -189,7 +189,7 @@
{
'allow_on_submit': None,
'colour': None,
'creation': '2011-06-23 11:03:25',
'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@ -202,9 +202,9 @@
'idx': 4,
'in_filter': None,
'label': 'Rename',
'modified': '2011-06-23 11:03:25',
'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
'name': 'FL05602',
'name': 'FL05560',
'no_column': None,
'no_copy': None,
'oldfieldname': None,