patch after doctype.py refactor
This commit is contained in:
parent
0493897297
commit
4b7ddff4c9
0
erpnext/patches/mar_2012/__init__.py
Normal file
0
erpnext/patches/mar_2012/__init__.py
Normal file
147
erpnext/patches/mar_2012/doctype_get_refactor.py
Normal file
147
erpnext/patches/mar_2012/doctype_get_refactor.py
Normal file
@ -0,0 +1,147 @@
|
||||
import webnotes
|
||||
def execute():
|
||||
"""
|
||||
* Custom Field changes
|
||||
* Add file_list to required tables
|
||||
* Change floats/currency to decimal(14, 6)
|
||||
* Remove DocFormat from DocType's fields
|
||||
* Remove 'no_column' from DocField
|
||||
* Drop table DocFormat
|
||||
"""
|
||||
handle_custom_fields()
|
||||
create_file_list()
|
||||
|
||||
# do at last - needs commit due to DDL statements
|
||||
change_to_decimal()
|
||||
|
||||
def handle_custom_fields():
|
||||
"""
|
||||
* Assign idx to custom fields
|
||||
* Create property setter entry of previous field
|
||||
* Remove custom fields from tabDocField
|
||||
"""
|
||||
cf = get_cf()
|
||||
assign_idx(cf)
|
||||
create_prev_field_prop_setter(cf)
|
||||
remove_custom_from_docfield(cf)
|
||||
|
||||
def get_cf():
|
||||
return webnotes.conn.sql("""\
|
||||
SELECT * FROM `tabCustom Field`
|
||||
WHERE docstatus < 2""", as_dict=1)
|
||||
|
||||
def assign_idx(cf):
|
||||
from webnotes.model.doctype import get
|
||||
from webnotes.utils import cint
|
||||
for f in cf:
|
||||
if f.get('idx'): continue
|
||||
temp_doclist = get(f.get('dt'), form=0)
|
||||
max_idx = max(d.idx for d in temp_doclist if d.doctype=='DocField')
|
||||
if not max_idx: continue
|
||||
webnotes.conn.sql("""\
|
||||
UPDATE `tabCustom Field` SET idx=%s
|
||||
WHERE name=%s""", (cint(max_idx)+1, f.get('name')))
|
||||
|
||||
def create_prev_field_prop_setter(cf):
|
||||
from webnotes.model.doc import Document
|
||||
from core.doctype.custom_field.custom_field import get_fields_label
|
||||
for f in cf:
|
||||
idx_label_list, field_list = get_fields_label(f.get('dt'), 0)
|
||||
temp_insert_after = (f.get('insert_after') or '').split(" - ")
|
||||
if len(temp_insert_after)<=1: continue
|
||||
similar_idx_label = [il for il in idx_label_list \
|
||||
if temp_insert_after[0] in il]
|
||||
if not similar_idx_label: continue
|
||||
label_index = idx_label_list.index(similar_idx_label[0])
|
||||
if label_index==-1: return
|
||||
|
||||
webnotes.conn.sql("""\
|
||||
UPDATE `tabCustom Field`
|
||||
SET insert_after = %s
|
||||
WHERE name = %s""", (similar_idx_label[0], f.get('name')))
|
||||
|
||||
prev_field = field_list[label_index]
|
||||
webnotes.conn.sql("""\
|
||||
DELETE FROM `tabProperty Setter`
|
||||
WHERE doc_type = %s
|
||||
AND doc_name = %s
|
||||
AND property = 'previous_field'""", (f.get('dt'), f.get('name')))
|
||||
ps = Document('Property Setter', fielddata = {
|
||||
'doctype_or_field': 'DocField',
|
||||
'doc_type': f.get('dt'),
|
||||
'doc_name': f.get('name'),
|
||||
'property': 'previous_field',
|
||||
'value': prev_field,
|
||||
'property_type': 'Data',
|
||||
'select_doctype': f.get('dt')
|
||||
})
|
||||
ps.save(1)
|
||||
|
||||
def remove_custom_from_docfield(cf):
|
||||
for f in cf:
|
||||
webnotes.conn.sql("""\
|
||||
DELETE FROM `tabDocField`
|
||||
WHERE parent=%s AND fieldname=%s""", (f.get('dt'),
|
||||
f.get('fieldname')))
|
||||
|
||||
def create_file_list():
|
||||
tables = webnotes.conn.sql("SHOW TABLES")
|
||||
exists = []
|
||||
for tab in tables:
|
||||
if not tab: continue
|
||||
desc = webnotes.conn.sql("DESC `%s`" % tab[0], as_dict=1)
|
||||
|
||||
for d in desc:
|
||||
if d.get('Field')=='file_list':
|
||||
exists.append(tab[0])
|
||||
break
|
||||
|
||||
print exists
|
||||
|
||||
should_exist = ['Website Settings', 'Web Page', 'Timesheet', 'Ticket',
|
||||
'Support Ticket', 'Supplier', 'Style Settings', 'Stock Reconciliation',
|
||||
'Stock Entry', 'Serial No', 'Sales Order', 'Receivable Voucher',
|
||||
'Quotation', 'Question', 'Purchase Receipt', 'Purchase Order',
|
||||
'Project', 'Profile', 'Production Order', 'Product', 'Print Format',
|
||||
'Price List', 'Payable Voucher', 'Page', 'Module Def',
|
||||
'Maintenance Visit', 'Maintenance Schedule', 'Letter Head',
|
||||
'Leave Application', 'Lead', 'Journal Voucher', 'Item', 'Indent',
|
||||
'Expense Voucher', 'Enquiry', 'Employee', 'Delivery Note',
|
||||
'Customer Issue', 'Customer', 'Contact Us Settings', 'Company',
|
||||
'Bulk Rename Tool', 'Blog', 'Bill Of Materials', 'About Us Settings']
|
||||
|
||||
from webnotes.model.code import get_obj
|
||||
|
||||
for dt in should_exist:
|
||||
if dt in exists: continue
|
||||
obj = get_obj('DocType', dt, with_children=1)
|
||||
obj.doc.allow_attach = 1
|
||||
obj.doc.save()
|
||||
obj.make_file_list()
|
||||
obj.on_update()
|
||||
|
||||
|
||||
def change_to_decimal():
|
||||
webnotes.conn.commit()
|
||||
tables = webnotes.conn.sql("SHOW TABLES")
|
||||
alter_tables_list = []
|
||||
for tab in tables:
|
||||
if not tab: continue
|
||||
desc = webnotes.conn.sql("DESC `%s`" % tab[0], as_dict=1)
|
||||
flist = []
|
||||
for d in desc:
|
||||
if d.get('Type')=='decimal(14,2)':
|
||||
flist.append(d.get('Field'))
|
||||
if flist:
|
||||
#print tab[0], flist
|
||||
statements = ("MODIFY `%s` decimal(14,6)" % f for f in flist)
|
||||
statements = ", \n".join(statements)
|
||||
alter_tables_list.append("ALTER TABLE `%s` \n%s\n" % (tab[0],
|
||||
statements))
|
||||
|
||||
#print "\n\n".join(alter_tables_list)
|
||||
for at in alter_tables_list:
|
||||
webnotes.conn.sql(at)
|
||||
|
||||
webnotes.conn.begin()
|
||||
|
@ -2229,15 +2229,8 @@ else if(nm=='Accounts Browser')
|
||||
pscript.make_chart(chart_type);}
|
||||
loadpage(nm,call_back);}
|
||||
var update_messages=function(reset){if(inList(['Guest'],user)){return;}
|
||||
<<<<<<< HEAD
|
||||
if(!reset){$c_page('home','event_updates','get_global_status_messages',null,function(r,rt){if(!r.exc){page_body.wntoolbar.set_new_comments(r.message.unread_messages);var messages_circle=$('#unread_msg_count')
|
||||
if(messages_circle){if(r.message.unread_messages.length){messages_circle.find('span:first').text(r.message.unread_messages.length);messages_circle.toggle(true);}else{messages_circle.toggle(false);}}
|
||||
var support_circle=$('#open_support_ticket_count')
|
||||
if(support_circle){if(r.message.open_support_tickets){support_circle.find('span:first').text(r.message.open_support_tickets);support_circle.toggle(true);}else{support_circle.toggle(false);}}}else{clearInterval(wn.updates.id);}});}else{page_body.wntoolbar.set_new_comments(0);$('#msg_count').toggle(false);}}
|
||||
=======
|
||||
if(!reset){$c_page('home','event_updates','get_global_status_messages',null,function(r,rt){if(!r.exc){page_body.wntoolbar.set_new_comments(r.message.unread_messages);var show_in_circle=function(parent_id,msg){var parent=$('#'+parent_id);if(parent){if(msg){parent.find('span:first').text(msg);parent.toggle(true);}else{parent.toggle(false);}}}
|
||||
show_in_circle('unread_messages',r.message.unread_messages.length);show_in_circle('open_support_tickets',r.message.open_support_tickets);show_in_circle('things_todo',r.message.things_todo);show_in_circle('todays_events',r.message.todays_events);}else{clearInterval(wn.updates.id);}});}else{page_body.wntoolbar.set_new_comments(0);$('#unread_messages').toggle(false);}}
|
||||
>>>>>>> master
|
||||
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
|
||||
wn.updates.id=setInterval(update_messages,60000);}
|
||||
erpnext.set_user_background=function(src){set_style(repl('body { background: url("files/%(src)s") repeat;}',{src:src}))}
|
||||
|
@ -1077,15 +1077,8 @@ else if(nm=='Accounts Browser')
|
||||
pscript.make_chart(chart_type);}
|
||||
loadpage(nm,call_back);}
|
||||
var update_messages=function(reset){if(inList(['Guest'],user)){return;}
|
||||
<<<<<<< HEAD
|
||||
if(!reset){$c_page('home','event_updates','get_global_status_messages',null,function(r,rt){if(!r.exc){page_body.wntoolbar.set_new_comments(r.message.unread_messages);var messages_circle=$('#unread_msg_count')
|
||||
if(messages_circle){if(r.message.unread_messages.length){messages_circle.find('span:first').text(r.message.unread_messages.length);messages_circle.toggle(true);}else{messages_circle.toggle(false);}}
|
||||
var support_circle=$('#open_support_ticket_count')
|
||||
if(support_circle){if(r.message.open_support_tickets){support_circle.find('span:first').text(r.message.open_support_tickets);support_circle.toggle(true);}else{support_circle.toggle(false);}}}else{clearInterval(wn.updates.id);}});}else{page_body.wntoolbar.set_new_comments(0);$('#msg_count').toggle(false);}}
|
||||
=======
|
||||
if(!reset){$c_page('home','event_updates','get_global_status_messages',null,function(r,rt){if(!r.exc){page_body.wntoolbar.set_new_comments(r.message.unread_messages);var show_in_circle=function(parent_id,msg){var parent=$('#'+parent_id);if(parent){if(msg){parent.find('span:first').text(msg);parent.toggle(true);}else{parent.toggle(false);}}}
|
||||
show_in_circle('unread_messages',r.message.unread_messages.length);show_in_circle('open_support_tickets',r.message.open_support_tickets);show_in_circle('things_todo',r.message.things_todo);show_in_circle('todays_events',r.message.todays_events);}else{clearInterval(wn.updates.id);}});}else{page_body.wntoolbar.set_new_comments(0);$('#unread_messages').toggle(false);}}
|
||||
>>>>>>> master
|
||||
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
|
||||
wn.updates.id=setInterval(update_messages,60000);}
|
||||
erpnext.set_user_background=function(src){set_style(repl('body { background: url("files/%(src)s") repeat;}',{src:src}))}
|
||||
|
@ -1 +1 @@
|
||||
959
|
||||
964
|
Loading…
x
Reference in New Issue
Block a user