blob: 2242d6b62910f75dfcb0a44306ad9e581a86b218 [file] [log] [blame]
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +05301import webnotes
2
3def execute():
4 # convert timesheet details to time logs
Rushabh Mehta3e712f22013-03-04 16:21:54 +05305 webnotes.reload_doc("projects", "doctype", "time_log")
6
7 # copy custom fields
8 custom_map = {"Timesheet":[], "Timesheet Detail":[]}
9 for custom_field in webnotes.conn.sql("""select * from `tabCustom Field` where
10 dt in ('Timesheet', 'Timesheet Detail')""", as_dict=True):
11 custom_map[custom_field.dt].append(custom_field.fieldname)
12 custom_field.doctype = "Custom Field"
13 custom_field.dt = "Time Log"
14 custom_field.insert_after = None
Rushabh Mehta986d48b2013-03-04 16:29:48 +053015 try:
16 cf = webnotes.bean(custom_field).insert()
17 except Exception, e:
18 # duplicate custom field
19 pass
Rushabh Mehta3e712f22013-03-04 16:21:54 +053020
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +053021 for name in webnotes.conn.sql_list("""select name from tabTimesheet"""):
22 ts = webnotes.bean("Timesheet", name)
Rushabh Mehta3e712f22013-03-04 16:21:54 +053023
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +053024 for tsd in ts.doclist.get({"doctype":"Timesheet Detail"}):
Rushabh Mehta5423c962013-03-04 15:45:46 +053025 if not webnotes.conn.exists("Project", tsd.project_name):
26 tsd.project_name = None
27 if not webnotes.conn.exists("Task", tsd.task_id):
28 tsd.task_id = None
29
Rushabh Mehta040e5992013-03-04 15:47:42 +053030 tl = webnotes.bean({
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +053031 "doctype": "Time Log",
32 "status": "Draft",
33 "from_time": ts.doc.timesheet_date + " " + tsd.act_start_time,
34 "to_time": ts.doc.timesheet_date + " " + tsd.act_end_time,
35 "activity_type": tsd.activity_type,
36 "task": tsd.task_id,
37 "project": tsd.project_name,
38 "note": ts.doc.notes,
39 "file_list": ts.doc.file_list,
Rushabh Mehta3e712f22013-03-04 16:21:54 +053040 "_user_tags": ts.doc._user_tags,
41 "owner": ts.doc.owner,
42 "creation": ts.doc.creation,
43 "modified_by": ts.doc.modified_by
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +053044 })
Rushabh Mehta3e712f22013-03-04 16:21:54 +053045
46 for key in custom_map["Timesheet"]:
47 tl.doc.fields[key] = ts.doc.fields.get(key)
48
49 for key in custom_map["Timesheet Detail"]:
50 tl.doc.fields[key] = tsd.fields.get(key)
51
Rushabh Mehta040e5992013-03-04 15:47:42 +053052 tl.make_obj()
53 tl.controller.set_status()
54 tl.controller.calculate_total_hours()
55 tl.doc.insert()