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",
|
"oldfieldname": "expense_voucher_details",
|
||||||
"oldfieldtype": "Table",
|
"oldfieldtype": "Table",
|
||||||
"options": "Expense Claim Detail",
|
"options": "Expense Claim Detail",
|
||||||
"permlevel": 0
|
"permlevel": 0,
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "sb1",
|
"fieldname": "sb1",
|
||||||
@ -235,7 +236,7 @@
|
|||||||
"icon": "icon-money",
|
"icon": "icon-money",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"modified": "2015-04-14 05:08:06.541441",
|
"modified": "2015-04-21 09:32:00.971151",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Expense Claim",
|
"name": "Expense Claim",
|
||||||
|
@ -18,11 +18,10 @@ class ExpenseClaim(Document):
|
|||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
validate_fiscal_year(self.posting_date, self.fiscal_year, _("Posting Date"), 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_sanctioned_amount()
|
||||||
self.validate_expense_approver()
|
self.validate_expense_approver()
|
||||||
self.validate_task()
|
self.validate_task()
|
||||||
|
self.calculate_total_amount()
|
||||||
set_employee_name(self)
|
set_employee_name(self)
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
@ -38,14 +37,10 @@ class ExpenseClaim(Document):
|
|||||||
def calculate_total_amount(self):
|
def calculate_total_amount(self):
|
||||||
self.total_claimed_amount = 0
|
self.total_claimed_amount = 0
|
||||||
self.total_sanctioned_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_claimed_amount += flt(d.claim_amount)
|
||||||
self.total_sanctioned_amount += flt(d.sanctioned_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):
|
def validate_expense_approver(self):
|
||||||
if self.exp_approver and "Expense Approver" not in frappe.get_roles(self.exp_approver):
|
if self.exp_approver and "Expense Approver" not in frappe.get_roles(self.exp_approver):
|
||||||
frappe.throw(_("{0} ({1}) must have role 'Expense 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"))
|
frappe.throw(_("Task is mandatory if Expense Claim is against a Project"))
|
||||||
|
|
||||||
def validate_sanctioned_amount(self):
|
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):
|
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))
|
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({
|
expense_claim = frappe.get_doc({
|
||||||
"doctype": "Expense Claim",
|
"doctype": "Expense Claim",
|
||||||
"employee": "_T-Employee-0001",
|
"employee": "_T-Employee-0001",
|
||||||
"posting_date": "2015-07-07",
|
|
||||||
"fiscal_year": "_Test Fiscal Year 2015",
|
|
||||||
"approval_status": "Approved",
|
"approval_status": "Approved",
|
||||||
"project": "_Test Project 1",
|
"project": "_Test Project 1",
|
||||||
"task": task_name,
|
"task": task_name,
|
||||||
@ -39,7 +37,6 @@ class TestExpenseClaim(unittest.TestCase):
|
|||||||
expense_claim2 = frappe.get_doc({
|
expense_claim2 = frappe.get_doc({
|
||||||
"doctype": "Expense Claim",
|
"doctype": "Expense Claim",
|
||||||
"employee": "_T-Employee-0001",
|
"employee": "_T-Employee-0001",
|
||||||
"posting_date": "2015-07-07",
|
|
||||||
"approval_status": "Approved",
|
"approval_status": "Approved",
|
||||||
"project": "_Test Project 1",
|
"project": "_Test Project 1",
|
||||||
"task": task_name,
|
"task": task_name,
|
||||||
|
@ -43,32 +43,34 @@ frappe.ui.form.on("Time Log", "to_time", function(frm) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var calculate_cost = function(doc) {
|
var calculate_cost = function(frm) {
|
||||||
cur_frm.set_value("costing_amount", doc.costing_rate * doc.hours);
|
frm.set_value("costing_amount", frm.doc.costing_rate * frm.doc.hours);
|
||||||
if (doc.billable==1){
|
if (frm.doc.billable==1){
|
||||||
cur_frm.set_value("billing_amount", doc.billing_rate * doc.hours);
|
frm.set_value("billing_amount", frm.doc.billing_rate * frm.doc.hours);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var get_activity_cost = function(frm) {
|
var get_activity_cost = function(frm) {
|
||||||
return frappe.call({
|
if (frm.doc.employee && frm.doc.activity_type){
|
||||||
method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost",
|
return frappe.call({
|
||||||
args: {
|
method: "erpnext.projects.doctype.time_log.time_log.get_activity_cost",
|
||||||
"employee": frm.doc.employee,
|
args: {
|
||||||
"activity_type": frm.doc.activity_type
|
"employee": frm.doc.employee,
|
||||||
},
|
"activity_type": frm.doc.activity_type
|
||||||
callback: function(r) {
|
},
|
||||||
if(!r.exc) {
|
callback: function(r) {
|
||||||
cur_frm.set_value("costing_rate", r.message.costing_rate);
|
if(!r.exc && r.message) {
|
||||||
cur_frm.set_value("billing_rate", r.message.billing_rate);
|
frm.set_value("costing_rate", r.message.costing_rate);
|
||||||
calculate_cost(frm.doc);
|
frm.set_value("billing_rate", r.message.billing_rate);
|
||||||
|
calculate_cost(frm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.ui.form.on("Time Log", "hours", function(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) {
|
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) {
|
frappe.ui.form.on("Time Log", "billable", function(frm) {
|
||||||
if (frm.doc.billable==1) {
|
if (frm.doc.billable==1) {
|
||||||
calculate_cost(frm.doc);
|
calculate_cost(frm);
|
||||||
}
|
}
|
||||||
else {
|
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):
|
def get_activity_cost(employee=None, activity_type=None):
|
||||||
rate = frappe.db.sql("""select costing_rate, billing_rate from `tabActivity Cost` where employee= %s
|
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)
|
and activity_type= %s""", (employee, activity_type), as_dict=1)
|
||||||
if rate:
|
return rate[0] if rate else {}
|
||||||
return {"costing_rate": rate[0].costing_rate, "billing_rate": rate[0].billing_rate }
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user