fixes in Expense Claim
This commit is contained in:
parent
7f9ea3bf6a
commit
2679b247b3
@ -19,7 +19,7 @@ class ExpenseClaim(Document):
|
||||
def validate(self):
|
||||
validate_fiscal_year(self.posting_date, self.fiscal_year, _("Posting Date"), self)
|
||||
self.validate_exp_details()
|
||||
self.validate_cost()
|
||||
self.calculate_total_amount()
|
||||
self.validate_sanctioned_amount()
|
||||
self.validate_expense_approver()
|
||||
self.validate_task()
|
||||
@ -32,17 +32,15 @@ class ExpenseClaim(Document):
|
||||
self.update_task()
|
||||
|
||||
def on_cancel(self):
|
||||
if self.project:
|
||||
if self.task:
|
||||
self.update_task()
|
||||
|
||||
def validate_cost(self):
|
||||
total_claimed_amount = 0
|
||||
total_sanctioned_amount = 0
|
||||
def calculate_total_amount(self):
|
||||
self.total_claimed_amount = 0
|
||||
self.total_sanctioned_amount = 0
|
||||
for d in self.expenses:
|
||||
total_claimed_amount += d.claim_amount
|
||||
total_sanctioned_amount += d.sanctioned_amount
|
||||
self.total_claimed_amount = total_claimed_amount
|
||||
self.total_sanctioned_amount = total_sanctioned_amount
|
||||
self.total_claimed_amount += d.claim_amount
|
||||
self.total_sanctioned_amount += d.sanctioned_amount
|
||||
|
||||
def validate_exp_details(self):
|
||||
if not self.get('expenses'):
|
||||
@ -54,17 +52,15 @@ class ExpenseClaim(Document):
|
||||
.format(get_fullname(self.exp_approver), self.exp_approver), InvalidExpenseApproverError)
|
||||
|
||||
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))
|
||||
|
||||
task = frappe.get_doc("Task", self.task)
|
||||
task.total_expense_claim = expense_amount
|
||||
task.update_total_expense_claim()
|
||||
task.save()
|
||||
|
||||
def validate_task(self):
|
||||
if self.project and not self.task:
|
||||
frappe.throw(_("Task is Mandatory if Time Log is against a project"))
|
||||
frappe.throw(_("Task is mandatory if Expense Claim is against a Project"))
|
||||
|
||||
def validate_sanctioned_amount(self):
|
||||
if self.total_sanctioned_amount > self.total_claimed_amount:
|
||||
frappe.throw(_("Total sanctioned amount cannot be greater than total claimed amount."))
|
||||
for d in self.expenses:
|
||||
if d.sanctioned_amount > d.claim_amount:
|
||||
frappe.throw(_("Sanctioned Amount cannot be greater than Claim Amount in Row {0}.").format(d.idx))
|
@ -8,7 +8,7 @@ import unittest
|
||||
test_records = frappe.get_test_records('Expense Claim')
|
||||
|
||||
class TestExpenseClaim(unittest.TestCase):
|
||||
def test_project_costing(self):
|
||||
def test_total_expense_claim_for_project(self):
|
||||
frappe.db.sql("delete from `tabTask`")
|
||||
frappe.db.sql("delete from `tabProject`")
|
||||
|
||||
|
@ -15,6 +15,12 @@
|
||||
"reqd": 0,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "expense_type",
|
||||
"fieldtype": "Link",
|
||||
@ -28,6 +34,12 @@
|
||||
"reqd": 1,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_4",
|
||||
"fieldtype": "Section Break",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "description",
|
||||
"fieldtype": "Small Text",
|
||||
@ -39,6 +51,12 @@
|
||||
"print_width": "300px",
|
||||
"width": "300px"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "claim_amount",
|
||||
"fieldtype": "Currency",
|
||||
@ -52,6 +70,12 @@
|
||||
"reqd": 1,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_8",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"fieldname": "sanctioned_amount",
|
||||
@ -69,7 +93,7 @@
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"modified": "2014-05-09 02:16:38.529082",
|
||||
"modified": "2015-04-08 06:18:47.539134",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Expense Claim Detail",
|
||||
|
@ -45,6 +45,10 @@ class Task(Document):
|
||||
project = frappe.get_doc("Project", self.project)
|
||||
project.run_method("update_percent_complete")
|
||||
|
||||
def update_total_expense_claim(self):
|
||||
self.total_expense_claim = 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.name))
|
||||
|
||||
def update_project(self):
|
||||
if self.project:
|
||||
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`
|
||||
|
Loading…
x
Reference in New Issue
Block a user