fixes in Expense Claim and get_avtivity_cost function
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.json b/erpnext/hr/doctype/expense_claim/expense_claim.json
index 95b8a81..f82fbcc 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.json
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.json
@@ -93,7 +93,8 @@
"oldfieldname": "expense_voucher_details",
"oldfieldtype": "Table",
"options": "Expense Claim Detail",
- "permlevel": 0
+ "permlevel": 0,
+ "reqd": 1
},
{
"fieldname": "sb1",
@@ -235,7 +236,7 @@
"icon": "icon-money",
"idx": 1,
"is_submittable": 1,
- "modified": "2015-04-14 05:08:06.541441",
+ "modified": "2015-04-21 09:32:00.971151",
"modified_by": "Administrator",
"module": "HR",
"name": "Expense Claim",
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index b5fe880..6687399 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -18,11 +18,10 @@
def validate(self):
validate_fiscal_year(self.posting_date, self.fiscal_year, _("Posting Date"), self)
- self.validate_exp_details()
- self.calculate_total_amount()
self.validate_sanctioned_amount()
self.validate_expense_approver()
self.validate_task()
+ self.calculate_total_amount()
set_employee_name(self)
def on_submit(self):
@@ -38,14 +37,10 @@
def calculate_total_amount(self):
self.total_claimed_amount = 0
self.total_sanctioned_amount = 0
- for d in self.expenses:
+ for d in self.get('expenses'):
self.total_claimed_amount += flt(d.claim_amount)
self.total_sanctioned_amount += flt(d.sanctioned_amount)
- def validate_exp_details(self):
- if not self.get('expenses'):
- frappe.throw(_("Please add expense voucher details"))
-
def validate_expense_approver(self):
if self.exp_approver and "Expense Approver" not in frappe.get_roles(self.exp_approver):
frappe.throw(_("{0} ({1}) must have role 'Expense Approver'")\
@@ -61,6 +56,6 @@
frappe.throw(_("Task is mandatory if Expense Claim is against a Project"))
def validate_sanctioned_amount(self):
- for d in self.expenses:
+ for d in self.get('expenses'):
if flt(d.sanctioned_amount) > flt(d.claim_amount):
frappe.throw(_("Sanctioned Amount cannot be greater than Claim Amount in Row {0}.").format(d.idx))
\ No newline at end of file
diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
index f5ae93c..a9091fb 100644
--- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
@@ -23,8 +23,6 @@
expense_claim = frappe.get_doc({
"doctype": "Expense Claim",
"employee": "_T-Employee-0001",
- "posting_date": "2015-07-07",
- "fiscal_year": "_Test Fiscal Year 2015",
"approval_status": "Approved",
"project": "_Test Project 1",
"task": task_name,
@@ -39,7 +37,6 @@
expense_claim2 = frappe.get_doc({
"doctype": "Expense Claim",
"employee": "_T-Employee-0001",
- "posting_date": "2015-07-07",
"approval_status": "Approved",
"project": "_Test Project 1",
"task": task_name,
diff --git a/erpnext/projects/doctype/time_log/time_log.js b/erpnext/projects/doctype/time_log/time_log.js
index 2f960ab..ba93301 100644
--- a/erpnext/projects/doctype/time_log/time_log.js
+++ b/erpnext/projects/doctype/time_log/time_log.js
@@ -43,32 +43,34 @@
});
-var calculate_cost = function(doc) {
- cur_frm.set_value("costing_amount", doc.costing_rate * doc.hours);
- if (doc.billable==1){
- cur_frm.set_value("billing_amount", doc.billing_rate * doc.hours);
+var calculate_cost = function(frm) {
+ frm.set_value("costing_amount", frm.doc.costing_rate * frm.doc.hours);
+ if (frm.doc.billable==1){
+ frm.set_value("billing_amount", frm.doc.billing_rate * frm.doc.hours);
}
}
var get_activity_cost = function(frm) {
- return frappe.call({
- method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost",
- args: {
- "employee": frm.doc.employee,
- "activity_type": frm.doc.activity_type
- },
- callback: function(r) {
- if(!r.exc) {
- cur_frm.set_value("costing_rate", r.message.costing_rate);
- cur_frm.set_value("billing_rate", r.message.billing_rate);
- calculate_cost(frm.doc);
+ if (frm.doc.employee && frm.doc.activity_type){
+ return frappe.call({
+ method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost",
+ args: {
+ "employee": frm.doc.employee,
+ "activity_type": frm.doc.activity_type
+ },
+ callback: function(r) {
+ if(!r.exc && r.message) {
+ frm.set_value("costing_rate", r.message.costing_rate);
+ frm.set_value("billing_rate", r.message.billing_rate);
+ calculate_cost(frm);
+ }
}
- }
- });
+ });
+ }
}
frappe.ui.form.on("Time Log", "hours", function(frm) {
- calculate_cost(frm.doc);
+ calculate_cost(frm);
});
frappe.ui.form.on("Time Log", "activity_type", function(frm) {
@@ -81,10 +83,10 @@
frappe.ui.form.on("Time Log", "billable", function(frm) {
if (frm.doc.billable==1) {
- calculate_cost(frm.doc);
+ calculate_cost(frm);
}
else {
- frm.doc("billing_amount", 0);
+ frm.set_value("billing_amount", 0);
}
});
diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py
index 1ee825f..25383a0 100644
--- a/erpnext/projects/doctype/time_log/time_log.py
+++ b/erpnext/projects/doctype/time_log/time_log.py
@@ -273,5 +273,4 @@
def get_activity_cost(employee=None, activity_type=None):
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 }
+ return rate[0] if rate else {}