diff --git a/erpnext/projects/doctype/time_log/time_log.js b/erpnext/projects/doctype/time_log/time_log.js index 7648a536dbf..10e3bc7763c 100644 --- a/erpnext/projects/doctype/time_log/time_log.js +++ b/erpnext/projects/doctype/time_log/time_log.js @@ -1,111 +1,105 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.provide("erpnext.projects"); - -frappe.ui.form.on("Time Log", "onload", function(frm) { - if (frm.doc.__islocal) { - if (frm.doc.for_manufacturing) { - frappe.ui.form.trigger("Time Log", "production_order"); +frappe.ui.form.on("Time Log", { + onload: function(frm) { + if (frm.doc.__islocal) { + if (frm.doc.for_manufacturing) { + frappe.ui.form.trigger("Time Log", "production_order"); + } + if (frm.doc.from_time && frm.doc.to_time) { + frappe.ui.form.trigger("Time Log", "to_time"); + } } - if (frm.doc.from_time && frm.doc.to_time) { - frappe.ui.form.trigger("Time Log", "to_time"); - } - } -}); - -frappe.ui.form.on("Time Log", "refresh", function(frm) { - // set default user if created - if (frm.doc.__islocal && !frm.doc.user) { - frm.set_value("user", user); - } - - frm.toggle_reqd("activity_type", !frm.doc.for_manufacturing); -}); - - -// set to time if hours is updated -frappe.ui.form.on("Time Log", "hours", function(frm) { - if(!frm.doc.from_time) { - frm.set_value("from_time", frappe.datetime.now_datetime()); - } - var d = moment(frm.doc.from_time); - d.add(frm.doc.hours, "hours"); - frm._setting_hours = true; - frm.set_value("to_time", d.format(moment.defaultDatetimeFormat)); - frm._setting_hours = false; -}); - -// clear production order if making time log -frappe.ui.form.on("Time Log", "before_save", function(frm) { - frm.doc.production_order && frappe.model.remove_from_locals("Production Order", - frm.doc.production_order); -}); - -// set hours if to_time is updated -frappe.ui.form.on("Time Log", "to_time", function(frm) { - if(frm._setting_hours) return; - frm.set_value("hours", moment(cur_frm.doc.to_time).diff(moment(cur_frm.doc.from_time), - "seconds") / 3600); - -}); - -var calculate_cost = function(frm) { - frm.set_value("costing_amount", frm.doc.costing_rate * frm.doc.hours); - if (frm.doc.billable==1){ - frm.set_value("billing_amount", (frm.doc.billing_rate * frm.doc.hours) + frm.doc.additional_cost); - } -} - -var get_activity_cost = function(frm) { - if (frm.doc.activity_type){ - return frappe.call({ - method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost", - args: { - "employee": frm.doc.employee, - "activity_type": frm.doc.activity_type - }, - callback: function(r) { - if(!r.exc && r.message) { - frm.set_value("costing_rate", r.message.costing_rate); - frm.set_value("billing_rate", r.message.billing_rate); - calculate_cost(frm); + frm.set_query('task', function() { + return { + filters:{ + 'project': frm.doc.project } } }); - } -} + }, + refresh: function(frm) { + // set default user if created + if (frm.doc.__islocal && !frm.doc.user) { + frm.set_value("user", user); + } + if (frm.doc.status==='In Progress' && !frm.is_new()) { + frm.add_custom_button(__('Finish'), function() { + frappe.prompt({ + fieldtype: 'Datetime', + fieldname: 'to_time', + label: __('End Time'), + 'default': dateutil.now_datetime() + }, function(value) { + frm.set_value('to_time', value.to_time); + frm.save(); + }); + }).addClass('btn-primary'); + } -frappe.ui.form.on("Time Log", "hours", function(frm) { - calculate_cost(frm); -}); -frappe.ui.form.on("Time Log", "additional_cost", function(frm) { - calculate_cost(frm); -}); + frm.toggle_reqd("activity_type", !frm.doc.for_manufacturing); + }, + hours: function(frm) { + if(!frm.doc.from_time) { + frm.set_value("from_time", frappe.datetime.now_datetime()); + } + var d = moment(frm.doc.from_time); + d.add(frm.doc.hours, "hours"); + frm._setting_hours = true; + frm.set_value("to_time", d.format(moment.defaultDatetimeFormat)); + frm._setting_hours = false; -frappe.ui.form.on("Time Log", "activity_type", function(frm) { - get_activity_cost(frm); -}); - -frappe.ui.form.on("Time Log", "employee", function(frm) { - get_activity_cost(frm); -}); - -frappe.ui.form.on("Time Log", "billable", function(frm) { - if (frm.doc.billable==1) { - calculate_cost(frm); - } - else { - frm.set_value("billing_amount", 0); - frm.set_value("additional_cost", 0); - } -}); - -cur_frm.fields_dict['task'].get_query = function(doc) { - return { - filters:{ - 'project': doc.project + frm.trigger('calculate_cost'); + }, + before_save: function(frm) { + frm.doc.production_order && frappe.model.remove_from_locals("Production Order", + frm.doc.production_order); + }, + to_time: function(frm) { + if(frm._setting_hours) return; + frm.set_value("hours", moment(cur_frm.doc.to_time).diff(moment(cur_frm.doc.from_time), + "seconds") / 3600); + }, + calculate_cost: function(frm) { + frm.set_value("costing_amount", frm.doc.costing_rate * frm.doc.hours); + if (frm.doc.billable==1){ + frm.set_value("billing_amount", (frm.doc.billing_rate * frm.doc.hours) + frm.doc.additional_cost); + } + }, + additional_cost: function(frm) { + frm.trigger('calculate_cost'); + }, + activity_type: function(frm) { + if (frm.doc.activity_type){ + return frappe.call({ + method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost", + args: { + "employee": frm.doc.employee, + "activity_type": frm.doc.activity_type + }, + callback: function(r) { + if(!r.exc && r.message) { + frm.set_value("costing_rate", r.message.costing_rate); + frm.set_value("billing_rate", r.message.billing_rate); + frm.trigger('calculate_cost'); + } + } + }); + } + }, + employee: function(frm) { + frm.trigger('activity_type'); + }, + billable: function(frm) { + if (frm.doc.billable==1) { + frm.trigger('calculate_cost'); + } + else { + frm.set_value("billing_amount", 0); + frm.set_value("additional_cost", 0); } } -} + +}); diff --git a/erpnext/projects/doctype/time_log/time_log.json b/erpnext/projects/doctype/time_log/time_log.json index 050fc5472bf..ef61d41f426 100644 --- a/erpnext/projects/doctype/time_log/time_log.json +++ b/erpnext/projects/doctype/time_log/time_log.json @@ -89,7 +89,7 @@ }, { "allow_on_submit": 0, - "bold": 0, + "bold": 1, "collapsible": 0, "depends_on": "", "fieldname": "project", @@ -115,7 +115,7 @@ }, { "allow_on_submit": 0, - "bold": 0, + "bold": 1, "collapsible": 0, "depends_on": "", "fieldname": "task", @@ -153,7 +153,7 @@ "label": "Status", "length": 0, "no_copy": 0, - "options": "Draft\nSubmitted\nBatched for Billing\nBilled\nCancelled", + "options": "In Progress\nTo Submit\nSubmitted\nBatched for Billing\nBilled\nCancelled", "permlevel": 0, "print_hide": 0, "print_hide_if_no_value": 0, @@ -190,8 +190,9 @@ }, { "allow_on_submit": 0, - "bold": 0, + "bold": 1, "collapsible": 0, + "default": "now", "fieldname": "from_time", "fieldtype": "Datetime", "hidden": 0, @@ -239,7 +240,7 @@ }, { "allow_on_submit": 0, - "bold": 0, + "bold": 1, "collapsible": 0, "fieldname": "to_time", "fieldtype": "Datetime", @@ -256,7 +257,7 @@ "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, - "reqd": 1, + "reqd": 0, "search_index": 0, "set_only_once": 0, "unique": 0 @@ -934,7 +935,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-04-15 07:51:03.097280", + "modified": "2016-04-29 03:45:50.096299", "modified_by": "Administrator", "module": "Projects", "name": "Time Log", diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py index e2641ebb023..9545bd7fabf 100644 --- a/erpnext/projects/doctype/time_log/time_log.py +++ b/erpnext/projects/doctype/time_log/time_log.py @@ -45,16 +45,19 @@ class TimeLog(Document): def set_status(self): self.status = { - 0: "Draft", + 0: "To Submit", 1: "Submitted", 2: "Cancelled" }[self.docstatus or 0] + if not self.to_time: + self.status = 'In Progress' + if self.time_log_batch: - self.status="Batched for Billing" + self.status= "Batched for Billing" if self.sales_invoice: - self.status="Billed" + self.status= "Billed" def set_title(self): """Set default title for the Time Log""" @@ -88,8 +91,8 @@ class TimeLog(Document): existing = frappe.db.sql("""select name, from_time, to_time from `tabTime Log` where `{0}`=%(val)s and ( - (%(from_time)s > from_time and %(from_time)s < to_time) or - (%(to_time)s > from_time and %(to_time)s < to_time) or + (%(from_time)s > from_time and %(from_time)s < to_time) or + (%(to_time)s > from_time and %(to_time)s < to_time) or (%(from_time)s <= from_time and %(to_time)s >= to_time)) and name!=%(name)s and docstatus < 2""".format(fieldname), @@ -233,7 +236,7 @@ class TimeLog(Document): self.billing_amount = self.billing_rate * self.hours else: self.billing_amount = 0 - + if self.additional_cost and self.billable: self.billing_amount += self.additional_cost @@ -247,11 +250,11 @@ class TimeLog(Document): elif self.project: frappe.get_doc("Project", self.project).update_project() - + def has_webform_permission(doc): project_user = frappe.db.get_value("Project User", {"parent": doc.project, "user":frappe.session.user} , "user") if project_user: - return True + return True @frappe.whitelist() diff --git a/erpnext/projects/doctype/time_log/time_log_list.js b/erpnext/projects/doctype/time_log/time_log_list.js index 53969283b35..e9e7d05b6c1 100644 --- a/erpnext/projects/doctype/time_log/time_log_list.js +++ b/erpnext/projects/doctype/time_log/time_log_list.js @@ -4,9 +4,15 @@ // render frappe.listview_settings['Time Log'] = { add_fields: ["status", "billable", "activity_type", "task", "project", "hours", "for_manufacturing", "billing_amount"], - + + has_indicator_for_draft: true, + get_indicator: function(doc) { - if (doc.status== "Batched for Billing") { + if (doc.status== "Draft") { + return [__("Draft"), "red", "status,=,Draft"] + } else if (doc.status== "In Progress") { + return [__("In Progress"), "orange", "status,=,In Progress"] + } else if (doc.status== "Batched for Billing") { return [__("Batched for Billing"), "darkgrey", "status,=,Batched for Billing"] } else if (doc.status== "Billed") { return [__("Billed"), "green", "status,=,Billed"] @@ -14,7 +20,7 @@ frappe.listview_settings['Time Log'] = { return [__("Billable"), "orange", "billable,=,1"] } }, - + selectable: true, onload: function(me) { me.page.add_menu_item(__("Make Time Log Batch"), function() {