2016-06-03 09:14:35 +00:00
|
|
|
import frappe
|
|
|
|
|
2016-06-29 10:02:36 +00:00
|
|
|
def execute():
|
2016-11-07 11:46:39 +00:00
|
|
|
frappe.reload_doc('projects', 'doctype', 'task')
|
2016-07-14 09:02:15 +00:00
|
|
|
frappe.reload_doc('projects', 'doctype', 'timesheet')
|
2016-09-07 11:01:26 +00:00
|
|
|
if not frappe.db.table_exists("Time Log"):
|
|
|
|
return
|
2016-07-12 20:20:32 +00:00
|
|
|
|
2018-09-11 11:20:46 +00:00
|
|
|
from erpnext.manufacturing.doctype.work_order.work_order \
|
|
|
|
import make_timesheet, add_timesheet_detail
|
|
|
|
|
2016-11-07 11:46:39 +00:00
|
|
|
for data in frappe.db.sql("select * from `tabTime Log`", as_dict=1):
|
2016-08-16 13:01:09 +00:00
|
|
|
if data.task:
|
|
|
|
company = frappe.db.get_value("Task", data.task, "company")
|
2018-03-20 07:08:43 +00:00
|
|
|
elif data.work_order:
|
|
|
|
company = frappe.db.get_value("Work Order", data.work_order, "company")
|
2016-08-16 13:01:09 +00:00
|
|
|
else:
|
|
|
|
company = frappe.db.get_single_value('Global Defaults', 'default_company')
|
|
|
|
|
2018-03-20 07:08:43 +00:00
|
|
|
time_sheet = make_timesheet(data.work_order, company)
|
2016-08-16 13:01:09 +00:00
|
|
|
args = get_timelog_data(data)
|
|
|
|
add_timesheet_detail(time_sheet, args)
|
2016-11-07 11:46:39 +00:00
|
|
|
if data.docstatus == 2:
|
|
|
|
time_sheet.docstatus = 0
|
|
|
|
else:
|
|
|
|
time_sheet.docstatus = data.docstatus
|
2016-08-31 19:27:43 +00:00
|
|
|
time_sheet.employee = data.employee
|
2016-08-16 13:01:09 +00:00
|
|
|
time_sheet.note = data.note
|
|
|
|
time_sheet.company = company
|
2016-09-02 06:54:54 +00:00
|
|
|
|
2016-08-16 13:01:09 +00:00
|
|
|
time_sheet.set_status()
|
2016-09-02 06:54:54 +00:00
|
|
|
time_sheet.set_dates()
|
2016-08-16 13:01:09 +00:00
|
|
|
time_sheet.update_cost()
|
|
|
|
time_sheet.calculate_total_amounts()
|
|
|
|
time_sheet.flags.ignore_validate = True
|
2016-09-23 05:38:02 +00:00
|
|
|
time_sheet.flags.ignore_links = True
|
2016-08-16 13:01:09 +00:00
|
|
|
time_sheet.save(ignore_permissions=True)
|
2016-06-03 09:14:35 +00:00
|
|
|
|
2016-08-22 07:29:28 +00:00
|
|
|
# To ignore validate_mandatory_fields function
|
|
|
|
if data.docstatus == 1:
|
|
|
|
time_sheet.db_set("docstatus", 1)
|
|
|
|
for d in time_sheet.get("time_logs"):
|
|
|
|
d.db_set("docstatus", 1)
|
2018-03-20 07:08:43 +00:00
|
|
|
time_sheet.update_work_order(time_sheet.name)
|
2016-08-22 07:29:28 +00:00
|
|
|
time_sheet.update_task_and_project()
|
2016-11-07 11:46:39 +00:00
|
|
|
if data.docstatus == 2:
|
|
|
|
time_sheet.db_set("docstatus", 2)
|
|
|
|
for d in time_sheet.get("time_logs"):
|
|
|
|
d.db_set("docstatus", 2)
|
2016-06-03 09:14:35 +00:00
|
|
|
|
2016-07-12 20:20:32 +00:00
|
|
|
def get_timelog_data(data):
|
2016-06-03 09:14:35 +00:00
|
|
|
return {
|
2016-07-02 14:42:34 +00:00
|
|
|
'billable': data.billable,
|
2016-06-03 09:14:35 +00:00
|
|
|
'from_time': data.from_time,
|
|
|
|
'hours': data.hours,
|
|
|
|
'to_time': data.to_time,
|
|
|
|
'project': data.project,
|
2016-07-02 14:42:34 +00:00
|
|
|
'task': data.task,
|
2016-06-29 10:02:36 +00:00
|
|
|
'activity_type': data.activity_type,
|
2016-06-03 09:14:35 +00:00
|
|
|
'operation': data.operation,
|
|
|
|
'operation_id': data.operation_id,
|
|
|
|
'workstation': data.workstation,
|
2016-07-12 20:20:32 +00:00
|
|
|
'completed_qty': data.completed_qty,
|
|
|
|
'billing_rate': data.billing_rate,
|
|
|
|
'billing_amount': data.billing_amount,
|
|
|
|
'costing_rate': data.costing_rate,
|
|
|
|
'costing_amount': data.costing_amount
|
2016-06-29 10:02:36 +00:00
|
|
|
}
|