From ef4e41380bd076fd70c8a598c1d4a28298580dc8 Mon Sep 17 00:00:00 2001 From: RobertSchouten Date: Fri, 7 Oct 2016 11:01:12 +0800 Subject: [PATCH 1/4] [fix] update timestamps and relink communication for timesheet --- .../v7_0/update_timesheet_modified_created | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 erpnext/patches/v7_0/update_timesheet_modified_created diff --git a/erpnext/patches/v7_0/update_timesheet_modified_created b/erpnext/patches/v7_0/update_timesheet_modified_created new file mode 100644 index 0000000000..25004a8aab --- /dev/null +++ b/erpnext/patches/v7_0/update_timesheet_modified_created @@ -0,0 +1,24 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + if frappe.db.table_exists("Time Log") and "employee" in frappe.db.get_table_columns("Time Log"): + timesheet = frappe.db.sql("""SELECT ts.name AS name, tl.name AS timelogname, + tl.modified AS modified, tl.modified_by AS modified_by, tl.creation AS creation, tl.owner AS owner + FROM + `tabTimesheet` ts, `tabTimesheet Detail` tsd, `tabTime Log` tl + WHERE + tsd.parent = ts.name AND tl.from_time = tsd.from_time AND tl.to_time = tsd.to_time + AND tl.hours = tsd.hours AND tl.billing_rate = tsd.billing_rate AND tsd.idx=1 + AND tl.docstatus < 2""", as_dict=1) + for data in timesheet: + frappe.db.sql(""" update `tabTimesheet` set creation = %(creation)s, + owner = %(owner)s, modified = %(modified)s, modified_by = %(modified_by)s + where name = %(name)s""", data) + frappe.db.sql("""update tabCommunication + set reference_doctype = "Timesheet", + reference_name = %(timesheet)s + where reference_doctype = "Time Log" + and reference_name = %(timelog)s""", + {'timesheet': data.name, 'timelog': data.timelogname}, + auto_commit=1) From e0a636c0818ca5394792643e4d73ada3bdb302b8 Mon Sep 17 00:00:00 2001 From: RobertSchouten Date: Fri, 7 Oct 2016 11:03:04 +0800 Subject: [PATCH 2/4] [fix] update timestamps and relink communication for timesheet --- erpnext/patches.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 9822fc041a..b0dbbff98e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -318,3 +318,4 @@ erpnext.patches.v7_0.set_party_name_in_payment_entry execute:frappe.db.sql("update `tabTimesheet` ts, `tabEmployee` emp set ts.employee_name = emp.employee_name where emp.name = ts.employee and ts.employee_name is null and ts.employee is not null") execute:frappe.db.sql("delete from `tabTimesheet Detail` where NOT EXISTS (select name from `tabTimesheet` where name = `tabTimesheet Detail`.parent)") erpnext.patches.v7_0.update_mode_of_payment_type +finally:erpnext.patches.v7_0.update_timesheet_modified_created From 1885207eca263d0a7fc8d66f65bc2ffbc7592050 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 7 Oct 2016 12:54:04 +0530 Subject: [PATCH 3/4] Update and rename update_timesheet_modified_created to update_timesheet_communications --- .../v7_0/update_timesheet_communications | 23 ++++++++++++++++++ .../v7_0/update_timesheet_modified_created | 24 ------------------- 2 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 erpnext/patches/v7_0/update_timesheet_communications delete mode 100644 erpnext/patches/v7_0/update_timesheet_modified_created diff --git a/erpnext/patches/v7_0/update_timesheet_communications b/erpnext/patches/v7_0/update_timesheet_communications new file mode 100644 index 0000000000..01d3210248 --- /dev/null +++ b/erpnext/patches/v7_0/update_timesheet_communications @@ -0,0 +1,23 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + if frappe.db.table_exists("Time Log"): + timesheet = frappe.db.sql("""SELECT ts.name AS name, tl.name AS timelogname, + tl.modified AS modified, tl.modified_by AS modified_by, tl.creation AS creation, tl.owner AS owner + FROM + `tabTimesheet` ts, `tabTimesheet Detail` tsd, `tabTime Log` tl + WHERE + tsd.parent = ts.name AND tl.from_time = tsd.from_time AND tl.to_time = tsd.to_time + AND tl.hours = tsd.hours AND tl.billing_rate = tsd.billing_rate AND tsd.idx=1 + AND tl.docstatus < 2""", as_dict=1) + + for data in timesheet: + frappe.db.sql(""" + update + tabCommunication + set + reference_doctype = "Timesheet", reference_name = %(timesheet)s + where + reference_doctype = "Time Log" and reference_name = %(timelog)s + """, {'timesheet': data.name, 'timelog': data.timelogname}, auto_commit=1) diff --git a/erpnext/patches/v7_0/update_timesheet_modified_created b/erpnext/patches/v7_0/update_timesheet_modified_created deleted file mode 100644 index 25004a8aab..0000000000 --- a/erpnext/patches/v7_0/update_timesheet_modified_created +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import unicode_literals -import frappe - -def execute(): - if frappe.db.table_exists("Time Log") and "employee" in frappe.db.get_table_columns("Time Log"): - timesheet = frappe.db.sql("""SELECT ts.name AS name, tl.name AS timelogname, - tl.modified AS modified, tl.modified_by AS modified_by, tl.creation AS creation, tl.owner AS owner - FROM - `tabTimesheet` ts, `tabTimesheet Detail` tsd, `tabTime Log` tl - WHERE - tsd.parent = ts.name AND tl.from_time = tsd.from_time AND tl.to_time = tsd.to_time - AND tl.hours = tsd.hours AND tl.billing_rate = tsd.billing_rate AND tsd.idx=1 - AND tl.docstatus < 2""", as_dict=1) - for data in timesheet: - frappe.db.sql(""" update `tabTimesheet` set creation = %(creation)s, - owner = %(owner)s, modified = %(modified)s, modified_by = %(modified_by)s - where name = %(name)s""", data) - frappe.db.sql("""update tabCommunication - set reference_doctype = "Timesheet", - reference_name = %(timesheet)s - where reference_doctype = "Time Log" - and reference_name = %(timelog)s""", - {'timesheet': data.name, 'timelog': data.timelogname}, - auto_commit=1) From 16f3f378f62523a879f300580f05919c2d1587e9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 7 Oct 2016 12:54:27 +0530 Subject: [PATCH 4/4] Update patches.txt --- erpnext/patches.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index b0dbbff98e..3f19f9297e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -318,4 +318,4 @@ erpnext.patches.v7_0.set_party_name_in_payment_entry execute:frappe.db.sql("update `tabTimesheet` ts, `tabEmployee` emp set ts.employee_name = emp.employee_name where emp.name = ts.employee and ts.employee_name is null and ts.employee is not null") execute:frappe.db.sql("delete from `tabTimesheet Detail` where NOT EXISTS (select name from `tabTimesheet` where name = `tabTimesheet Detail`.parent)") erpnext.patches.v7_0.update_mode_of_payment_type -finally:erpnext.patches.v7_0.update_timesheet_modified_created +finally:erpnext.patches.v7_0.update_timesheet_communications