From a11770f06ff10b2e3dd28a78eb5aacd167f350e1 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 31 Mar 2015 13:27:55 +0530 Subject: [PATCH] in Time Log - Server side validations added to recalculate cost on save --- .../hr/doctype/expense_claim/expense_claim.py | 5 ++++- erpnext/projects/doctype/task/task.json | 3 ++- erpnext/projects/doctype/time_log/time_log.js | 18 ++++++++++++------ erpnext/projects/doctype/time_log/time_log.py | 3 +++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index 886a55db17..9bc16e4ebc 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -46,7 +46,10 @@ class ExpenseClaim(Document): 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 5cbef3c5ad..b46fe2111c 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 e4fbfc3ee1..6892d10228 100644 --- a/erpnext/projects/doctype/time_log/time_log.js +++ b/erpnext/projects/doctype/time_log/time_log.js @@ -51,11 +51,7 @@ var calculate_cost = function(doc) { } } -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", "activity_type", function(frm) { } } }); +} + +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 09d0becf73..1f70221f10 100644 --- a/erpnext/projects/doctype/time_log/time_log.py +++ b/erpnext/projects/doctype/time_log/time_log.py @@ -216,6 +216,9 @@ class TimeLog(Document): 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