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

@@ -1,31 +0,0 @@
// ======================= OnLoad =============================================
cur_frm.cscript.onload = function(doc,cdt,cdn){
if(!doc.status) set_multiple(cdt,cdn,{status:'Draft'});
if(!doc.timesheet_date) set_multiple(cdt,cdn,{timesheet_date:get_today()});
}
cur_frm.cscript.refresh = function(doc,cdt,cdn){}
cur_frm.fields_dict['timesheet_details'].grid.get_field("project_name").get_query = function(doc,cdt,cdn){
var cond=cond1='';
var d = locals[cdt][cdn];
//if(d.customer_name) cond = 'ifnull(`tabProject`.customer_name, "") = "'+d.customer_name+'" AND';
if(d.task_id) cond1 = 'ifnull(`tabTicket`.project, "") = `tabProject`.name AND `tabTicket`.name = "'+d.task_id+'" AND';
return repl('SELECT distinct `tabProject`.`name` FROM `tabProject`, `tabTicket` WHERE %(cond1)s `tabProject`.`name` LIKE "%s" ORDER BY `tabProject`.`name` ASC LIMIT 50', {cond1:cond1});
}
cur_frm.cscript.task_name = function(doc, cdt, cdn){
var d = locals[cdt][cdn];
if(d.task_name) get_server_fields('get_task_details', d.task_name, 'timesheet_details', doc, cdt, cdn, 1);
}
cur_frm.fields_dict['timesheet_details'].grid.get_field("task_name").get_query = function(doc,cdt,cdn){
var cond='';
var d = locals[cdt][cdn];
if(d.project_name) cond = 'ifnull(`tabTicket`.project, "") = "'+d.project_name+'" AND';
return repl('SELECT distinct `tabTicket`.`subject` FROM `tabTicket` WHERE %(cond)s `tabTicket`.`subject` LIKE "%s" ORDER BY `tabTicket`.`subject` ASC LIMIT 50', {cond:cond});
}

View File

@@ -1,81 +0,0 @@
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
class DocType:
def __init__(self,doc,doclist=[]):
self.doc = doc
self.doclist = doclist
def get_customer_details(self, project_name):
cust = sql("select customer, customer_name from `tabProject` where name = %s", project_name)
if cust:
ret = {'customer': cust and cust[0][0] or '', 'customer_name': cust and cust[0][1] or ''}
return (ret)
def get_task_details(self, task_sub):
tsk = sql("select name, project, customer, customer_name from `tabTicket` where subject = %s", task_sub)
if tsk:
ret = {'task_id': tsk and tsk[0][0] or '', 'project_name': tsk and tsk[0][1] or '', 'customer_name': tsk and tsk[0][3] or ''}
return ret
def validate(self):
if getdate(self.doc.timesheet_date) > getdate(nowdate()):
msgprint("You can not prepare timesheet for future date")
raise Exception
chk = sql("select name from `tabTimesheet` where timesheet_date=%s and owner=%s and status!='Cancelled' and name!=%s", (self.doc.timesheet_date, self.doc.owner, self.doc.name))
if chk:
msgprint("You have already created timesheet "+ cstr(chk and chk[0][0] or '')+" for this date.")
raise Exception
import time
for d in getlist(self.doclist, 'timesheet_details'):
if d.act_start_time and d.act_end_time:
d1 = time.strptime(d.act_start_time, "%H:%M")
d2 = time.strptime(d.act_end_time, "%H:%M")
if d1 > d2:
msgprint("Start time can not be greater than end time. Check for Task Id : "+cstr(d.task_id))
raise Exception
elif d1 == d2:
msgprint("Start time and end time can not be same. Check for Task Id : "+cstr(d.task_id))
raise Exception
def calculate_total_hr(self):
import datetime
import time
for d in getlist(self.doclist, 'timesheet_details'):
x1 = d.act_start_time.split(":")
x2 = d.act_end_time.split(":")
d1 = datetime.timedelta(minutes=cint(x1[1]), hours=cint(x1[0]))
d2 = datetime.timedelta(minutes=cint(x2[1]), hours=cint(x2[0]))
d3 = (d2 - d1).seconds
d.act_total_hrs = time.strftime("%H:%M", time.gmtime(d3))
sql("update `tabTimesheet Detail` set act_total_hrs = %s where parent=%s and name=%s", (d.act_total_hrs,self.doc.name,d.name))
def on_update(self):
self.calculate_total_hr()
set(self.doc, 'status', 'Draft')
def on_submit(self):
set(self.doc, 'status', 'Submitted')
def on_cancel(self):
set(self.doc, 'status', 'Cancelled')

View File

@@ -1,219 +0,0 @@
# DocType, Timesheet
[
# These values are common in all dictionaries
{
'creation': '2010-12-14 10:23:29',
'docstatus': 0,
'modified': '2011-02-23 11:22:29',
'modified_by': 'Administrator',
'owner': 'ashwini@webnotestech.com'
},
# These values are common for all DocType
{
'autoname': 'TimeSheet.#####',
'colour': 'White:FFF',
'doctype': 'DocType',
'module': 'Projects',
'name': '__common__',
'search_fields': 'status, owner, timesheet_date',
'section_style': 'Simple',
'server_code_error': ' ',
'subject': '%(owner)s',
'version': 68
},
# These values are common for all DocField
{
'doctype': 'DocField',
'name': '__common__',
'parent': 'Timesheet',
'parentfield': 'fields',
'parenttype': 'DocType'
},
# These values are common for all DocPerm
{
'doctype': 'DocPerm',
'name': '__common__',
'parent': 'Timesheet',
'parentfield': 'permissions',
'parenttype': 'DocType',
'read': 1
},
# DocType, Timesheet
{
'doctype': 'DocType',
'name': 'Timesheet'
},
# DocPerm
{
'amend': 1,
'cancel': 1,
'create': 1,
'doctype': 'DocPerm',
'permlevel': 0,
'role': 'Projects User',
'submit': 1,
'write': 1
},
# DocPerm
{
'doctype': 'DocPerm',
'permlevel': 1,
'role': 'Projects User'
},
# DocPerm
{
'amend': 1,
'cancel': 1,
'create': 1,
'doctype': 'DocPerm',
'idx': 1,
'permlevel': 0,
'role': 'System Manager',
'submit': 1,
'write': 1
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 2,
'permlevel': 1,
'role': 'System Manager'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 1,
'label': 'Timesheet Details',
'permlevel': 0
},
# DocField
{
'colour': 'White:FFF',
'default': 'Draft',
'doctype': 'DocField',
'fieldname': 'status',
'fieldtype': 'Select',
'idx': 2,
'in_filter': 0,
'label': 'Status',
'oldfieldname': 'status',
'oldfieldtype': 'Select',
'options': '\nDraft\nSubmitted\nCancelled',
'permlevel': 1,
'reqd': 1,
'search_index': 1
},
# DocField
{
'colour': 'White:FFF',
'default': 'Today',
'doctype': 'DocField',
'fieldname': 'timesheet_date',
'fieldtype': 'Date',
'idx': 3,
'in_filter': 1,
'label': 'Timesheet Date',
'oldfieldname': 'timesheet_date',
'oldfieldtype': 'Date',
'permlevel': 0,
'reqd': 1,
'search_index': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'owner',
'fieldtype': 'Link',
'idx': 4,
'in_filter': 1,
'label': 'Timesheet By',
'oldfieldname': 'owner',
'oldfieldtype': 'Link',
'options': 'Profile',
'permlevel': 0,
'reqd': 1,
'search_index': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'amended_from',
'fieldtype': 'Data',
'hidden': 1,
'idx': 5,
'label': 'Amended From',
'oldfieldname': 'amended_from',
'oldfieldtype': 'Data',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'amendment_date',
'fieldtype': 'Date',
'hidden': 1,
'idx': 6,
'label': 'Amendment Date',
'oldfieldname': 'amendment_date',
'oldfieldtype': 'Date',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 7,
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'notes',
'fieldtype': 'Text',
'idx': 8,
'label': 'Notes',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 9,
'options': 'Simple',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'timesheet_details',
'fieldtype': 'Table',
'idx': 10,
'label': 'Timesheet Details',
'oldfieldname': 'timesheet_details',
'oldfieldtype': 'Table',
'options': 'Timesheet Detail',
'permlevel': 0
}
]