Merge pull request #6243 from rohitwaghchaure/timesheet_issue

[Patch] Check table exist
This commit is contained in:
Nabin Hait 2016-09-01 12:38:30 +05:30 committed by GitHub
commit 9afee28c36

View File

@ -2,18 +2,19 @@ from __future__ import unicode_literals
import frappe import frappe
def execute(): def execute():
timesheet = frappe.db.sql("""select tl.employee as employee, ts.name as name, if frappe.db.table_exists("Time Log"):
tl.modified as modified, tl.modified_by as modified_by, tl.creation as creation, tl.owner as owner timesheet = frappe.db.sql("""select tl.employee as employee, ts.name as name,
from tl.modified as modified, tl.modified_by as modified_by, tl.creation as creation, tl.owner as owner
`tabTimesheet` ts, `tabTimesheet Detail` tsd, `tabTime Log` tl from
where `tabTimesheet` ts, `tabTimesheet Detail` tsd, `tabTime Log` tl
tsd.parent = ts.name and tl.from_time = tsd.from_time and tl.to_time = tsd.to_time where
and tl.hours = tsd.hours and tl.billing_rate = tsd.billing_rate and tsd.idx=1 tsd.parent = ts.name and tl.from_time = tsd.from_time and tl.to_time = tsd.to_time
and tl.docstatus < 2 and (ts.employee = '' or ts.employee is null)""", as_dict=1) and tl.hours = tsd.hours and tl.billing_rate = tsd.billing_rate and tsd.idx=1
and tl.docstatus < 2 and (ts.employee = '' or ts.employee is null)""", as_dict=1)
for data in timesheet: for data in timesheet:
ts_doc = frappe.get_doc('Timesheet', data.name) ts_doc = frappe.get_doc('Timesheet', data.name)
if len(ts_doc.time_logs) == 1: if len(ts_doc.time_logs) == 1:
frappe.db.sql(""" update `tabTimesheet` set creation = %(creation)s, frappe.db.sql(""" update `tabTimesheet` set creation = %(creation)s,
owner = %(owner)s, modified = %(modified)s, modified_by = %(modified_by)s, owner = %(owner)s, modified = %(modified)s, modified_by = %(modified_by)s,
employee = %(employee)s where name = %(name)s""", data) employee = %(employee)s where name = %(name)s""", data)