in Time Log - Server side validations added to recalculate cost on save
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index 886a55d..9bc16e4 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -46,7 +46,10 @@
def update_task(self):
expense_amount = 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.task))
- frappe.db.set_value("Project", self.project, "total_expense_claim", expense_amount)
+
+ task = frappe.get_doc("Task", self.task)
+ task.total_expense_claim = expense_amount
+ task.save()
def validate_task(self):
if self.project and not self.task:
diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json
index 5cbef3c..b46fe21 100644
--- a/erpnext/projects/doctype/task/task.json
+++ b/erpnext/projects/doctype/task/task.json
@@ -246,8 +246,9 @@
],
"icon": "icon-check",
"idx": 1,
+ "istable": 0,
"max_attachments": 5,
- "modified": "2015-03-30 05:50:04.409614",
+ "modified": "2015-03-31 03:31:13.055284",
"modified_by": "Administrator",
"module": "Projects",
"name": "Task",
diff --git a/erpnext/projects/doctype/time_log/time_log.js b/erpnext/projects/doctype/time_log/time_log.js
index e4fbfc3..6892d10 100644
--- a/erpnext/projects/doctype/time_log/time_log.js
+++ b/erpnext/projects/doctype/time_log/time_log.js
@@ -51,11 +51,7 @@
}
}
-frappe.ui.form.on("Time Log", "hours", function(frm) {
- calculate_cost(frm.doc);
-});
-
-frappe.ui.form.on("Time Log", "activity_type", function(frm) {
+var get_activity_cost = function(frm) {
return frappe.call({
method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost",
args: {
@@ -70,9 +66,19 @@
}
}
});
+}
+
+frappe.ui.form.on("Time Log", "hours", function(frm) {
+ calculate_cost(frm.doc);
});
-cur_frm.cscript.employee = cur_frm.cscript.activity_type;
+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);
+});
cur_frm.cscript.billable = function(doc) {
if (doc.billable==1) {
diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py
index 09d0bec..1f70221 100644
--- a/erpnext/projects/doctype/time_log/time_log.py
+++ b/erpnext/projects/doctype/time_log/time_log.py
@@ -216,6 +216,9 @@
self.quantity = None
def validate_cost(self):
+ rate = get_activity_cost(self.employee, self.activity_type)
+ self.internal_rate = rate.get('internal_rate')
+ self.billing_rate = rate.get('billing_rate')
self.internal_cost = self.internal_rate * self.hours
if self.billable:
self.billing_amount = self.billing_rate * self.hours