mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 20:29:09 +00:00
[fix] making time log entry easier, to time not mandatory while making time log and Finish button
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
// 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");
|
||||||
@@ -12,20 +11,37 @@ frappe.ui.form.on("Time Log", "onload", function(frm) {
|
|||||||
frappe.ui.form.trigger("Time Log", "to_time");
|
frappe.ui.form.trigger("Time Log", "to_time");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
frm.set_query('task', function() {
|
||||||
|
return {
|
||||||
frappe.ui.form.on("Time Log", "refresh", function(frm) {
|
filters:{
|
||||||
|
'project': frm.doc.project
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
refresh: function(frm) {
|
||||||
// set default user if created
|
// set default user if created
|
||||||
if (frm.doc.__islocal && !frm.doc.user) {
|
if (frm.doc.__islocal && !frm.doc.user) {
|
||||||
frm.set_value("user", 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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
frm.toggle_reqd("activity_type", !frm.doc.for_manufacturing);
|
frm.toggle_reqd("activity_type", !frm.doc.for_manufacturing);
|
||||||
});
|
},
|
||||||
|
hours: function(frm) {
|
||||||
|
|
||||||
// set to time if hours is updated
|
|
||||||
frappe.ui.form.on("Time Log", "hours", function(frm) {
|
|
||||||
if(!frm.doc.from_time) {
|
if(!frm.doc.from_time) {
|
||||||
frm.set_value("from_time", frappe.datetime.now_datetime());
|
frm.set_value("from_time", frappe.datetime.now_datetime());
|
||||||
}
|
}
|
||||||
@@ -34,30 +50,28 @@ frappe.ui.form.on("Time Log", "hours", function(frm) {
|
|||||||
frm._setting_hours = true;
|
frm._setting_hours = true;
|
||||||
frm.set_value("to_time", d.format(moment.defaultDatetimeFormat));
|
frm.set_value("to_time", d.format(moment.defaultDatetimeFormat));
|
||||||
frm._setting_hours = false;
|
frm._setting_hours = false;
|
||||||
});
|
|
||||||
|
|
||||||
// clear production order if making time log
|
frm.trigger('calculate_cost');
|
||||||
frappe.ui.form.on("Time Log", "before_save", function(frm) {
|
},
|
||||||
|
before_save: function(frm) {
|
||||||
frm.doc.production_order && frappe.model.remove_from_locals("Production Order",
|
frm.doc.production_order && frappe.model.remove_from_locals("Production Order",
|
||||||
frm.doc.production_order);
|
frm.doc.production_order);
|
||||||
});
|
},
|
||||||
|
to_time: function(frm) {
|
||||||
// set hours if to_time is updated
|
|
||||||
frappe.ui.form.on("Time Log", "to_time", function(frm) {
|
|
||||||
if(frm._setting_hours) return;
|
if(frm._setting_hours) return;
|
||||||
frm.set_value("hours", moment(cur_frm.doc.to_time).diff(moment(cur_frm.doc.from_time),
|
frm.set_value("hours", moment(cur_frm.doc.to_time).diff(moment(cur_frm.doc.from_time),
|
||||||
"seconds") / 3600);
|
"seconds") / 3600);
|
||||||
|
},
|
||||||
});
|
calculate_cost: function(frm) {
|
||||||
|
|
||||||
var calculate_cost = function(frm) {
|
|
||||||
frm.set_value("costing_amount", frm.doc.costing_rate * frm.doc.hours);
|
frm.set_value("costing_amount", frm.doc.costing_rate * frm.doc.hours);
|
||||||
if (frm.doc.billable==1){
|
if (frm.doc.billable==1){
|
||||||
frm.set_value("billing_amount", (frm.doc.billing_rate * frm.doc.hours) + frm.doc.additional_cost);
|
frm.set_value("billing_amount", (frm.doc.billing_rate * frm.doc.hours) + frm.doc.additional_cost);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
additional_cost: function(frm) {
|
||||||
var get_activity_cost = function(frm) {
|
frm.trigger('calculate_cost');
|
||||||
|
},
|
||||||
|
activity_type: function(frm) {
|
||||||
if (frm.doc.activity_type){
|
if (frm.doc.activity_type){
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost",
|
method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost",
|
||||||
@@ -69,43 +83,23 @@ var get_activity_cost = function(frm) {
|
|||||||
if(!r.exc && r.message) {
|
if(!r.exc && r.message) {
|
||||||
frm.set_value("costing_rate", r.message.costing_rate);
|
frm.set_value("costing_rate", r.message.costing_rate);
|
||||||
frm.set_value("billing_rate", r.message.billing_rate);
|
frm.set_value("billing_rate", r.message.billing_rate);
|
||||||
calculate_cost(frm);
|
frm.trigger('calculate_cost');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
employee: function(frm) {
|
||||||
frappe.ui.form.on("Time Log", "hours", function(frm) {
|
frm.trigger('activity_type');
|
||||||
calculate_cost(frm);
|
},
|
||||||
});
|
billable: function(frm) {
|
||||||
|
|
||||||
frappe.ui.form.on("Time Log", "additional_cost", function(frm) {
|
|
||||||
calculate_cost(frm);
|
|
||||||
});
|
|
||||||
|
|
||||||
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) {
|
if (frm.doc.billable==1) {
|
||||||
calculate_cost(frm);
|
frm.trigger('calculate_cost');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
frm.set_value("billing_amount", 0);
|
frm.set_value("billing_amount", 0);
|
||||||
frm.set_value("additional_cost", 0);
|
frm.set_value("additional_cost", 0);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
cur_frm.fields_dict['task'].get_query = function(doc) {
|
});
|
||||||
return {
|
|
||||||
filters:{
|
|
||||||
'project': doc.project
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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"""
|
||||||
|
|||||||
@@ -5,8 +5,14 @@
|
|||||||
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"]
|
||||||
|
|||||||
Reference in New Issue
Block a user