Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 1 | import webnotes |
| 2 | |
| 3 | def execute(): |
| 4 | # convert timesheet details to time logs |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 5 | 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 Mehta | 986d48b | 2013-03-04 16:29:48 +0530 | [diff] [blame] | 15 | try: |
| 16 | cf = webnotes.bean(custom_field).insert() |
| 17 | except Exception, e: |
| 18 | # duplicate custom field |
| 19 | pass |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 20 | |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 21 | for name in webnotes.conn.sql_list("""select name from tabTimesheet"""): |
| 22 | ts = webnotes.bean("Timesheet", name) |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 23 | |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 24 | for tsd in ts.doclist.get({"doctype":"Timesheet Detail"}): |
Rushabh Mehta | 5423c96 | 2013-03-04 15:45:46 +0530 | [diff] [blame] | 25 | 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 Mehta | 040e599 | 2013-03-04 15:47:42 +0530 | [diff] [blame] | 30 | tl = webnotes.bean({ |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 31 | "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 Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 40 | "_user_tags": ts.doc._user_tags, |
| 41 | "owner": ts.doc.owner, |
| 42 | "creation": ts.doc.creation, |
| 43 | "modified_by": ts.doc.modified_by |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 44 | }) |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 45 | |
| 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 Mehta | 040e599 | 2013-03-04 15:47:42 +0530 | [diff] [blame] | 52 | tl.make_obj() |
| 53 | tl.controller.set_status() |
| 54 | tl.controller.calculate_total_hours() |
| 55 | tl.doc.insert() |