fixes in Expense Claim and get_avtivity_cost function
This commit is contained in:
parent
832dfe7980
commit
5e317d2b72
@ -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",
|
||||
|
@ -18,11 +18,10 @@ class ExpenseClaim(Document):
|
||||
|
||||
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 @@ class ExpenseClaim(Document):
|
||||
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 @@ class ExpenseClaim(Document):
|
||||
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))
|
@ -23,8 +23,6 @@ class TestExpenseClaim(unittest.TestCase):
|
||||
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 @@ class TestExpenseClaim(unittest.TestCase):
|
||||
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,
|
||||
|
@ -43,32 +43,34 @@ frappe.ui.form.on("Time Log", "to_time", function(frm) {
|
||||
|
||||
});
|
||||
|
||||
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", "employee", function(frm) {
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -273,5 +273,4 @@ def get_events(start, end, filters=None):
|
||||
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 {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user