2016-06-03 09:14:35 +00:00
|
|
|
import frappe
|
2016-08-16 09:48:20 +00:00
|
|
|
from erpnext.manufacturing.doctype.production_order.production_order \
|
|
|
|
import make_timesheet, add_timesheet_detail
|
2016-06-03 09:14:35 +00:00
|
|
|
|
2016-06-29 10:02:36 +00:00
|
|
|
def execute():
|
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
|
|
|
|
2016-09-07 11:47:47 +00:00
|
|
|
for data in frappe.db.sql("select * from `tabTime Log` where docstatus < 2", as_dict=1):
|
2016-08-16 13:01:09 +00:00
|
|
|
if data.task:
|
|
|
|
company = frappe.db.get_value("Task", data.task, "company")
|
|
|
|
elif data.production_order:
|
|
|
|
company = frappe.db.get_value("Prodction Order", data.production_order, "company")
|
|
|
|
else:
|
|
|
|
company = frappe.db.get_single_value('Global Defaults', 'default_company')
|
|
|
|
|
|
|
|
time_sheet = make_timesheet(data.production_order)
|
|
|
|
args = get_timelog_data(data)
|
|
|
|
add_timesheet_detail(time_sheet, args)
|
2016-08-22 09:06:33 +00:00
|
|
|
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)
|
|
|
|
time_sheet.update_production_order(time_sheet.name)
|
|
|
|
time_sheet.update_task_and_project()
|
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
|
|
|
}
|