[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
// 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);
}
}
}
});

View File

@ -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",

View File

@ -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"""

View File

@ -5,8 +5,14 @@
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"]