Fixes in time_log
This commit is contained in:
parent
c33ad6b36a
commit
78b96ca769
@ -49,6 +49,17 @@ class Task(Document):
|
|||||||
self.total_expense_claim = frappe.db.sql("""select sum(total_sanctioned_amount) from `tabExpense Claim`
|
self.total_expense_claim = frappe.db.sql("""select sum(total_sanctioned_amount) from `tabExpense Claim`
|
||||||
where project = %s and task = %s and approval_status = "Approved" and docstatus=1""",(self.project, self.name))
|
where project = %s and task = %s and approval_status = "Approved" and docstatus=1""",(self.project, self.name))
|
||||||
|
|
||||||
|
def update_actual_time_and_costing(self):
|
||||||
|
tl = frappe.db.sql("""select min(from_time) as start_date, max(to_time) as
|
||||||
|
end_date, sum(billing_amount) as cost, sum(hours) as time from `tabTime Log` where
|
||||||
|
project = %s and task = %s and docstatus=1""",(self.project, self.name),as_dict=1)[0]
|
||||||
|
if self.status == "Open":
|
||||||
|
self.status = "Working"
|
||||||
|
self.actual_cost= tl.cost
|
||||||
|
self.actual_time= tl.time
|
||||||
|
self.act_start_date= tl.start_date
|
||||||
|
self.act_end_date= tl.end_date
|
||||||
|
|
||||||
def update_project(self):
|
def update_project(self):
|
||||||
if self.project:
|
if self.project:
|
||||||
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`
|
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`
|
||||||
|
@ -85,7 +85,7 @@ class TestTimeLog(unittest.TestCase):
|
|||||||
self.assertRaises(frappe.ValidationError, test_time_log.save)
|
self.assertRaises(frappe.ValidationError, test_time_log.save)
|
||||||
frappe.db.sql("delete from `tabTime Log`")
|
frappe.db.sql("delete from `tabTime Log`")
|
||||||
|
|
||||||
def test_time_log_costing(self):
|
def test_total_activity_cost_for_project(self):
|
||||||
frappe.db.sql("delete from `tabTask`")
|
frappe.db.sql("delete from `tabTask`")
|
||||||
frappe.db.sql("delete from `tabProject`")
|
frappe.db.sql("delete from `tabProject`")
|
||||||
|
|
||||||
|
@ -80,11 +80,11 @@ frappe.ui.form.on("Time Log", "employee", function(frm) {
|
|||||||
get_activity_cost(frm);
|
get_activity_cost(frm);
|
||||||
});
|
});
|
||||||
|
|
||||||
cur_frm.cscript.billable = function(doc) {
|
frappe.ui.form.on("Time Log", "billable", function(frm) {
|
||||||
if (doc.billable==1) {
|
if (frm.doc.billable==1) {
|
||||||
calculate_cost(doc);
|
calculate_cost(frm.doc);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cur_frm.set_value("billing_amount", 0);
|
frm.doc("billing_amount", 0);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
@ -242,7 +242,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "0",
|
"default": "0",
|
||||||
"description": "will be updated only if Time Log is 'Billable'",
|
"description": "Will be updated only if Time Log is 'Billable'",
|
||||||
"fieldname": "billing_amount",
|
"fieldname": "billing_amount",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Billing Amount",
|
"label": "Billing Amount",
|
||||||
@ -297,7 +297,11 @@
|
|||||||
"icon": "icon-time",
|
"icon": "icon-time",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
|
<<<<<<< HEAD
|
||||||
"modified": "2015-04-06 02:47:16.187046",
|
"modified": "2015-04-06 02:47:16.187046",
|
||||||
|
=======
|
||||||
|
"modified": "2015-04-09 08:29:34.464429",
|
||||||
|
>>>>>>> Fixes in time_log
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Projects",
|
"module": "Projects",
|
||||||
"name": "Time Log",
|
"name": "Time Log",
|
||||||
|
@ -217,29 +217,22 @@ class TimeLog(Document):
|
|||||||
|
|
||||||
def validate_cost(self):
|
def validate_cost(self):
|
||||||
rate = get_activity_cost(self.employee, self.activity_type)
|
rate = get_activity_cost(self.employee, self.activity_type)
|
||||||
self.costing_rate = rate.get('costing_rate') or 0
|
if rate:
|
||||||
self.billing_rate = rate.get('billing_rate') or 0
|
self.costing_rate = rate.get('costing_rate')
|
||||||
self.costing_amount = self.costing_rate * self.hours
|
self.billing_rate = rate.get('billing_rate')
|
||||||
if self.billable:
|
self.costing_amount = self.costing_rate * self.hours
|
||||||
self.billing_amount = self.billing_rate * self.hours
|
if self.billable:
|
||||||
else:
|
self.billing_amount = self.billing_rate * self.hours
|
||||||
self.billing_amount = 0
|
else:
|
||||||
|
self.billing_amount = 0
|
||||||
|
|
||||||
def validate_task(self):
|
def validate_task(self):
|
||||||
if self.project and not self.task:
|
if self.project and not self.task:
|
||||||
frappe.throw(_("Task is Mandatory if Time Log is against a project"))
|
frappe.throw(_("Task is Mandatory if Time Log is against a project"))
|
||||||
|
|
||||||
def update_task(self):
|
def update_task(self):
|
||||||
tl = frappe.db.sql("""select min(from_time) as start_date, max(to_time) as end_date, sum(billing_amount) as cost, sum(hours) as time
|
|
||||||
from `tabTime Log` where project = %s and task = %s and docstatus=1""",(self.project, self.task),as_dict=1)[0]
|
|
||||||
|
|
||||||
task = frappe.get_doc("Task", self.task)
|
task = frappe.get_doc("Task", self.task)
|
||||||
if task.status == "Open":
|
task.update_actual_time_and_costing()
|
||||||
task.status = "Working"
|
|
||||||
task.actual_cost= tl.cost
|
|
||||||
task.actual_time= tl.time
|
|
||||||
task.act_start_date= tl.start_date
|
|
||||||
task.act_end_date= tl.end_date
|
|
||||||
task.save()
|
task.save()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@ -281,7 +274,7 @@ def get_events(start, end, filters=None):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_activity_cost(employee=None, activity_type=None):
|
def get_activity_cost(employee=None, activity_type=None):
|
||||||
costing_rate = frappe.db.get_value("Activity Cost", {"employee":employee,"activity_type":activity_type}, "costing_rate")
|
rate = frappe.db.sql("""select costing_rate, billing_rate from `tabActivity Cost` where employee= %s
|
||||||
billing_rate = frappe.db.get_value("Activity Cost", {"employee":employee,"activity_type":activity_type}, "billing_rate")
|
and activity_type= %s""", (employee, activity_type), as_dict=1)
|
||||||
return {"costing_rate": costing_rate, "billing_rate": billing_rate }
|
if rate:
|
||||||
|
return {"costing_rate": rate[0].costing_rate, "billing_rate": rate[0].billing_rate }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user