first cut for lazy loading framework

This commit is contained in:
Rushabh Mehta
2011-09-05 18:43:09 +05:30
parent 09938bda69
commit 66ac2b018a
1512 changed files with 832 additions and 0 deletions

View File

View File

@@ -1,43 +0,0 @@
import webnotes
sql = webnotes.conn.sql
# update SO
#---------------
def update_percent():
so = sql("select name from `tabSales Order` where docstatus = 1")
for d in so:
sql("""
update
`tabSales Order`
set
per_delivered = (select sum(if(qty > ifnull(delivered_qty, 0), delivered_qty, qty))/sum(qty)*100 from `tabSales Order Detail` where parent='%s'),
per_billed = (select sum(if(qty > ifnull(billed_qty, 0), billed_qty, qty))/sum(qty)*100 from `tabSales Order Detail` where parent='%s')
where
name='%s'""" % (d[0], d[0], d[0]))
# update DN
# ---------
dn = sql("select name from `tabDelivery Note` where docstatus = 1")
for d in dn:
sql("""
update
`tabDelivery Note`
set
per_billed = (select sum(if(qty > ifnull(billed_qty, 0), billed_qty, qty))/sum(qty)*100 from `tabDelivery Note Detail` where parent='%s')
where
name='%s'""" % (d[0], d[0]))
# update delivery/billing status
#-------------------------------
def update_status():
sql("""update `tabSales Order` set delivery_status = if(ifnull(per_delivered,0) < 0.001, 'Not Delivered',
if(per_delivered >= 99.99, 'Fully Delivered', 'Partly Delivered'))""")
sql("""update `tabSales Order` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
sql("""update `tabDelivery Note` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
def run_patch():
update_percent()
update_status()

View File

@@ -1,200 +0,0 @@
#Cleanup all unwanted documents and restructure of moduloes
#----------------------------------------------------------
import webnotes
from webnotes.model import delete_doc
from webnotes.modules.module_manager import reload_doc
from webnotes.modules.export_module import export_to_files
sql = webnotes.conn.sql
#----------------------------
def delete_unwanted_doctypes():
"deletes doctypes which are not used anymore"
try:
sql("delete from `tabMenu Item`")
sql("delete from tabDocField where fieldname = 'site_map_details' and parent ='Control Panel'")
except:
pass
lst = ['Zone', 'WN Account Control', 'Wiki Page', 'Wiki History', 'Wiki Control', 'While You Were Out', 'Web Visitor', 'Tweet', 'Transfer Utility', 'Transfer Module', 'Transfer Control', 'Transfer Account', 'Tips Common', 'TestTabDT', 'TestDT', 'Test Type', 'Test Run', 'Test Record Detail', 'Test Record', 'Test Case', 'Supplier TDS Category Detail', 'Shopping Cart Control', 'Service Series', 'Series Detail', 'Rule Engine', 'RFQ', 'Report Filter Detail', 'Report Field Detail','Report Control', 'Rating Widget Record', 'Rating Widget Control', 'Rating Template Detail', 'Rating Template', 'PV Ded Tax Detail', 'PV Add Tax Detail', 'Product Variant', 'Product Variance', 'Product Group', 'Product Feature', 'Payroll Tips Common', 'Payroll Rule', 'Password Control', 'Page Visit', 'Patch', 'Multiple Transfer', 'Module Tip Control', 'Module Setter', 'Module Manager', 'Module Import', 'Module Detail', 'Message Control', 'Message', 'Mail Participant Details', 'Mail', 'Leave Type Detail', 'Leave Detail', 'Leave Applicable Detail', 'Lead Item Detail', 'Lead Attachment Detail', 'Item Attachments Detail', 'Instant Message', 'Impact Analysis', 'Forum Topic', 'Forum Control', 'Form Settings', 'Follower', 'ERP Setup', 'Enquiry Attachment Detail', 'Documentation', 'Condition Detail', 'Complaint Note', 'Code History', 'Code Editor', 'Code Backup Control', 'Code Backup', 'City', 'Change Log', 'Business Letter Type', 'Business Letter Template', 'Business Letter', 'Badge Settings Detail', 'Application Type', 'Application', 'Action Detail', 'Accounts Setup', 'Stock Common', 'Job Application', 'Service Schedule', 'Comment Control', 'Bank', 'Tag Widget Control', 'Feature Update', 'RFQ Detail', 'Supplier Quotation Detail', 'Supplier Quotation', 'Year Closing Voucher', 'Approval Structure', 'Site Map Detail', 'Menu Control', 'Menu Item', 'Menu Item Role'] # bank
for d in lst:
try:
sql("delete from `tabProperty Setter` where select_doctype = '%s'" % d)
sql("delete from `tabCustom Script` where dt = '%s'" % d)
sql("delete from `tabCustom Field` where dt = '%s'" % d)
delete_doc('DocType', d)
except:
pass
sql("commit")
delete_tables(lst)
def delete_tables(lst):
for d in lst:
for t in ['tab', 'arc']:
try:
sql("drop table `%s%s`" % (t, d))
except:
continue
def delete_unwanted_pages():
"deletes pages which are not used anymore"
lst = ['Transaction Authorization', 'Prduct Display', 'Data Import', 'Partner Home', 'Product Display', 'Module Settings', 'About Us', 'Custom Reports', 'MIS', 'MIS - Comparison Report', 'Monthly MIS', 'MyReports', 'Navigation Page', 'Point Race', 'Tag Widget', 'Widget Test', 'Yearly MIS']
for d in lst:
try:
delete_doc('Page', d)
except:
pass
def delete_unwanted_search_criteria():
"deletes search criteria which are not used anymore"
sql("update `tabSearch Criteria` set module = 'HR' where name = 'salary_structure_details'")
lst = ['_SRCH00002', '_SRCH00001', 'warranty-amc_summary1', 'test_so4', 'test_so3', 'test_so2', 'test_so1', 'test_so', 'test5', 'target_variance_report1', 'STDSRCH/00006', 'STDSRCH/00005', 'STDSRCH/00004', 'STDSRCH/00003', 'STDSRCH/00002', 'STDSRCH/00001', 'so_pending_items_6', 'so_pending_items_5', 'so_pending_items_3', 'so_pending_items_34', 'scrap', 'sales_report_test', 'salary_structure_details1', 'salary_structure_details2', 'salary_structure_details3', 'salary_slips1', 'projectwise_pending_qty_and_costs2', 'projectwise_pending_qty_and_costs1', 'projectwise_delivered_qty_and_costs1', 'projectwise_delivered_qty_and_costs2', 'New Search Criteria 1', 'monthly_salary_register2', 'monthly_salary_register1', 'installed_items','follow_up_history', 'follow_up_report', 'employee_in_company_experience2', 'employee_in_company_experience1', 'employee_in_company_experience', 'employee_details', 'employee_details1', 'employee_details2', 'employees_birthday1', 'draft_so_pending_items', 'draft_sales_orders', 'delivery_notewise_pending_qty_to_install', 'datewise_leave_report2', 'datewise_leave_report1', 'datewise_leave_report', 'customer_issues1', 'cancelled_so_pending_items1', 'cancelled_so_pending_items', 'budget_variance_report3', 'budget_variance_report1', 'account_-_inputs_rg_23_a_-_part_ii_wrong_one', 'territory_item_group_wise_gp', 'sales_orderwise_pending_packing_item_summary', 'itemwise_trend', 'monthly_attendance_details_old', 'projectwise_contribution_report', 'projectwise_delivery_and_material_cost', 'projectwise_delivery_and_mat_cost_report', 'territorywise_trend', 'test_dn', 'rfq', 'rfq1']
for d in lst:
if sql("select name from `tabSearch Criteria` where ifnull(standard, 'Yes') = 'Yes' and name = '%s'" % d):
try:
delete_doc('Search Criteria', d)
except:
pass
def delete_unwanted_mappers():
"deletes unwanted mappers"
lst = ['Customer Issue-Maintenance Report', 'Enquiry-Service Quotation', 'Sales Order-Maintenance Report', 'Service Quotation-Service Order', 'Supplier Quotation-Purchase Order', 'Visit Schedule-Maintenance Report', 'RFQ-Supplier Quotation', 'Indent-RFQ']
for d in lst:
try:
delete_doc('DocType Mapper', d)
except:
pass
def delete_unwanted_modules():
"deletes unwanted modules"
lst = ['Development', 'Recycle Bin', 'Testing', 'Testing System', 'Test', 'Partner Updates', 'My Company', 'Event Updates', 'E-Commerce']
for d in lst:
try:
delete_doc('Module Def', d)
except:
pass
#---------------------------------------------
def rename_merge_modules():
"Rename module as per users view and merge for removing confusion"
rename_lst = [['CRM', 'Selling'], ['SRM','Buying'], ['Material Management', 'Stock'], ['Payroll','HR'], ['Maintenance', 'Support']]
for d in rename_lst:
# create new module manually and export to file???????
reload_doc(d[1].lower(), 'Module Def', d[1])
merge_lst = [['Tools', 'Utilities'], ['Application Internal', 'Utilities'], ['Settings', 'Setup']]
# settings hardcoded in my_company
# module hardcoded in home_control
# material_management hardcoded in installation note
# maintenance hardcoded in support_email_settings
lst = rename_lst + merge_lst
for d in lst:
update_module(d[0], d[1])
try:
delete_doc('Module Def', d[0])
except:
pass
reload_doc('Utilities', 'Module Def', 'Utilities')
def update_module(from_mod, to_mod):
for t in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
sql("update `tab%s` set module='%s' where module = '%s'"% (t, to_mod, from_mod))
#------------------------------------
def sync_roles():
"Put Roles into corresponding module and delete Roles module"
# roles
roles = {
'Accounts' : "'Accounts Manager', 'Accounts User', 'Auditor'",
'Selling' : "'Customer', 'Sales User', 'Sales Manager', 'Sales Master Manager', 'Partner'",
'Buying' : "'Supplier', 'Purchase User', 'Purchase Manager', 'Purchase Master Manager'",
'Stock' : "'Material User', 'Material Master Manager', 'Material Manager', 'Quality Manager'",
'Support' : "'Support Team', 'Support Manager', 'Maintenance User', 'Maintenance Manager'",
'Production': "'Production User', 'Production Manager', 'Production Master Manager'",
'Setup' : "'System Manager'",
'Projects' : "'Projects User'",
'HR' : "'HR User', 'HR Manager', 'Employee'",
'Core' : "'Administrator', 'All', 'Guest'"
}
for mod in roles.keys():
sql("update `tabRole` set module = '%s' where name in (%s)" % (mod, roles[mod]))
sql("update `tabDocType` set module = 'Setup' where name = 'Role'")
try:
delete_doc('Module Def', 'Roles')
except:
pass
#------------------------------------
def sync_mapper():
"Put mappers into corresponding module"
mappers = {
'Accounts': ('Delivery Note-Receivable Voucher', 'Project-Receivable Voucher', 'Purchase Order-Payable Voucher', 'Purchase Receipt-Payable Voucher', 'Sales Order-Receivable Voucher'),
'Selling': ('Delivery Note-Installation Note', 'Enquiry-Quotation', 'Lead-Enquiry', 'Lead-Customer', 'Project-Sales Order', 'Quotation-Sales Order', ),
'Buying': ('Indent-Purchase Order', 'Sales Order-Indent'),
'Stock': ('Purchase Order-Purchase Receipt', 'Project-Delivery Note', 'Receivable Voucher-Delivery Note', 'Sales Order-Delivery Note'),
'Support': ('Customer Issue-Maintenance Visit', 'Sales Order-Maintenance Schedule', 'Sales Order-Maintenance Visit'),
'Production': ('Production Forecast-Production Plan', 'Production Forecast-Production Planning Tool', 'Sales Order-Production Plan'),
'HR': ('KRA Template-Appraisal', 'Salary Structure-Salary Slip')
}
for mod in mappers.keys():
sql("update `tabDocType Mapper` set module = '%s' where name in %s" % (mod, mappers[mod]))
try:
delete_doc('Module Def', 'Mapper')
except:
pass
# --------------------------------------
# function below will be run only in localhost
'''def export_docs():
"""
Export all documents where module has been changed
"""
for dtype in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
lst = sql("select name, module from `tab%s`" % dtype)
for rec in lst:
webnotes.msgprint(rec)
if rec and rec[0] and rec[1]:
export_to_files(record_list = [[dtype, rec[0]]], record_module = rec[1])
#grep test company
'''
#---------------------------------------
def run_patches():
# update module
dt_module = {'LC PR Detail':'Stock', 'Landed Cost Detail':'Stock', 'Comment Widget Record': 'Core', 'Tag':'Core', 'Tag Detail': 'Core', 'POS Settings': 'Accounts', 'Menu Item': 'Setup', 'Menu Item Role': 'Setup'}
for d in dt_module.keys():
sql("update `tabDocType` set module = '%s' where name = '%s'" % (dt_module[d], d))
delete_unwanted_mappers()
delete_unwanted_doctypes()
sql("start transaction")
delete_unwanted_pages()
delete_unwanted_search_criteria()
rename_merge_modules()
sync_roles()
sync_mapper()
delete_unwanted_modules()
# landed cost wizard link in stock
reload_doc('stock', 'Module Def', 'Stock')
sql("commit")

View File

@@ -1,295 +0,0 @@
"""
This patch removes wrong indexs and add proper indexes in tables
"""
import webnotes
sql = webnotes.conn.sql
from webnotes.utils import cint, cstr
def create_proper_index():
from webnotes.modules.export_module import export_to_files
dt_index_fields={
'Purchase Receipt Detail': ['prevdoc_docname', 'item_code', 'warehouse', 'prevdoc_detail_docname'],
'Period Closing Voucher': ['closing_account_head', 'fiscal_year'],
'Lead': ['lead_name', 'status', 'transaction_date'],
'Time Sheet Detail': ['app_name'],
'Item Specification Detail': [],
'Budget Detail': ['fiscal_year', 'account'],
'Grade': [],
'RV Tax Detail': ['parenttype', 'account_head'],
'TDS Category Account': ['account_head'],
'Role': [],
'Leave Allocation': ['leave_type', 'employee', 'fiscal_year'],
'Branch': [],
'Department': [],
'Contact Detail': [],
'Territory': ['lft', 'rgt', 'parent_territory'],
'Item Tax': ['tax_type'],
'Bin': ['warehouse', 'item_code'],
'PPW Detail': ['warehouse'],
'Sales Partner': ['partner_name'],
'Default Home Page': ['home_page', 'role'],
'Custom Field': ['dt'],
'DocFormat': ['format'],
'DocType Mapper': ['from_doctype', 'to_doctype'],
'Brand': [],
'Order Lost Reason': [],
'Journal Voucher': ['posting_date', 'voucher_type'],
'TDS Return Acknowledgement': ['date_of_receipt', 'acknowledgement'],
'BOM Report Detail': ['item_code'],
'Quotation Detail': ['item_code'],
'Update Delivery Date Detail': ['sales_order_no'],
'Advance Adjustment Detail': ['journal_voucher'],
'Authorization Rule': ['approving_user', 'system_user', 'system_role', 'approving_role'],
'DocPerm': ['permlevel', 'role'],
'Stock Entry Detail': ['item_code', 't_warehouse', 's_warehouse'],
'Stock Entry': ['posting_date', 'delivery_note_no', 'purchase_receipt_no', 'production_order'],
'Price List': [],
'KRA Sheet': [],
'Production Order': ['status', 'project_name', 'production_item'],
'Account': ['lft', 'rgt', 'parent_account'],
'Earn Deduction Detail': [],
'Indent': ['status', 'transaction_date'],
'Tag Detail': [],
'SS Deduction Detail': ['d_type'],
'Batch': ['item'],
'Deduction Type': [],
'Project': ['project_name', 'customer'],
'UserRole': ['role'],
'DocField': ['label', 'fieldtype', 'fieldname'],
'Property Setter': ['doc_type', 'doc_name', 'property'],
'Appraisal': ['status', 'employee'],
'Letter Head': [],
'Follow up': ['follow_up_by'],
'Project Cost Breakup': [],
'Table Mapper Detail': [],
'Campaign': [],
'Static Parameter Detail': [],
'Leave Type': [],
'Account Balance': ['period', 'start_date', 'end_date', 'account'],
'Absent Days Detail': [],
'Tag': [],
'Raw Materials Supplied': ['raw_material'],
'Project Activity Update': [],
'PR Raw Material Detail': [],
'Bank Reconciliation Detail': ['voucher_id'],
'Sales Order': ['quotation_no', 'project_name', 'customer', 'posting_date'],
'Chapter VI A Detail': [],
'Experience In Company Detail': [],
'Order Reconciliation Detail': ['sales_order_no'],
'Attendance': ['employee', 'att_date'],
'Previous Experience Detail': [],
'Earning Detail': ['e_type'],
'Sales Order Detail': ['item_code', 'prevdoc_docname', 'reserved_warehouse'],
'KRA Template': [],
'Budget Distribution': ['fiscal_year'],
'Workstation': ['warehouse'],
'Period': [],
'Training Session Details': [],
'Other Charges': [],
'State': [],
'Bulk Rename Tool': [],
'Landed Cost Master Detail': [],
'Employee': ['employee_name', 'designation', 'department'],
'Terms And Conditions': [],
'TC Detail': [],
'UOM': [],
'Supplier Type': [],
'Project Milestone': [],
'Landed Cost Master': [],
'Budget Distribution Detail': [],
'Form 16A Ack Detail': [],
'Campaign Expense': [],
'Time Sheet': ['employee_name', 'time_sheet_date'],
'File Group': ['parent_group'],
'Maintenance Visit Detail': ['item_code', 'service_person'],
'Support Ticket Response': [],
'PV Detail': ['item_code', 'purchase_order', 'po_detail', 'purchase_receipt', 'pr_detail', 'expense_head', 'cost_center'],
'Timesheet Detail': ['project_name', 'task_id', 'customer_name'],
'Holiday List Detail': [],
'Workflow Rule Detail': [],
'Module Def': ['module_seq', 'module_page'],
'Term': [],
'PF Detail': ['item_code'],
'POS Setting': ['user', 'territory'],
'QA Specification Detail': [],
'Support Ticket': ['customer', 'allocated_to', 'status'],
'Project Activity': ['project'],
'Customer Group': ['lft', 'rgt', 'parent_customer_group'],
'Return Detail': ['item_code'],
'Series Detail': [],
'Event Role': ['role'],
'Contact': ['employee_id'],
'BOM Material': ['item_code', 'bom_no'],
'Invest 80 Declaration Detail': [],
'PO Raw Material Detail': [],
'Industry Type': [],
'Declaration Detail': [],
'Holiday List': ['fiscal_year'],
'Sales Person': ['lft', 'rgt', 'parent_sales_person'],
'RV Detail': ['item_code', 'sales_order', 'so_detail', 'delivery_note', 'dn_detail', 'cost_center', 'income_account'],
'Module Def Item': [],
'TDS Category': [],
'DocTrigger': [],
'Print Format': ['standard'],
'Installed Item Details': ['prevdoc_docname', 'item_code'],
'Form 16A Tax Detail': [],
'Event': ['event_date', 'event_type'],
'Currency': [],
'Service Quotation Detail': ['item_code'],
'Warehouse Type': ['warehouse_type'],
'Sales BOM': ['item_group'],
'IT Checklist': ['employee'],
'Purchase Other Charges': [],
'Company': [],
'Call Log': [],
'Professional Training Details': [],
'Warehouse': ['warehouse_type'],
'Competitor': [],
'Mode of Payment': [],
'Training Session': ['customer'],
'Cost Center': ['lft', 'rgt', 'parent_cost_center'],
'Timesheet': ['status', 'timesheet_date'],
'Form 16A': ['party_no'],
'Sales BOM Detail': ['item_code'],
'Answer': ['question'],
'Supplier': [],
'Installation Note': ['delivery_note_no', 'customer', 'inst_date'],
'Expense Voucher': ['approval_status', 'employee'],
'Target Detail': ['from_date', 'to_date', 'fiscal_year'],
'Page Role': ['role'],
'Partner Target Detail': ['fiscal_year', 'item_group'],
'Shipping Address': ['customer'],
'Indent Detail': ['item_code', 'warehouse'],
'TDS Payment Detail': [],
'Market Segment': [],
'Comment Widget Record': [],
'Service Order Detail': ['item_code', 'prevdoc_docname'],
'TDS Payment': ['from_date', 'to_date', 'tds_category'],
'Lead Email CC Detail': [],
'User Setting-Role User': [],
'Salary Slip': ['month', 'year', 'employee'],
'Maintenance Schedule Detail': ['item_code', 'scheduled_date'],
'Employment Type': [],
'Advance Allocation Detail': ['journal_voucher'],
'Quotation': ['customer', 'transaction_date'],
'Deduction Detail': ['d_type'],
'Bill Of Materials': ['item', 'project_name'],
'Earning Type': [],
'Designation': [],
'BOM Replace Utility Detail': ['parent_bom'],
'Question': [],
'Stock Ledger Entry': ['item_code', 'warehouse', 'posting_date', 'posting_time'],
'Educational Qualifications Detail': [],
'BOM Operation': [],
'Item Group': ['lft', 'rgt', 'parent_item_group'],
'Workflow Action Detail': [],
'User Setting-Profile': [],
'Customer Issue': ['item_code', 'customer', 'complaint_date'],
'Feed': [],
'Purchase Tax Detail': ['account_head'],
'GL Mapper Detail': [],
'TDS Detail': [],
'PRO Detail': ['item_code', 'source_warehouse'],
'DocType Label': [],
'Receivable Voucher': ['posting_date', 'debit_to', 'project_name'],
'GL Entry': ['posting_date', 'account', 'voucher_no'],
'Serial No': ['status', 'warehouse'],
'Delivery Note': ['posting_date', 'project_name', 'customer'],
'UOM Conversion Detail': ['uom'],
'Search Criteria': ['criteria_name'],
'Salary Structure': [],
'Educational Qualifications': ['qualification'],
'TDS Rate Chart': ['applicable_from', 'applicable_to'],
'GL Mapper': [],
'Announcement': [],
'Call Log Details': [],
'Enquiry': ['lead', 'customer', 'transaction_date'],
'Flat BOM Detail': ['item_code'],
'Landed Cost Detail': ['account_head'],
'Field Mapper Detail': ['from_field', 'to_field'],
'File Data': [],
'Question Tag': [],
'QA Inspection Report': ['item_code', 'purchase_receipt_no', 'report_date'],
'Appraisal Detail': [],
'POS Settings': ['territory'],
'Delivery Note Detail': ['item_code', 'prevdoc_docname', 'warehouse', 'prevdoc_detail_docname'],
'Profile': [],
'Other Income Detail': [],
'Product': ['item_code', 'stock_warehouse'],
'PO Detail': ['prevdoc_docname', 'item_code', 'prevdoc_detail_docname', 'warehouse'],
'Module Def Role': ['role'],
'Sales Team': ['sales_person'],
'Enquiry Detail': ['item_code'],
'DocType': [],
'Compaint Note': ['nature_of_complaint', 'compliance_date'],
'Maintenance Schedule': ['customer', 'sales_order_no'],
'Event User': ['person'],
'Stock Reconciliation': ['reconciliation_date'],
'Purchase Receipt': ['posting_date', 'supplier', 'project_name'],
'Complaint Detail': ['item_name'],
'Address': ['customer', 'supplier'],
'Ticket': ['request_date', 'allocated_to', 'category', 'customer', 'project'],
'Territory Target Detail': ['month', 'fiscal_year'],
'LC PR Detail': ['purchase_receipt_no'],
'Customer': ['customer_name', 'customer_group'],
'PP SO Detail': [],
'PP Detail': ['document_date', 'item_code', 'parent_item'],
'User Setting-Role Permission': [],
'Custom Script': ['dt'],
'Country': [],
'DefaultValue': [],
'Ledger Detail': [],
'SS Earning Detail': ['e_type'],
'SMS Log': [],
'Expense Type': [],
'Item': ['item_group'],
'Fiscal Year': [],
'ToDo Item': ['role'],
'Payable Voucher': ['posting_date', 'credit_to', 'project_name', 'supplier'],
'Journal Voucher Detail': ['account', 'against_voucher', 'against_invoice', 'against_jv'],
'Online Contact': [],
'Page': ['module'],
'Leave Application': ['employee', 'leave_type', 'from_date', 'to_date'],
'Expense Voucher Detail': ['expense_type'],
'Maintenance Visit': ['customer', 'sales_order_no', 'customer_issue_no'],
'Ref Rate Detail': ['price_list_name', 'ref_currency'],
'Receiver Detail': [],
'Naming Series Options': ['doc_type'],
'Activity Type': [],
'PRO PP Detail': [],
'Delivery Note Packing Detail': ['item_code', 'parent_item', 'warehouse'],
'Workflow Rule': ['select_form'],
'File': ['file_group'],
'Item Maintenance Detail': ['item_code', 'start_date', 'end_date', 'prevdoc_docname'],
'Purchase Order': ['supplier', 'project_name', 'posting_date'],
'Print Heading': [],
'TDS Rate Detail': ['category']
}
#sql("commit") # only required if run from login
exist_dt = [cstr(d[0]) for d in sql("select name from `tabDocType`")]
for dt in [d for d in dt_index_fields.keys() if d in exist_dt]:
try:
current_index = sql("show indexes from `tab%s`" % dt)
proper_index = dt_index_fields[dt]
for d in current_index:
if d[4] not in ['name', 'parent', 'parenttype']:
if d[4] not in proper_index:
sql("ALTER TABLE `tab%s` DROP INDEX %s" % (dt, d[4]))
sql("start transaction")
sql("UPDATE `tabDocField` SET search_index = 0 WHERE fieldname = '%s' AND parent = '%s'" % (d[4], dt))
sql("commit")
else:
proper_index.remove(d[4])
for d in proper_index:
sql("ALTER TABLE `tab%s` ADD INDEX ( `%s` ) " % (dt, d))
sql("start transaction")
sql("UPDATE `tabDocField` SET search_index = 1 WHERE fieldname = '%s' AND parent = '%s'" % (d, dt))
sql("commit")
except:
continue

View File

@@ -1,688 +0,0 @@
import webnotes
from webnotes.model.doc import Document
from webnotes.utils import load_json, cint, cstr
from webnotes import msgprint, errprint
def make_address():
from webnotes.modules.module_manager import reload_doc
reload_doc('utilities','doctype','address')
from webnotes.model.db_schema import updatedb
updatedb('Address')
def make_address_from_customer():
for c in webnotes.conn.sql("select * from tabCustomer", as_dict=1):
d = Document('Address')
d.address_line1 = c['address_line1']
d.address_line2 = c['address_line2']
d.city = c['city']
d.country = c['country']
d.pincode = c['pincode']
d.state = c['state']
d.fax = c['fax_1']
d.email_id = c['email_id']
d.phone = c['phone_1']
d.customer = c['name']
d.customer_name = c['customer_name']
d.is_primary_address = 1
d.address_type = 'Office'
try:
d.save(1)
except NameError, e:
pass
def make_address_from_supplier():
for c in webnotes.conn.sql("select * from tabSupplier", as_dict=1):
d = Document('Address')
d.address_line1 = c['address_line1']
d.address_line2 = c['address_line2']
d.city = c['city']
d.country = c['country']
d.pincode = c['pincode']
d.state = c['state']
d.supplier = c['name']
d.supplier_name = c['supplier_name']
d.is_primary_address = 1
d.address_type = 'Office'
try:
d.save(1)
except NameError, e:
pass
def make_contact_from_contacttab():
webnotes.conn.sql("""
update ignore tabContact set
is_primary_contact = if(is_primary_contact='Yes',1,0)
""")
webnotes.conn.sql("""
update ignore tabContact t1, tabCustomer t2 set
t1.name = concat(ifnull(t1.contact_name,t1.name), '-', ifnull(t1.customer_name, t2.name))
where ifnull(t1.is_customer,0)=1
and t1.customer = t2.name
""")
webnotes.conn.sql("""
update ignore tabContact t1, tabSupplier t2 set
t1.name = concat(ifnull(t1.contact_name,t1.name), '-', ifnull(t1.supplier_name, t2.name))
where ifnull(t1.is_supplier,0)=1
and t1.supplier = t2.name
""")
webnotes.conn.sql("""
update ignore tabContact set
name = concat(ifnull(contact_name,name), '-', sales_partner)
where ifnull(is_sales_partner,0)=1
""")
webnotes.conn.commit()
try:
webnotes.conn.sql("""alter table tabContact change contact_no phone varchar(180)""")
webnotes.conn.sql("""alter table tabContact change is_primary_contact is_primary_contact int(1)""")
except:
pass
webnotes.conn.begin()
def delete_unwanted_fields():
delete_fields = [
('Contact', 'is_sales_partner'), ('Contact', 'sales_partner_address'), ('Contact', 'partner_type'), ('Contact', 'disable_login'), ('Contact', 'contact_address'), ('Contact', 'fax'), ('Contact', 'company_name'), ('Contact', 'contact_no'), ('Contact', 'customer_group'), ('Contact', 'has_login'), ('Contact', 'Create Login'), ('Contact', 'contact_name'), ('Contact', 'company_address'), ('Contact', 'customer_address'), ('Contact', 'supplier_address'), ('Contact', 'supplier_type'), ('Contact', 'is_customer'), ('Contact', 'is_supplier'), ('Contact', 'employee_id'), ('Contact', 'is_employee'),
('Customer', 'region'), ('Customer', 'pincode'), ('Customer', 'city'), ('Customer', 'country'), ('Customer', 'state'), ('Customer', 'address'), ('Customer', 'telephone'), ('Customer', 'address_line2'), ('Customer', 'address_line1'), ('Customer', 'last_sales_order'), ('Customer', 'Shipping HTML'), ('Customer', 'phone_1'), ('Customer', 'Territory Help'), ('Customer', 'CG Help'), ('Customer', 'fax_1'), ('Customer', 'email_id'),
('Customer Issue', 'email_id'), ('Customer Issue', 'contact_no'),
('Delivery Note', 'customer_mobile_no'), ('Delivery Note', 'Send SMS'), ('Delivery Note', 'Get Other Charges'), ('Delivery Note', 'message'), ('Delivery Note', 'shipping_address'), ('Delivery Note', 'ship_to'), ('Delivery Note', 'ship_det_no'), ('Delivery Note', 'contact_no'), ('Delivery Note', 'Customer Details'), ('Delivery Note', 'email_id'), ('Delivery Note', 'delivery_address'), ('Delivery Note', 'Contact Help'), ('Delivery Note', 'Territory Help'),
('Enquiry', 'address'), ('Enquiry', 'Send Email'), ('Enquiry', 'enquiry_attachment_detail'), ('Enquiry', 'contact_date_ref'), ('Enquiry', 'Update Follow up'), ('Enquiry', 'email_id1'), ('Enquiry', 'cc_to'), ('Enquiry', 'subject'), ('Enquiry', 'message'), ('Enquiry', 'Attachment Html'), ('Enquiry', 'Create New File'), ('Enquiry', 'contact_no'), ('Enquiry', 'email_id'), ('Enquiry', 'project'), ('Enquiry', 'update_follow_up'), ('Enquiry', 'Contact Help'),
('Installation Note', 'address'),
('Lead', 'message'), ('Lead', 'Send Email'), ('Lead', 'address'), ('Lead', 'subject'), ('Lead', 'contact_no'), ('Lead', 'TerritoryHelp'),
('Maintenance Schedule', 'address'),
('Maintenance Visit', 'address'),
('Purchase Order', 'Contact Help'), ('Purchase Order', 'supplier_qtn'), ('Purchase Order', 'contact_no'), ('Purchase Order', 'email'),
('Purchase Receipt', 'Contact Help'),
('Quotation', 'email_id'), ('Quotation', 'contact_no'), ('Quotation', 'Update Follow up'), ('Quotation', 'contact_date_ref'), ('Quotation', 'Territory Help'), ('Quotation', 'Contact Help'),
('Receivable Voucher', 'Territory Help'),
('Sales Order', 'contact_no'), ('Sales Order', 'email_id'), ('Sales Order', 'Contact Help'), ('Sales Order', 'file_list'), ('Sales Order', 'ship_det_no'), ('Sales Order', 'mobile_no'), ('Sales Order', 'Territory Help'), ('Sales Order', 'ship_to'), ('Sales Order', 'Customer Details'),
('Sales Partner', 'area_code'), ('Sales Partner', 'telephone'), ('Sales Partner', 'email'), ('Sales Partner', 'address'), ('Sales Partner', 'TerritoryHelp'), ('Sales Partner', 'pincode'), ('Sales Partner', 'country'), ('Sales Partner', 'city'), ('Sales Partner', 'address_line2'), ('Sales Partner', 'address_line1'), ('Sales Partner', 'mobile'), ('Sales Partner', 'state'),
('Serial No', 'supplier_address'),
('Supplier', 'city'), ('Supplier', 'country'), ('Supplier', 'state'), ('Supplier', 'address_line1'), ('Supplier', 'last_purchase_order'), ('Supplier', 'address'), ('Supplier', 'address_line2'), ('Supplier', 'pincode'), ('Supplier rating', 'address'), ('Supplier rating', 'select'), ('Supplier rating', 'supplier')]
for d in delete_fields:
webnotes.conn.sql("delete from tabDocField where parent=%s and if(ifnull(fieldname,'')='',ifnull(label,''),fieldname)=%s", (d[0], d[1]))
#def gen_txt_files():
# from webnotes.modules.export_module import export_to_files
# for dt in ['Contact','Customer','Customer Issue','Delivery Note','Enquiry','Installation Note','Lead','Maintenance Schedule','Maintenance Visit','Purchase Order','Purchase Receipt','Quotation','Receivable Voucher','Sales Order','Sales Partner','Serial No','Supplier']:
# export_to_files(record_list=[['DocType',dt]])
def reload_doc_files():
from webnotes.modules.module_manager import reload_doc
reload_doc('utilities', 'doctype', 'contact')
reload_doc('selling', 'doctype', 'customer')
reload_doc('support', 'doctype', 'customer_issue')
reload_doc('stock', 'doctype', 'delivery_note')
reload_doc('selling', 'doctype', 'enquiry')
reload_doc('selling', 'doctype', 'installation_note')
reload_doc('selling', 'doctype', 'lead')
reload_doc('support', 'doctype', 'maintenance_schedule')
reload_doc('support', 'doctype', 'maintenance_visit')
reload_doc('buying', 'doctype', 'purchase_order')
reload_doc('stock', 'doctype', 'purchase_receipt')
reload_doc('selling', 'doctype', 'quotation')
reload_doc('accounts', 'doctype', 'receivable_voucher')
reload_doc('accounts', 'doctype', 'payable_voucher')
reload_doc('selling', 'doctype', 'sales_order')
reload_doc('setup', 'doctype', 'sales_partner')
reload_doc('stock', 'doctype', 'serial_no')
reload_doc('buying', 'doctype', 'supplier')
def reload_mapper_files():
from webnotes.modules.module_manager import reload_doc
reload_doc('Mapper', 'DocType Mapper', 'Customer Issue-Maintenance Visit')
reload_doc('Mapper', 'DocType Mapper', 'Delivery Note-Installation Note')
reload_doc('Mapper', 'DocType Mapper', 'Delivery Note-Receivable Voucher')
reload_doc('Mapper', 'DocType Mapper', 'Enquiry-Quotation')
reload_doc('Mapper', 'DocType Mapper', 'Lead-Customer')
reload_doc('Mapper', 'DocType Mapper', 'Lead-Enquiry')
reload_doc('Mapper', 'DocType Mapper', 'Purchase Order-Payable Voucher')
reload_doc('Mapper', 'DocType Mapper', 'Purchase Order-Purchase Receipt')
reload_doc('Mapper', 'DocType Mapper', 'Purchase Receipt-Payable Voucher')
reload_doc('Mapper', 'DocType Mapper', 'Quotation-Sales Order')
reload_doc('Mapper', 'DocType Mapper', 'Receivable Voucher-Delivery Note')
reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Delivery Note')
reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Maintenance Schedule')
reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Maintenance Visit')
reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Receivable Voucher')
def delete_unwanted_mapper_fields():
delete_fields = [
('Customer Issue-Maintenance Visit', 'customer_address', 'address'),
('Delivery Note-Installation Note', 'customer_address', 'address'),
('Enquiry-Quotation', 'contact_no', 'contact_no'), ('Enquiry-Quotation', 'subject', 'enq_det'), ('Enquiry-Quotation', 'customer_name', 'customer_name'), ('Enquiry-Quotation', 'customer_name', 'customer_name'), ('Enquiry-Quotation', 'address', 'customer_address'), ('Enquiry-Quotation', 'email_id', 'email_id'),
('Quotation-Sales Order', 'contact_no', 'contact_no'), ('Quotation-Sales Order', 'email_id', 'email_id'), ('Quotation-Sales Order', 'customer_mobile_no', 'customer_mobile_no'),
('Sales Order-Delivery Note', 'customer_address', 'delivery_address'), ('Sales Order-Delivery Note', 'customer_address', 'customer_address'), ('Sales Order-Delivery Note', 'contact_no', 'contact_no'), ('Sales Order-Delivery Note', 'email_id', 'email_id'), ('Sales Order-Delivery Note', 'ship_det_no', 'ship_det_no'), ('Sales Order-Delivery Note', 'ship_to', 'ship_to'), ('Sales Order-Delivery Note', 'shipping_address', 'shipping_address'), ('Sales Order-Delivery Note', 'customer_mobile_no', 'customer_mobile_no'),
('Sales Order-Maintenance Schedule', 'customer_address', 'address'),
('Sales Order-Maintenance Visit', 'customer_address', 'address'),
('Sales Order-Receivable Voucher', 'contact_no', 'contact_no')]
for rec in delete_fields:
webnotes.conn.sql("delete from `tabField Mapper Detail` where parent=%s and from_field=%s and to_field=%s",(rec[0], rec[1], rec[2]))
def sync_docfield_properties():
update_fields = [
('Contact', 'customer', 'Customer', 0L, None, 0L, None), ('Contact', 'supplier', 'Supplier', 0L, None, None, None), ('Contact', 'is_primary_contact', None, 0L, None, None, None), ('Contact', 'email_id', None, 0L, 1L, None, None), ('Contact', 'department', 'Suggest', 0L, None, None, None), ('Contact', 'designation', 'Suggest', 0L, None, None, None),
('Customer Issue', 'customer', 'Customer', 0L, 1L, 1L, None), ('Customer Issue', 'customer_address', 'Address', 0L, None, 1L, None), ('Customer Issue', 'contact_person', 'Contact', 0L, None, 1L, None), ('Customer Issue', 'customer_name', None, 1L, None, None, None), ('Customer Issue', 'company', 'Company', 0L, 1L, 1L, None), ('Customer Issue', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None),
('Delivery Note', 'customer_address', 'Address', 0L, None, 1L, None), ('Delivery Note', 'contact_person', 'Contact', 0L, None, 1L, None), ('Delivery Note', 'customer_name', None, 1L, None, None, None), ('Delivery Note', 'status', '\nDraft\nSubmitted\nCancelled', 1L, 1L, 1L, None), ('Delivery Note', 'territory', 'Territory', 0L, 1L, 1L, 0L), ('Delivery Note', 'customer_group', 'Customer Group', 0L, None, 1L, None), ('Delivery Note', 'transporter_name', None, 0L, 0L, 1L, None), ('Delivery Note', 'lr_no', None, 0L, 0L, 1L, None), ('Delivery Note', 'lr_date', None, 0L, None, 1L, None), ('Delivery Note', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Delivery Note', 'letter_head', 'link:Letter Head', 0L, None, 1L, None),
('Enquiry', 'contact_person', 'Contact', 0L, None, 1L, None), ('Enquiry', 'customer_name', None, 1L, None, 0L, None), ('Enquiry', 'lead', 'Lead', 0L, None, 1L, 0L), ('Enquiry', 'enquiry_type', '\nSales\nMaintenance', 0L, 1L, None, None), ('Enquiry', 'territory', 'Territory', 0L, 1L, 1L, None), ('Enquiry', 'customer_group', 'Customer Group', 0L, 0L, 1L, 0L), ('Enquiry', 'contact_by', 'Profile', 0L, None, None, None),
('Installation Note', 'contact_person', 'Contact', 0L, None, 1L, None), ('Installation Note', 'customer_name', None, 1L, 0L, None, None), ('Installation Note', 'territory', 'Territory', 0L, 1L, 1L, None), ('Installation Note', 'status', 'Draft\nSubmitted\nCancelled', 1L, 1L, 1L, None),
('Lead', 'city', None, 0L, 1L, 1L, None), ('Lead', 'country', 'link:Country', 0L, 1L, 1L, None), ('Lead', 'state', 'Suggest', 0L, None, 1L, None), ('Lead', 'company', 'Company', 0L, 1L, None, None), ('Lead', 'contact_by', 'Profile', 0L, 0L, 0L, 0L),
('Maintenance Schedule', 'customer', 'Customer', 0L, 1L, 1L, None), ('Maintenance Schedule', 'contact_person', 'Contact', 0L, None, 1L, None), ('Maintenance Schedule', 'status', '\nDraft\nSubmitted\nCancelled', 1L, 1L, None, None), ('Maintenance Schedule', 'territory', 'Territory', 0L, 1L, None, None),
('Maintenance Visit', 'customer', 'Customer', 0L, 1L, 1L, None), ('Maintenance Visit', 'contact_person', 'Contact', 0L, None, 1L, None), ('Maintenance Visit', 'customer_name', None, 1L, None, None, None), ('Maintenance Visit', 'company', 'link:Company', 0L, 1L, 1L, None), ('Maintenance Visit', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None), ('Maintenance Visit', 'status', '\nDraft\nCancelled\nSubmitted', 1L, 1L, None, None), ('Maintenance Visit', 'territory', 'Territory', 0L, None, 1L, None),
('Purchase Order', 'supplier_address', 'Address', 0L, None, 1L, None), ('Purchase Order', 'contact_person', 'Contact', 0L, None, 1L, None), ('Purchase Order', 'supplier_name', None, 1L, None, None, None), ('Purchase Order', 'status', '\nDraft\nSubmitted\nStopped\nCancelled', 1L, 1L, 1L, None), ('Purchase Order', 'indent_no', 'Indent', 0L, None, 1L, 0L), ('Purchase Order', 'is_subcontracted', '\nYes\nNo', 0L, None, 1L, None), ('Purchase Order', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Purchase Order', 'net_total', None, 1L, 0L, 1L, None),
('Purchase Receipt', 'supplier_address', 'Address', 0L, None, 1L, None), ('Purchase Receipt', 'contact_person', 'Contact', 0L, None, 1L, None), ('Purchase Receipt', 'supplier_name', None, 1L, None, None, None), ('Purchase Receipt', 'status', '\nDraft\nSubmitted\nCancelled', 1L, 1L, 1L, None), ('Purchase Receipt', 'currency', 'link:Currency', 0L, 1L, 1L, None),
('Quotation', 'customer', 'Customer', 0L, None, 1L, 0L), ('Quotation', 'customer_address', 'Address', 0L, None, 1L, 0L), ('Quotation', 'contact_person', 'Contact', 0L, 0L, 1L, 0L), ('Quotation', 'customer_name', None, 1L, None, None, None), ('Quotation', 'lead', 'Lead', 0L, None, 1L, 0L), ('Quotation', 'lead_name', None, 1L, None, None, None), ('Quotation', 'order_type', '\nSales\nMaintenance', 0L, 1L, 0L, None), ('Quotation', 'status', '\nDraft\nSubmitted\nOrder Confirmed\nOrder Lost\nCancelled', 1L, 1L, 1L, None), ('Quotation', 'territory', 'Territory', 0L, 1L, 1L, 0L), ('Quotation', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Quotation', 'letter_head', 'link:Letter Head', 0L, None, 1L, None), ('Quotation', 'order_lost_reason', None, 1L, None, 1L, None), ('Quotation', 'contact_by', 'Profile', 0L, None, 1L, None), ('Quotation', 'contact_date', None, 0L, None, 1L, None), ('Quotation', 'to_discuss', None, 0L, None, 1L, None),
('Receivable Voucher', 'debit_to', 'Account', 0L, 1L, 1L, None), ('Receivable Voucher', 'customer_address', 'Address', 0L, None, 1L, None), ('Receivable Voucher', 'territory', 'Territory', 0L, 1L, 1L, None), ('Receivable Voucher', 'paid_amount', None, 0L, None, 1L, None), ('Receivable Voucher', 'company', 'Company', 0L, 1L, 1L, None), ('Receivable Voucher', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None), ('Receivable Voucher', 'outstanding_amount', None, 1L, None, 1L, None),
('Payable Voucher', 'supplier_address', 'Address', 0L, None, 1L, None), ('Payable Voucher', 'contact_display', None, 1L, None, None, None), ('Payable Voucher', 'contact_mobile', None, 1L, None, None, None), ('Payable Voucher', 'contact_email', None, 1L, None, 1L, None), ('Payable Voucher', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Payable Voucher', 'conversion_rate', None, 0L, 1L, 1L, None), ('Payable Voucher', 'company', 'Company', 0L, 1L, 1L, None), ('Payable Voucher', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None),
('Sales Order', 'customer_address', 'Address', 0L, None, 1L, 0L), ('Sales Order', 'contact_person', 'Contact', 0L, None, 1L, None), ('Sales Order', 'customer_name', None, 1L, None, None, None), ('Sales Order', 'status', '\nDraft\nSubmitted\nStopped\nCancelled', 1L, 1L, 1L, None), ('Sales Order', 'quotation_date', None, 1L, 0L, 1L, 1L), ('Sales Order', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Sales Order', 'letter_head', 'link:Letter Head', 0L, None, 1L, None),
('Sales Partner', 'territory', 'Territory', 0L, 1L, None, None),
('Supplier', 'company', 'Company', 0L, 1L, None, None)]
for rec in update_fields:
webnotes.conn.sql("UPDATE `tabDocField` SET options=%s, permlevel=%s, reqd=%s, print_hide=%s, hidden=%s where parent=%s and fieldname=%s",(rec[2], rec[3], rec[4], rec[5], rec[6], rec[0], rec[1]))
def run_patch():
make_address()
make_address_from_customer()
make_address_from_supplier()
make_contact_from_contacttab()
delete_unwanted_fields()
reload_doc_files()
reload_mapper_files()
delete_unwanted_mapper_fields()
sync_docfield_properties()
#Old Customer Data Sync Patch for "Quotation, SO, PO, RV, PV, DN, PR, Installation Note, Maintenance Schedule, Customer Issue, Maintenance Visit"
#--------------------------------------------------------------
def run_old_data_sync_patch():
sync_quotation_customer_data()
sync_sales_order_customer_data()
sync_purchase_order_supplier_data()
sync_receivable_voucher_customer_data()
sync_payable_voucher_supplier_data()
sync_delivery_note_customer_data()
sync_purchase_receipt_supplier_data()
sync_installation_note_customer_data()
sync_maintenance_schedule_customer_data()
sync_customer_issue_customer_data()
sync_maintenance_visit_customer_data()
sync_lead_phone()
#Quotation
def sync_quotation_customer_data():
data_rec = webnotes.conn.sql("""
SELECT tq.name as id,tq.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM tabQuotation tq, tabAddress ta
WHERE tq.customer = ta.customer
AND tq.quotation_to = 'Customer'
AND tq.docstatus !=2
ORDER BY tq.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE tabQuotation SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT tq.name as id,tq.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM tabQuotation tq, tabContact tc
WHERE tq.customer = tc.customer
AND tq.quotation_to = 'Customer'
AND tq.docstatus !=2
ORDER BY tq.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE tabQuotation SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Sales Order
def sync_sales_order_customer_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabSales Order` t, tabAddress ta
WHERE t.customer = ta.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Phone: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabSales Order` SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabSales Order` t, tabContact tc
WHERE t.customer = tc.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabSales Order` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Purchase Order
def sync_purchase_order_supplier_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.supplier,
ta.name as supplier_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabPurchase Order` t, tabAddress ta
WHERE t.supplier = ta.supplier
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabPurchase Order` SET
supplier_address = %s,
address_display = %s
WHERE name = %s
""",(rec['supplier_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.supplier,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabPurchase Order` t, tabContact tc
WHERE t.supplier = tc.supplier
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabPurchase Order` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Sales Invoice
def sync_receivable_voucher_customer_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabReceivable Voucher` t, tabAddress ta
WHERE t.customer = ta.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabReceivable Voucher` SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabReceivable Voucher` t, tabContact tc
WHERE t.customer = tc.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabReceivable Voucher` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Purchase Invoice
def sync_payable_voucher_supplier_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.supplier,
ta.name as supplier_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabPayable Voucher` t, tabAddress ta
WHERE t.supplier = ta.supplier
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabPayable Voucher` SET
supplier_address = %s,
address_display = %s
WHERE name = %s
""",(rec['supplier_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.supplier,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabPayable Voucher` t, tabContact tc
WHERE t.supplier = tc.supplier
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabPayable Voucher` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Delivery Note
def sync_delivery_note_customer_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabDelivery Note` t, tabAddress ta
WHERE t.customer = ta.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabDelivery Note` SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabDelivery Note` t, tabContact tc
WHERE t.customer = tc.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabDelivery Note` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Purchase Receipt
def sync_purchase_receipt_supplier_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.supplier,
ta.name as supplier_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabPurchase Receipt` t, tabAddress ta
WHERE t.supplier = ta.supplier
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabPurchase Receipt` SET
supplier_address = %s,
address_display = %s
WHERE name = %s
""",(rec['supplier_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.supplier,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabPurchase Receipt` t, tabContact tc
WHERE t.supplier = tc.supplier
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabPurchase Receipt` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Installation Note
def sync_installation_note_customer_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabInstallation Note` t, tabAddress ta
WHERE t.customer = ta.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabInstallation Note` SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabInstallation Note` t, tabContact tc
WHERE t.customer = tc.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabInstallation Note` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Maintenance Schedule
def sync_maintenance_schedule_customer_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabMaintenance Schedule` t, tabAddress ta
WHERE t.customer = ta.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabMaintenance Schedule` SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabMaintenance Schedule` t, tabContact tc
WHERE t.customer = tc.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabMaintenance Schedule` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Customer Issue
def sync_customer_issue_customer_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabCustomer Issue` t, tabAddress ta
WHERE t.customer = ta.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabCustomer Issue` SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabCustomer Issue` t, tabContact tc
WHERE t.customer = tc.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabCustomer Issue` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#Maintenance Visit
def sync_maintenance_visit_customer_data():
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
FROM `tabMaintenance Visit` t, tabAddress ta
WHERE t.customer = ta.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
webnotes.conn.sql("""
UPDATE `tabMaintenance Visit` SET
customer_address = %s,
address_display = %s
WHERE name = %s
""",(rec['customer_address'],address_display,rec['id']))
data_rec = webnotes.conn.sql("""
SELECT t.name as id,t.customer,
tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
FROM `tabMaintenance Visit` t, tabContact tc
WHERE t.customer = tc.customer
AND t.docstatus !=2
ORDER BY t.name
""", as_dict=1)
for rec in data_rec:
contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
webnotes.conn.sql("""
UPDATE `tabMaintenance Visit` SET
contact_person = %s,
contact_mobile = %s,
contact_email = %s,
contact_display = %s
WHERE name = %s
""",(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
#lead phone data sync
def sync_lead_phone():
webnotes.conn.sql("""
update ignore tabLead set
phone = contact_no
where contact_no is not null
""")

View File

@@ -1,74 +0,0 @@
import webnotes
def set_doctype_permissions():
# remove descriptions
webnotes.conn.sql("update tabDocType set description=null")
from webnotes.modules.module_manager import reload_doc
reload_doc('core','doctype','custom_script')
reload_doc('core','doctype','custom_field')
reload_doc('core','doctype','property_setter')
# remove admin rights
webnotes.conn.sql("delete from tabUserRole where role in ('Administrator','Customer','Supplier') and parent!='Administrator'")
# create custom scripts
create_custom_scripts()
# remove script fields
reload_doc('core','doctype','doctype')
# allow sys manager to read doctype, custom script
allow_sys_manager()
def create_custom_scripts():
cs_list = webnotes.conn.sql("select name, server_code, client_script from tabDocType where ifnull(server_code,'')!='' or ifnull(client_script,'')!=''")
from webnotes.model.doc import Document
for c in cs_list:
if c[1]:
cs = Document('Custom Script')
cs.dt = c[0]
cs.script_type = 'Server'
cs.script = c[1]
try:
cs.save(1)
except NameError:
pass
if c[2]:
cs = Document('Custom Script')
cs.dt = c[0]
cs.script_type = 'Client'
cs.script = c[2]
try:
cs.save(1)
except NameError:
pass
def allow_sys_manager():
from webnotes.model.doc import Document
if not webnotes.conn.sql("select name from tabDocPerm where parent='DocType' and role='System Manager' and `read`=1"):
d = Document('DocPerm')
d.parent = 'DocType'
d.parenttype = 'DocType'
d.parentfield = 'permissions'
d.role = 'System Manager'
d.read = 1
d.save(1)
if not webnotes.conn.sql("select name from tabDocPerm where parent='Custom Script' and role='System Manager' and `write`=1"):
d = Document('DocPerm')
d.parent = 'Custom Script'
d.parenttype = 'DocType'
d.parentfield = 'permissions'
d.role = 'System Manager'
d.read = 1
d.write = 1
d.create = 1
d.save(1)

View File

@@ -1,102 +0,0 @@
# long patches
import webnotes
def set_subjects_and_tagfields():
subject_dict = {
'Item':'%(item_name)s',
'Customer':' ',
'Contact':'%(first_name)s %(last_name)s - Email: %(email_id)s | Contact: %(contact_no)s',
'Supplier':' ',
'Lead':'%(lead_name)s from %(company_name)s | To Discuss: %(to_discuss)s',
'Quotation':'To %(customer_name)s on %(transaction_date)s worth %(currency)s %(grand_total_export)s',
'Enquiry':'To %(customer_name)s%(lead_name)s on %(transaction_date)s',
'Sales Order':'From %(customer_name)s on %(transaction_date)s worth %(currency)s %(grand_total_export)s | %(per_delivered)s% delivered | %(per_billed)s% billed',
'Delivery Note':'To %(customer_name)s on %(transaction_date)s | %(per_billed)s% billed',
'Indent':'%(per_ordered)s% ordered',
'Purchase Order':'To %(supplier_name)s on %(transaction_date)s | %(per_received)s% delivered',
'Purchase Receipt':'From %(supplier_name)s against %(purchase_order)s on %(transaction_date)s',
'Receivable Voucher':'To %(customer_name)s worth %(currency)s %(grand_total_export)s due on %(due_date)s | %(outstanding_amount)s outstanding',
'Payable Voucher':'From %(supplier_name)s due on %(due_date)s | %(outstanding_amount)s outstanding',
'Journal Voucher':' ',
'Serial No':'%(item_code)s',
'Project':' ',
'Ticket':'%(subject)s',
'Timesheet':'%(owner)s',
'Support Ticket':'%(problem_description)s',
'Installation Note':'At %(customer_name)s on %(inst_date)s',
'Maintenance Visit':'To %(customer_name)s on %(mntc_date)s',
'Customer Issue':'%(complaint)s By %(complaint_raised_by)s on %(issue_date)s',
'Employee':'%(employee_name)s',
'Expense Voucher':'From %(employee_name)s for %(total_claimed_amount)s (claimed)',
'Appraisal':'',
'Leave Application':'From %(employee_name)s, %(designation)s',
'Salary Structure':'For %(employee_name)s',
'Salary Slip':'For %(employee_name)s, %(designation)s',
'Bill of Materials':'%(item_code)s'
}
tags_dict = {
'Item':'item_group',
'Customer':'customer_group,customer_type',
#'Contact':'',
'Supplier':'supplier_type',
'Lead':'status,source',
'Quotation':'status',
'Enquiry':'',
'Sales Order':'status',
'Delivery Note':'',
'Indent':'',
'Purchase Order':'',
'Purchase Receipt':'',
'Receivable Voucher':'',
'Payable Voucher':'',
'Journal Voucher':'voucher_type',
'Serial No':'status',
'Project':'status',
'Ticket':'status',
'Timesheet':'',
'Support Ticket':'',
'Installation Note':'',
'Maintenance Visit':'completion_status,maintenance_type',
'Customer Issue':'status',
'Employee':'status',
'Expense Voucher':'approval_status',
'Appraisal':'',
'Leave Application':'leave_type',
'Salary Structure':'',
'Bill of Materials':''
}
description_dict = {
'Property Setter':'Property Setter overrides a standard DocType or Field property',
'Custom Field':'Adds a custom field to a DocType',
'Custom Script':'Adds a custom script (client or server) to a DocType'
}
alldt = []
for dt in subject_dict:
webnotes.conn.sql('update tabDocType set subject=%s where name=%s', (subject_dict[dt], dt))
if not dt in alldt: alldt.append(dt)
for dt in tags_dict:
webnotes.conn.sql('update tabDocType set tag_fields=%s where name=%s', (tags_dict[dt], dt))
if not dt in alldt: alldt.append(dt)
for dt in description_dict:
webnotes.conn.sql('update tabDocType set description=%s where name=%s', (description_dict[dt], dt))
if not dt in alldt: alldt.append(dt)
#from webnotes.modules.export_module import export_to_files
#for dt in alldt:
# export_to_files(record_list=[['DocType',dt]])
def support_patch():
# relaod support and other doctypes
from webnotes.modules.module_manager import reload_doc
webnotes.model.delete_doc('DocType','Support Ticket')
reload_doc('setup','doctype','support_email_settings')
reload_doc('support','doctype','support_ticket')
reload_doc('support','doctype','support_ticket_response')

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +0,0 @@
import os
def replace_code(old, new):
txt = os.popen("""grep "%s" ./*/*/*/*.js""" % old).read().split()
txt = [t.split(':')[0] for t in txt]
txt = list(set(filter(lambda t: t.startswith('./'), txt)))
for t in txt:
if new:
code = open(t,'r').read().replace(old, new)
open(t, 'w').write(code)
print "Replaced for %s" % t
else:
print 'Found in %s' % t
if __name__=='__main__':
old = """cur_frm.cscript.get_tips(doc, cdt, cdn);"""
new = " "
replace_code(old, new)

View File

@@ -1,306 +0,0 @@
# REMEMBER to update this
# ========================
last_patch = 355
#-------------------------------------------
def execute(patch_no):
import webnotes
from webnotes.modules.module_manager import reload_doc
from webnotes.model.code import get_obj
sql = webnotes.conn.sql
from webnotes.utils import cint, cstr, flt
from webnotes.model.doc import Document
from webnotes.model import delete_doc
if patch_no == 301:
from patches.delivery_billing_status_patch import run_patch
run_patch()
elif patch_no == 302:
sql("update `tabDocField` set no_copy = 1 where fieldname = 'naming_series'")
elif patch_no == 303:
pass
elif patch_no == 304:
sql("delete from `tabDocField` where parent = 'company' and label = 'Trash Company' and fieldtype = 'button'")
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('utilities', 'doctype', 'rename_tool')
elif patch_no == 307:
sql("delete from `tabDocField` where parent = 'company' and label = 'Trash Company' and fieldtype = 'Button'")
reload_doc('setup', 'doctype', 'company')
elif patch_no == 308:
sql("update `tabDocField` set reqd = 0 where fieldname = 'select_item' and parent = 'Property Setter'")
elif patch_no == 309:
sql("delete from `tabDocField` where fieldname = 'item_attachments_details' and parent = 'Item'")
sql("delete from `tabModule Def Item` where parent = 'Stock' and doc_name = 'Landed Cost Wizard'")
elif patch_no == 310:
from erpnext_structure_cleanup import run_patches
run_patches()
elif patch_no == 311:
sql("update `tabDocField` set reqd = 0 where fieldname = 'select_item' and parent = 'Property Setter'")
#reload_doc('core', 'doctype', 'property_setter')
elif patch_no == 312:
sql("delete from `tabSessions`")
sql("delete from `__SessionCache`")
elif patch_no == 313:
dt = ['GL Entry', 'Stock Ledger Entry']
for t in dt:
rec = sql("select voucher_type, voucher_no, ifnull(is_cancelled, 'No') from `tab%s` where modified >= '2011-07-06 10:00:00' group by voucher_no" % t)
for d in rec:
sql("update `tab%s` set docstatus = %s where name = '%s'" % (d[0], d[2]=='No' and 1 or 2, d[1]))
other_dt = ['Enquiry', 'Quotation', 'Sales Order', 'Indent', 'Purchase Order', 'Production Order', 'Customer Issue', 'Installation Note']
for dt in other_dt:
rec = sql("select name, status from `tab%s` where modified >= '2011-07-06 10:00:00'" % dt)
for r in rec:
sql("update `tab%s` set docstatus = %s where name = '%s'" % (dt, (r[1] in ['Submitted', 'Closed'] and 1 or r[1]=='Cancelled' and 2 or 0), r[0]))
dt_list = ['Delivery Note', 'Purchase Receipt']
for dt in dt_list:
sql("update `tab%s` set status = 'Submitted' where docstatus = 1 and modified >='2011-07-06 10:00:00'" % dt)
sql("update `tab%s` set status = 'Cancelled' where docstatus = 2 and modified >='2011-07-06 10:00:00'" % dt)
dt_list = ['Enquiry', 'Quotation', 'Sales Order', 'Indent', 'Purchase Order', 'Production Order', 'Customer Issue', 'Installation Note', 'Receivable Voucher', 'Payable Voucher', 'Delivery Note', 'Purchase Receipt', 'Journal Voucher', 'Stock Entry']
for d in dt_list:
tbl = sql("select options from `tabDocField` where fieldtype = 'Table' and parent = '%s'" % d)
for t in tbl:
sql("update `tab%s` t1, `tab%s` t2 set t1.docstatus = t2.docstatus where t1.parent = t2.name" % (t[0], d))
elif patch_no == 314:
# delete double feed
sql("delete from tabFeed where subject like 'New %'")
elif patch_no == 315:
# delete double feed
sql("delete from tabFeed where doc_name like 'New %'")
reload_doc('core', 'doctype', 'property_setter')
from webnotes.model.doc import Document
m = Document('Module Def Role')
m.role = 'All'
m.parent = 'Home'
m.parenttype = 'Module Def'
m.parentfield = 'roles'
m.save(1)
elif patch_no == 316:
pass
elif patch_no == 317:
sql("update `tabPage` set name = 'profile-settings' where page_name = 'Profile Settings'")
elif patch_no == 318:
reload_doc('utilities', 'doctype', 'bulk_rename_tool')
elif patch_no == 319:
sql("delete from tabFeed where doc_name like 'New %'")
elif patch_no == 320:
reload_doc('setup', 'doctype', 'series_detail')
elif patch_no == 321:
reload_doc('hr','doctype','leave_application')
elif patch_no == 322:
sql("delete from `tabDocField` where parent = 'Leave Application' and fieldname = 'latter_head'")
elif patch_no == 323:
reload_doc('stock', 'doctype', 'stock_entry')
sql("update `tabDocField` set options = 'get_stock_and_rate' where parent = 'Stock Entry' and label = 'Get Stock and Rate'")
sql("delete from `tabDocField` where label = 'Get Current Stock' and parent = 'Stock Entry'")
elif patch_no == 324:
sql("delete from `tabDocField` where fieldname = 'test_field' and parent = 'Customer'")
elif patch_no == 325:
sql("update `tabDocField` set fieldtype = 'Data' where parent = 'Salary Slip' and fieldname = 'total_days_in_month'")
reload_doc('hr', 'doctype', 'salary_slip')
elif patch_no == 326:
# load the new billing page
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
reload_doc('server_tools','page','billing')
elif patch_no == 327:
# patch for support email settings now moved to email settings
reload_doc('setup','doctype','email_settings')
# map fields from support to email settings
field_map = {
'support_email': 'email',
'support_host':'host',
'support_username': 'username',
'support_password': 'password',
'support_use_ssl': 'use_ssl',
'sync_support_mails': 'integrate_incoming',
'signature': 'support_signature'
}
for key in field_map:
webnotes.conn.set_value('Email Settings',None,key, \
webnotes.conn.get_value('Support Email Settings',None,field_map[key]))
# delete support email settings
delete_doc('DocType', 'Support Email Settings')
reload_doc('support','doctype','support_ticket')
sql("delete from tabDocField where fieldname='problem_description' and parent='Support Ticket'")
elif patch_no == 328:
if webnotes.conn.get_value('Control Panel', None, 'account_id') != 'axjanak2011':
sql("delete from `tabDocField` where fieldname = 'supplier_status' and parent = 'Supplier'")
elif patch_no == 329:
reload_doc('utilities', 'doctype', 'rename_tool')
reload_doc('utilities', 'doctype', 'bulk_rename_tool')
elif patch_no == 330:
reload_doc('accounts', 'doctype', 'lease_agreement')
reload_doc('accounts', 'doctype', 'lease_installment')
reload_doc('accounts', 'search_criteria', 'lease_agreement_list')
reload_doc('accounts', 'search_criteria', 'lease_monthly_future_installment_inflows')
reload_doc('accounts', 'search_criteria', 'lease_overdue_age_wise')
reload_doc('accounts', 'search_criteria', 'lease_over_due_list')
reload_doc('accounts', 'search_criteria', 'lease_receipts_client_wise')
reload_doc('accounts', 'search_criteria', 'lease_receipt_summary_year_to_date')
reload_doc('accounts', 'search_criteria', 'lease_yearly_future_installment_inflows')
reload_doc('accounts', 'Module Def', 'Accounts')
elif patch_no == 331:
p = get_obj('Patch Util')
# permission
p.add_permission('Lease Agreement', 'Accounts Manager', 0, read = 1, write=1,submit=1, cancel=1,amend=1)
p.add_permission('Lease Agreement', 'Accounts Manager', 1, read = 1)
elif patch_no == 332:
sql("update `tabDocField` set permlevel=1, hidden = 1 where parent = 'Bulk Rename Tool' and fieldname = 'file_list'")
elif patch_no == 333:
sql("update `tabDocPerm` set `create` =1 where role = 'Accounts Manager' and parent = 'Lease Agreement'")
p = get_obj('Patch Util')
p.add_permission('DocType Mapper', 'System Manager', 0, read = 1, write=1, create=1)
p.add_permission('Role', 'System Manager', 0, read = 1, write=1, create=1)
p.add_permission('Print Format', 'System Manager', 0, read = 1, write=1, create=1)
elif patch_no == 334:
reload_doc('knowledge_base', 'doctype', 'answer')
elif patch_no == 335:
for dt in ['Account', 'Cost Center', 'Territory', 'Item Group', 'Customer Group']:
sql("update `tabDocField` set fieldtype = 'Link', options = %s where fieldname = 'old_parent' and parent = %s", (dt, dt))
elif patch_no == 336:
reload_doc('server_tools','page','billing')
elif patch_no == 337:
item_list = webnotes.conn.sql("""SELECT name, description_html
FROM tabItem""")
if item_list:
for item, html in item_list:
if html and "getfile" in html and "acx" in html:
ac_id = webnotes.conn.sql("""SELECT value FROM `tabSingles` WHERE doctype='Control Panel' AND field='account_id'""")
sp_acx = html.split("acx=")
l_acx = len(sp_acx)
if l_acx > 1:
for i in range(l_acx-1):
sp_quot = sp_acx[i+1].split('"')
if len(sp_quot) > 1: sp_quot[0] = str(ac_id[0][0])
sp_acx[i+1] = '"'.join(sp_quot)
html = "acx=".join(sp_acx)
webnotes.conn.sql("""UPDATE tabItem SET description_html=%s WHERE name=%s""", (html, item))
elif patch_no == 338:
# Patch for billing status based on amount
# reload so and dn
reload_doc('selling','doctype','sales_order')
reload_doc('stock','doctype','delivery_note')
# delete billed_qty field
sql("delete from `tabDocField` where fieldname = 'billed_qty' and parent in ('Sales Order Detail', 'Delivery Note Detail')")
# update billed amt in item table in so and dn
sql(""" update `tabSales Order Detail` so
set billed_amt = (select sum(amount) from `tabRV Detail` where `so_detail`= so.name and docstatus=1 and parent not like 'old%%'), modified = now()""")
sql(""" update `tabDelivery Note Detail` dn
set billed_amt = (select sum(amount) from `tabRV Detail` where `dn_detail`= dn.name and docstatus=1 and parent not like 'old%%'), modified = now()""")
# calculate % billed based on item table
sql(""" update `tabSales Order` so
set per_billed = (select sum(if(amount > ifnull(billed_amt, 0), billed_amt, amount))/sum(amount)*100 from `tabSales Order Detail` where parent = so.name), modified = now()""")
sql(""" update `tabDelivery Note` dn
set per_billed = (select sum(if(amount > ifnull(billed_amt, 0), billed_amt, amount))/sum(amount)*100 from `tabDelivery Note Detail` where parent = dn.name), modified = now()""")
# update billing status based on % billed
sql("""update `tabSales Order` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
sql("""update `tabDelivery Note` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
# update name of questions page
sql("update tabPage set name='questions' where name='Questions'")
sql("update tabPage set name='question-view' where name='Question View'")
elif patch_no == 339:
reload_doc('production','doctype','bill_of_materials')
elif patch_no == 340:
sql("update `tabDocField` set permlevel = 0 where (fieldname in ('process', 'production_order', 'fg_completed_qty') or label = 'Get Items') and parent = 'Stock Entry'")
elif patch_no == 341:
reload_doc('stock','doctype','delivery_note')
reload_doc('stock','doctype','item')
reload_doc('selling','doctype','quotation')
reload_doc('stock','Print Format','Delivery Note Packing List Wise')
if not sql("select format from `tabDocFormat` where name = 'Delivery Note Packing List Wise' and parent = 'Delivery Note'"):
from webnotes.model.doc import addchild
dt_obj = get_obj('DocType', 'Delivery Note', with_children = 1)
ch = addchild(dt_obj.doc, 'formats', 'DocFormat', 1)
ch.format = 'Delivery Note Packing List Wise'
ch.save(1)
elif patch_no == 342:
sql("update `tabDocField` set permlevel = 0 where parent = 'Stock Entry Detail' and fieldname in ('s_warehouse', 't_warehouse', 'fg_item')")
elif patch_no == 343:
reload_doc('stock','doctype','item_customer_detail')
elif patch_no == 344:
sql("delete from `tabDocFormat` where ifnull(format, '') = '' and parent = 'Delivery Note'")
elif patch_no == 345:
# rerun 343 (merge confict)
reload_doc('stock','doctype','item_customer_detail')
sql("delete from `tabModule Def Item` where display_name = 'Salary Slip Control Panel' and parent = 'HR'")
reload_doc('hr','Module Def','HR')
elif patch_no == 346:
pass
elif patch_no == 347:
sql("delete from `tabField Mapper Detail` where from_field = to_field and map = 'Yes' and ifnull(checking_operator, '') = ''")
elif patch_no == 348:
sql("update `tabStock Ledger Entry` set is_cancelled = 'No' where voucher_type = 'Serial No'")
elif patch_no == 349:
delete_doc('Custom Script', 'Update Series-Server')
delete_doc('Custom Script', 'Profile-Client')
delete_doc('Custom Script', 'Event-Client')
delete_doc('Custom Script', 'File-Server')
# reload profile with new fields for security
delete_doc('DocType', 'Profile')
reload_doc('core', 'doctype', 'profile')
elif patch_no == 350:
reload_doc('stock', 'doctype', 'delivery_note_detail')
reload_doc('stock', 'doctype', 'item_customer_detail')
elif patch_no == 351:
reload_doc('home', 'page', 'dashboard')
elif patch_no == 352:
reload_doc('stock','doctype','delivery_note')
reload_doc('stock','doctype','item')
reload_doc('selling','doctype','quotation')
reload_doc('stock','Print Format','Delivery Note Packing List Wise')
if not sql("select format from `tabDocFormat` where name = 'Delivery Note Packing List Wise' and parent = 'Delivery Note'"):
from webnotes.model.doc import addchild
dt_obj = get_obj('DocType', 'Delivery Note', with_children = 1)
ch = addchild(dt_obj.doc, 'formats', 'DocFormat', 1)
ch.format = 'Delivery Note Packing List Wise'
ch.save(1)
elif patch_no == 353:
reload_doc('hr', 'doctype', 'salary_manager')
elif patch_no == 354:
reload_doc('setup', 'doctype','feature_setup')
reload_doc('stock','doctype','item')
sql("update tabDocField set label='Produced Qty',description='Updated after finished goods are transferred to FG Warehouse through Stock Entry' where parent='Production Order' and fieldname='produced_qty'")
rs = sql("select fieldname from tabDocField where parent='Features Setup' and fieldname is not null")
from webnotes.model.doc import Document
m = Document('Features Setup')
for d in rs:
m.fields[d[0]] = 1
m.save()
elif patch_no == 355:
reload_doc('hr', 'doctype', 'salary_slip')
delete_doc('DocType', 'Salary Control Panel')