[fix] making time log entry easier, to time not mandatory while making time log and Finish button

This commit is contained in:
Rushabh Mehta 2016-04-29 13:19:34 +05:30
parent 49e470035d
commit 127de729b2
4 changed files with 121 additions and 117 deletions

View File

@ -1,111 +1,105 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.projects"); frappe.ui.form.on("Time Log", {
onload: function(frm) {
frappe.ui.form.on("Time Log", "onload", function(frm) { if (frm.doc.__islocal) {
if (frm.doc.__islocal) { if (frm.doc.for_manufacturing) {
if (frm.doc.for_manufacturing) { frappe.ui.form.trigger("Time Log", "production_order");
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) { frm.set_query('task', function() {
frappe.ui.form.trigger("Time Log", "to_time"); return {
} filters:{
} 'project': frm.doc.project
});
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);
} }
} }
}); });
} },
} 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) { frm.toggle_reqd("activity_type", !frm.doc.for_manufacturing);
calculate_cost(frm); },
}); 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) { frm.trigger('calculate_cost');
get_activity_cost(frm); },
}); before_save: function(frm) {
frm.doc.production_order && frappe.model.remove_from_locals("Production Order",
frappe.ui.form.on("Time Log", "employee", function(frm) { frm.doc.production_order);
get_activity_cost(frm); },
}); to_time: function(frm) {
if(frm._setting_hours) return;
frappe.ui.form.on("Time Log", "billable", function(frm) { frm.set_value("hours", moment(cur_frm.doc.to_time).diff(moment(cur_frm.doc.from_time),
if (frm.doc.billable==1) { "seconds") / 3600);
calculate_cost(frm); },
} calculate_cost: function(frm) {
else { frm.set_value("costing_amount", frm.doc.costing_rate * frm.doc.hours);
frm.set_value("billing_amount", 0); if (frm.doc.billable==1){
frm.set_value("additional_cost", 0); frm.set_value("billing_amount", (frm.doc.billing_rate * frm.doc.hours) + frm.doc.additional_cost);
} }
}); },
additional_cost: function(frm) {
cur_frm.fields_dict['task'].get_query = function(doc) { frm.trigger('calculate_cost');
return { },
filters:{ activity_type: function(frm) {
'project': doc.project 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);
} }
} }
}
});

View File

@ -89,7 +89,7 @@
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 1,
"collapsible": 0, "collapsible": 0,
"depends_on": "", "depends_on": "",
"fieldname": "project", "fieldname": "project",
@ -115,7 +115,7 @@
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 1,
"collapsible": 0, "collapsible": 0,
"depends_on": "", "depends_on": "",
"fieldname": "task", "fieldname": "task",
@ -153,7 +153,7 @@
"label": "Status", "label": "Status",
"length": 0, "length": 0,
"no_copy": 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, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
@ -190,8 +190,9 @@
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 1,
"collapsible": 0, "collapsible": 0,
"default": "now",
"fieldname": "from_time", "fieldname": "from_time",
"fieldtype": "Datetime", "fieldtype": "Datetime",
"hidden": 0, "hidden": 0,
@ -239,7 +240,7 @@
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 1,
"collapsible": 0, "collapsible": 0,
"fieldname": "to_time", "fieldname": "to_time",
"fieldtype": "Datetime", "fieldtype": "Datetime",
@ -256,7 +257,7 @@
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
@ -934,7 +935,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-04-15 07:51:03.097280", "modified": "2016-04-29 03:45:50.096299",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Projects", "module": "Projects",
"name": "Time Log", "name": "Time Log",

View File

@ -45,16 +45,19 @@ class TimeLog(Document):
def set_status(self): def set_status(self):
self.status = { self.status = {
0: "Draft", 0: "To Submit",
1: "Submitted", 1: "Submitted",
2: "Cancelled" 2: "Cancelled"
}[self.docstatus or 0] }[self.docstatus or 0]
if not self.to_time:
self.status = 'In Progress'
if self.time_log_batch: if self.time_log_batch:
self.status="Batched for Billing" self.status= "Batched for Billing"
if self.sales_invoice: if self.sales_invoice:
self.status="Billed" self.status= "Billed"
def set_title(self): def set_title(self):
"""Set default title for the Time Log""" """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` existing = frappe.db.sql("""select name, from_time, to_time from `tabTime Log`
where `{0}`=%(val)s and where `{0}`=%(val)s and
( (
(%(from_time)s > from_time and %(from_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 (%(to_time)s > from_time and %(to_time)s < to_time) or
(%(from_time)s <= from_time and %(to_time)s >= to_time)) (%(from_time)s <= from_time and %(to_time)s >= to_time))
and name!=%(name)s and name!=%(name)s
and docstatus < 2""".format(fieldname), and docstatus < 2""".format(fieldname),
@ -233,7 +236,7 @@ class TimeLog(Document):
self.billing_amount = self.billing_rate * self.hours self.billing_amount = self.billing_rate * self.hours
else: else:
self.billing_amount = 0 self.billing_amount = 0
if self.additional_cost and self.billable: if self.additional_cost and self.billable:
self.billing_amount += self.additional_cost self.billing_amount += self.additional_cost
@ -247,11 +250,11 @@ class TimeLog(Document):
elif self.project: elif self.project:
frappe.get_doc("Project", self.project).update_project() frappe.get_doc("Project", self.project).update_project()
def has_webform_permission(doc): def has_webform_permission(doc):
project_user = frappe.db.get_value("Project User", {"parent": doc.project, "user":frappe.session.user} , "user") project_user = frappe.db.get_value("Project User", {"parent": doc.project, "user":frappe.session.user} , "user")
if project_user: if project_user:
return True return True
@frappe.whitelist() @frappe.whitelist()

View File

@ -4,9 +4,15 @@
// render // render
frappe.listview_settings['Time Log'] = { frappe.listview_settings['Time Log'] = {
add_fields: ["status", "billable", "activity_type", "task", "project", "hours", "for_manufacturing", "billing_amount"], add_fields: ["status", "billable", "activity_type", "task", "project", "hours", "for_manufacturing", "billing_amount"],
has_indicator_for_draft: true,
get_indicator: function(doc) { 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"] return [__("Batched for Billing"), "darkgrey", "status,=,Batched for Billing"]
} else if (doc.status== "Billed") { } else if (doc.status== "Billed") {
return [__("Billed"), "green", "status,=,Billed"] return [__("Billed"), "green", "status,=,Billed"]
@ -14,7 +20,7 @@ frappe.listview_settings['Time Log'] = {
return [__("Billable"), "orange", "billable,=,1"] return [__("Billable"), "orange", "billable,=,1"]
} }
}, },
selectable: true, selectable: true,
onload: function(me) { onload: function(me) {
me.page.add_menu_item(__("Make Time Log Batch"), function() { me.page.add_menu_item(__("Make Time Log Batch"), function() {