Fixes in time_log

This commit is contained in:
Neil Trini Lasrado 2015-04-09 18:28:32 +05:30
parent c33ad6b36a
commit 78b96ca769
5 changed files with 35 additions and 27 deletions

View File

@ -49,6 +49,17 @@ class Task(Document):
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))
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):
if self.project:
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`

View File

@ -85,7 +85,7 @@ class TestTimeLog(unittest.TestCase):
self.assertRaises(frappe.ValidationError, test_time_log.save)
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 `tabProject`")

View File

@ -80,11 +80,11 @@ frappe.ui.form.on("Time Log", "employee", function(frm) {
get_activity_cost(frm);
});
cur_frm.cscript.billable = function(doc) {
if (doc.billable==1) {
calculate_cost(doc);
frappe.ui.form.on("Time Log", "billable", function(frm) {
if (frm.doc.billable==1) {
calculate_cost(frm.doc);
}
else {
cur_frm.set_value("billing_amount", 0);
frm.doc("billing_amount", 0);
}
}
});

View File

@ -242,7 +242,7 @@
},
{
"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",
"fieldtype": "Currency",
"label": "Billing Amount",
@ -297,7 +297,11 @@
"icon": "icon-time",
"idx": 1,
"is_submittable": 1,
<<<<<<< HEAD
"modified": "2015-04-06 02:47:16.187046",
=======
"modified": "2015-04-09 08:29:34.464429",
>>>>>>> Fixes in time_log
"modified_by": "Administrator",
"module": "Projects",
"name": "Time Log",

View File

@ -217,8 +217,9 @@ class TimeLog(Document):
def validate_cost(self):
rate = get_activity_cost(self.employee, self.activity_type)
self.costing_rate = rate.get('costing_rate') or 0
self.billing_rate = rate.get('billing_rate') or 0
if rate:
self.costing_rate = rate.get('costing_rate')
self.billing_rate = rate.get('billing_rate')
self.costing_amount = self.costing_rate * self.hours
if self.billable:
self.billing_amount = self.billing_rate * self.hours
@ -230,16 +231,8 @@ class TimeLog(Document):
frappe.throw(_("Task is Mandatory if Time Log is against a project"))
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)
if task.status == "Open":
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.update_actual_time_and_costing()
task.save()
@frappe.whitelist()
@ -281,7 +274,7 @@ def get_events(start, end, filters=None):
@frappe.whitelist()
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")
billing_rate = frappe.db.get_value("Activity Cost", {"employee":employee,"activity_type":activity_type}, "billing_rate")
return {"costing_rate": costing_rate, "billing_rate": billing_rate }
rate = frappe.db.sql("""select costing_rate, billing_rate from `tabActivity Cost` where employee= %s
and activity_type= %s""", (employee, activity_type), as_dict=1)
if rate:
return {"costing_rate": rate[0].costing_rate, "billing_rate": rate[0].billing_rate }