Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 4 | import webnotes |
| 5 | |
| 6 | def execute(): |
| 7 | # convert timesheet details to time logs |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 8 | webnotes.reload_doc("projects", "doctype", "time_log") |
| 9 | |
| 10 | # copy custom fields |
| 11 | custom_map = {"Timesheet":[], "Timesheet Detail":[]} |
| 12 | for custom_field in webnotes.conn.sql("""select * from `tabCustom Field` where |
| 13 | dt in ('Timesheet', 'Timesheet Detail')""", as_dict=True): |
| 14 | custom_map[custom_field.dt].append(custom_field.fieldname) |
| 15 | custom_field.doctype = "Custom Field" |
| 16 | custom_field.dt = "Time Log" |
| 17 | custom_field.insert_after = None |
Rushabh Mehta | 986d48b | 2013-03-04 16:29:48 +0530 | [diff] [blame] | 18 | try: |
| 19 | cf = webnotes.bean(custom_field).insert() |
| 20 | except Exception, e: |
| 21 | # duplicate custom field |
| 22 | pass |
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 name in webnotes.conn.sql_list("""select name from tabTimesheet"""): |
| 25 | ts = webnotes.bean("Timesheet", name) |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 26 | |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 27 | for tsd in ts.doclist.get({"doctype":"Timesheet Detail"}): |
Rushabh Mehta | 5423c96 | 2013-03-04 15:45:46 +0530 | [diff] [blame] | 28 | if not webnotes.conn.exists("Project", tsd.project_name): |
| 29 | tsd.project_name = None |
| 30 | if not webnotes.conn.exists("Task", tsd.task_id): |
| 31 | tsd.task_id = None |
| 32 | |
Rushabh Mehta | 040e599 | 2013-03-04 15:47:42 +0530 | [diff] [blame] | 33 | tl = webnotes.bean({ |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 34 | "doctype": "Time Log", |
| 35 | "status": "Draft", |
| 36 | "from_time": ts.doc.timesheet_date + " " + tsd.act_start_time, |
| 37 | "to_time": ts.doc.timesheet_date + " " + tsd.act_end_time, |
| 38 | "activity_type": tsd.activity_type, |
| 39 | "task": tsd.task_id, |
| 40 | "project": tsd.project_name, |
| 41 | "note": ts.doc.notes, |
| 42 | "file_list": ts.doc.file_list, |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 43 | "_user_tags": ts.doc._user_tags, |
| 44 | "owner": ts.doc.owner, |
| 45 | "creation": ts.doc.creation, |
| 46 | "modified_by": ts.doc.modified_by |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 47 | }) |
Rushabh Mehta | 3e712f2 | 2013-03-04 16:21:54 +0530 | [diff] [blame] | 48 | |
| 49 | for key in custom_map["Timesheet"]: |
| 50 | tl.doc.fields[key] = ts.doc.fields.get(key) |
| 51 | |
| 52 | for key in custom_map["Timesheet Detail"]: |
| 53 | tl.doc.fields[key] = tsd.fields.get(key) |
| 54 | |
Rushabh Mehta | 03e9a4e | 2013-06-28 12:49:28 +0530 | [diff] [blame] | 55 | tl.make_controller() |
Rushabh Mehta | 040e599 | 2013-03-04 15:47:42 +0530 | [diff] [blame] | 56 | tl.controller.set_status() |
| 57 | tl.controller.calculate_total_hours() |
| 58 | tl.doc.insert() |