moved directory structure

This commit is contained in:
Rushabh Mehta
2012-09-24 19:13:42 +05:30
parent e47a6779e9
commit 2fa2f7178d
1637 changed files with 47 additions and 11450 deletions

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,43 @@
# do not run this patch
from __future__ import unicode_literals
def execute():
import webnotes
import webnotes.modules
forbidden = ['%', "'", '"', '#', '*', '?', '`', '(', ')', '<', '>', '-',
'\\', '/', '.', '&', '!', '@', '$', '^', '+']
doctype_list = webnotes.conn.sql("SELECT name, module FROM `tabDocType`")
for doctype, module in doctype_list:
docfield_list = webnotes.conn.sql("""\
SELECT name, label, fieldtype FROM `tabDocField`
WHERE parent = %s AND IFNULL(fieldname, '') = ''""", doctype)
field_type_count = {}
count = 0
for name, label, fieldtype in docfield_list:
fieldname = None
if label:
temp_label = label
if len(temp_label)==1:
temp_label = fieldtype + temp_label
fieldname = temp_label.lower().replace(' ', '_')
if "<" in fieldname:
count = field_type_count.setdefault(fieldtype, 0)
fieldname = fieldtype.lower().replace(' ', '_') + str(count)
field_type_count[fieldtype] = count + 1
elif fieldtype:
count = field_type_count.setdefault(fieldtype, 0)
fieldname = fieldtype.lower().replace(' ', '_') + str(count)
field_type_count[fieldtype] = count + 1
if fieldname:
for f in forbidden: fieldname = fieldname.replace(f, '')
fieldname = fieldname.replace('__', '_')
if fieldname.endswith('_'):
fieldname = fieldname[:-1]
if fieldname.startswith('_'):
fieldname = fieldname[1:]
#print fieldname
webnotes.conn.sql("""\
UPDATE `tabDocField` SET fieldname = %s
WHERE name = %s""", (fieldname, name))
webnotes.modules.export_doc('DocType', doctype)

View File

@@ -0,0 +1,79 @@
from __future__ import unicode_literals
import webnotes
def execute():
"""
* Remove unnecessary doctype properties
* Remove docfield property setters if fieldname doesn't exist
* Remove prev_field properties if value fieldname doesn't exist
"""
change_property_setter_fieldnames()
clean_doctype_properties()
clean_docfield_properties()
def change_property_setter_fieldnames():
import webnotes.model.sync
webnotes.model.sync.sync('core', 'property_setter')
docfield_list = webnotes.conn.sql("""\
SELECT name, fieldname FROM `tabDocField`""", as_list=1)
custom_field_list = webnotes.conn.sql("""\
SELECT name, fieldname FROM `tabCustom Field`""", as_list=1)
field_list = docfield_list + custom_field_list
property_setter_list = webnotes.conn.sql("""\
SELECT name, doc_name, value, property
FROM `tabProperty Setter`
WHERE doctype_or_field='DocField'""")
field_dict = dict(field_list)
for name, doc_name, value, prop in property_setter_list:
if doc_name in field_dict:
webnotes.conn.sql("""\
UPDATE `tabProperty Setter`
SET field_name = %s
WHERE name = %s""", (field_dict.get(doc_name), name))
if value in field_dict and prop=='previous_field':
webnotes.conn.sql("""\
UPDATE `tabProperty Setter`
SET value = %s
WHERE name = %s""", (field_dict.get(value), name))
def clean_doctype_properties():
desc = webnotes.conn.sql("DESC `tabDocType`", as_dict=1)
property_list = '", "'.join([d.get('Field') for d in desc])
webnotes.conn.sql("""\
DELETE FROM `tabProperty Setter`
WHERE doctype_or_field = 'DocType'
AND property NOT IN ("%s")""" % property_list)
def clean_docfield_properties():
delete_list_1 = webnotes.conn.sql("""\
SELECT name FROM `tabProperty Setter` ps
WHERE doctype_or_field = 'DocField'
AND NOT EXISTS (
SELECT fieldname FROM `tabDocField` df
WHERE df.parent = ps.doc_type
AND df.fieldname = ps.field_name
) AND NOT EXISTS (
SELECT fieldname FROM `tabCustom Field` cf
WHERE cf.dt = ps.doc_type
AND cf.fieldname = ps.field_name
)""")
delete_list_2 = webnotes.conn.sql("""\
SELECT name FROM `tabProperty Setter` ps
WHERE doctype_or_field = 'DocField'
AND property = 'previous_field'
AND NOT EXISTS (
SELECT fieldname FROM `tabDocField` df
WHERE df.parent = ps.doc_type
AND df.fieldname = ps.value
) AND NOT EXISTS (
SELECT fieldname FROM `tabCustom Field` cf
WHERE cf.dt = ps.doc_type
AND cf.fieldname = ps.value
)""")
delete_list = [d[0] for d in delete_list_1] + [d[0] for d in delete_list_2]
webnotes.conn.sql("""\
DELETE FROM `tabProperty Setter`
WHERE NAME IN ("%s")""" % '", "'.join(delete_list))

View File

@@ -0,0 +1,8 @@
from __future__ import unicode_literals
import webnotes
def execute():
webnotes.conn.sql("""\
DELETE FROM `tabSingles`
WHERE doctype = 'Control Panel'
AND field IN ("sync_with_gateway", "mail_password", "auto_email_id",
"mail_port", "outgoing_mail_server", "mail_login", "use_ssl")""")

View File

@@ -0,0 +1,116 @@
# do not run this patch
from __future__ import unicode_literals
field_list = [
['Contact', 'notes'],
['Contact', 'birthday'],
['Contact', 'anniversary'],
['Customer', 'state_tax_type'],
['Customer', 'tin_no'],
['Customer', 'excise_registration_number'],
['Customer', 'customer_discount_details'],
['Customer', 'notes'],
['Customer', 'follow_up_section'],
['Customer', 'follow_up'],
['Delivery Note', 'shipping_contact_no'],
['Delivery Note', 'shipping_tin_no'],
['Delivery Note', 'shipping_excise_no'],
['Delivery Note', 'tin_no'],
['Delivery Note', 'excise_no'],
['Delivery Note Detail', 'cetsh_number'],
['Item', 'base_material'],
['Item', 'tool_type'],
['Item', 'no_of_flutes'],
['Item', 'special_treatment'],
['Item', 'length'],
['Item', 'width'],
['Item', 'height_dia'],
['Item', 'pl_item'],
['Item', 'cetsh_number'],
['Item', 'stock_maintained'],
['Item', 'is_rm'],
['Journal Voucher Detail', 'line_remarks'],
['Lead', 'designation'],
['Purchase Order', 'challan_number'],
['Quotation', 'cust_enq_no'],
['Quotation', 'enq_date'],
['Quotation', 'quote_valid'],
['Quotation', 'due_date'],
['Receivable Voucher', 'voucher_time'],
['Receivable Voucher', 'removal_time'],
['Receivable Voucher', 'removal_date'],
['Receivable Voucher', 'shipping_address'],
['Receivable Voucher', 'shipping_location'],
['Receivable Voucher', 'ship_to'],
['Receivable Voucher', 'shipping_contact_no'],
['Receivable Voucher', 'shipping_excise_no'],
['Receivable Voucher', 'shipping_tin_no'],
['Receivable Voucher', 'po_no'],
['Receivable Voucher', 'po_date'],
['Receivable Voucher', 'lr_no'],
['Receivable Voucher', 'transporters'],
['Receivable Voucher', 'ship_terms'],
['Receivable Voucher', 'tin_no'],
['Receivable Voucher', 'excise_no'],
['RV Detail', 'cetsh_number'],
['Sales Order', 'shipping_contact_no'],
['Sales Order', 'shipping_tin_no'],
['Sales Order', 'shipping_excise_no'],
['Sales Order', 'tin_no'],
['Sales Order', 'excise_number'],
['Sales Order Detail', 'cetsh_number'],
['Sales Order Detail', 'prd_notes'],
['Shipping Address', 'phone_no'],
['Shipping Address', 'tin_no'],
['Shipping Address', 'excise_no'],
['Stock Entry', 'process_custom'],
['Stock Entry', 'city'],
['Stock Entry', 'address_line_2'],
['Stock Entry', 'address_line_1'],
['Stock Entry', 'comp_other'],
['Stock Entry', 'mobile_no'],
['Stock Entry', 'phone_no'],
['Stock Entry', 'country'],
['Stock Entry', 'state'],
['Stock Entry', 'challan_number'],
['Stock Entry Detail', 'machine'],
['Stock Entry Detail', 'worker'],
['Supplier', 'notes'],
['Supplier', 'purchase_other_charges'],
['Supplier', 'tax_details'],
['Supplier', 'tin_number'],
['Supplier', 'excise_regd_number'],
['Supplier', 'service_tax_regd_number'],
['Warehouse', 'comp_other'],
['Warehouse', 'process'],
['Warehouse', 'country'],
['Warehouse', 'tax_registration_number'],
['Warehouse Type', 'process'],
['Workstation', 'maintenance_data'],
]
import webnotes
from webnotes.model.code import get_obj
from webnotes.model.doc import Document
def execute():
import webnotes.model.sync
webnotes.model.sync.sync('core', 'custom_field')
for f in field_list:
res = webnotes.conn.sql("""SELECT name FROM `tabCustom Field`
WHERE dt=%s AND fieldname=%s""", (f[0], f[1]))
if res: continue
docfield = webnotes.conn.sql("""SELECT * FROM `tabDocField`
WHERE parent=%s AND fieldname=%s""", (f[0], f[1]), as_dict=1)
if not docfield: continue
custom_field = docfield[0]
# scrub custom field dict
custom_field['dt'] = custom_field['parent']
del custom_field['parent']
d = Document('Custom Field', fielddata=custom_field)
d.name = custom_field['dt'] + '-' + custom_field['fieldname']
d.save(1, ignore_fields=1)
#obj = get_obj(doc=d)
#obj.on_update()

View File

@@ -0,0 +1,9 @@
from __future__ import unicode_literals
def execute():
import webnotes
webnotes.conn.sql("DELETE FROM `tabDocField` WHERE options='DocFormat'")
webnotes.conn.sql("DELETE FROM `tabDocField` WHERE parent='DocFormat'")
webnotes.conn.sql("DELETE FROM `tabDocType` WHERE name='DocFormat'")
webnotes.conn.commit()
webnotes.conn.sql("DROP TABLE `tabDocFormat`")
webnotes.conn.begin()

View File

@@ -0,0 +1,146 @@
from __future__ import unicode_literals
import webnotes
def execute():
"""
* Custom Field changes
* Add file_list to required tables
* Change floats/currency to decimal(18, 6)
* Remove DocFormat from DocType's fields
* Remove 'no_column' from DocField
* Drop table DocFormat
"""
import webnotes.model.sync
webnotes.model.sync.sync_all(force=1)
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
"""
print "in handle custom fields"
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
#print len(cf)
for f in cf:
#print f.get('dt'), f.get('name')
if f.get('idx'): continue
temp_doclist = get(f.get('dt'), form=0)
#print len(temp_doclist)
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]
res = webnotes.conn.sql("""\
SELECT name FROM `tabProperty Setter`
WHERE doc_type = %s
AND field_name = %s
AND property = 'previous_field'""", (f.get('dt'), f.get('fieldname')))
if not res:
ps = Document('Property Setter', fielddata = {
'doctype_or_field': 'DocField',
'doc_type': f.get('dt'),
'field_name': f.get('fieldname'),
'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():
should_exist = ['Website Settings', 'Web Page', 'Timesheet', 'Task',
'Support Ticket', 'Supplier', 'Style Settings', 'Stock Reconciliation',
'Stock Entry', 'Serial No', 'Sales Order', 'Sales Invoice',
'Quotation', 'Question', 'Purchase Receipt', 'Purchase Order',
'Project', 'Profile', 'Production Order', 'Product', 'Print Format',
'Price List', 'Purchase Invoice', 'Page',
'Maintenance Visit', 'Maintenance Schedule', 'Letter Head',
'Leave Application', 'Lead', 'Journal Voucher', 'Item', 'Purchase Request',
'Expense Claim', 'Opportunity', 'Employee', 'Delivery Note',
'Customer Issue', 'Customer', 'Contact Us Settings', 'Company',
'Bulk Rename Tool', 'Blog', 'BOM', 'About Us Settings']
from webnotes.model.code import get_obj
for dt in should_exist:
obj = get_obj('DocType', dt, with_children=1)
obj.doc.allow_attach = 1
obj.doc.save()
obj.make_file_list()
from webnotes.model.db_schema import updatedb
updatedb(obj.doc.name)
from webnotes.utils.cache import CacheItem
CacheItem(obj.doc.name).clear()
def change_to_decimal():
print "in 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(18,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()

View File

@@ -0,0 +1,15 @@
from __future__ import unicode_literals
def execute():
import webnotes
webnotes.conn.sql("""
UPDATE `tabDocField`
SET fieldtype = 'Link', options = 'Deduction Type'
WHERE parent = 'Deduction Detail'
AND fieldname = 'd_type'
""")
webnotes.conn.sql("""
UPDATE `tabDocField`
SET fieldtype = 'Link', options = 'Earning Type'
WHERE parent = 'Earning Detail'
AND fieldname = 'e_type'
""")

View File

@@ -0,0 +1,24 @@
# dont run this patch
from __future__ import unicode_literals
def execute():
import webnotes
import webnotes.model.doctype
from webnotes.utils import cint
from webnotes.model.doc import Document
from webnotes.model.code import get_obj
doctype_list = webnotes.conn.sql("SELECT name FROM `tabDocType`")
for dt in doctype_list:
doclist = webnotes.model.doctype.get(dt[0], form=0)
is_submittable = 0
for d in doclist:
if d.doctype == 'DocPerm' and d.fields.get('permlevel') == 0 \
and cint(d.fields.get('submit')) == 1:
is_submittable = 1
break
if is_submittable:
dt_doc = Document('DocType', doclist[0].name)
dt_doc.is_submittable = 1
dt_doc.save()
obj = get_obj(doc=dt_doc)
obj.make_amendable()
obj.on_update()

View File

@@ -0,0 +1,4 @@
from __future__ import unicode_literals
def execute():
from webnotes.modules import reload_doc
reload_doc('accounts', 'Print Format', 'POS Invoice')

View File

@@ -0,0 +1,11 @@
from __future__ import unicode_literals
def execute():
import webnotes
count = webnotes.conn.sql("""SELECT COUNT(*) FROM `tabTable Mapper Detail`
WHERE parent='Sales Order-Sales Invoice'
AND from_table='Sales Order Item'""")
if count and count[0][0]==2:
webnotes.conn.sql("""DELETE FROM `tabTable Mapper Detail`
WHERE parent='Sales Order-Sales Invoice'
AND from_table='Sales Order Item'
AND validation_logic='docstatus = 1'""")

View File

@@ -0,0 +1,18 @@
from __future__ import unicode_literals
def execute():
import webnotes
doctype_list = webnotes.conn.sql("""SELECT name FROM `tabDocType`
WHERE docstatus<2 AND IFNULL(issingle, 0)=0
AND IFNULL(istable, 0)=0""")
webnotes.conn.commit()
for d in doctype_list:
add_col = True
desc = webnotes.conn.sql("DESC `tab%s`" % d[0], as_dict=1)
for td in desc:
if td.get('Field')=='_user_tags':
add_col = False
if add_col:
webnotes.conn.sql("alter table `tab%s` add column `_user_tags` varchar(180)" % d[0])
webnotes.conn.begin()