Test Cases
This commit is contained in:
parent
709c43674b
commit
33d58ac431
@ -3,12 +3,19 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ActivityCost(Document):
|
||||
def validate(self):
|
||||
self.set_title()
|
||||
self.check_unique()
|
||||
|
||||
def set_title(self):
|
||||
self.title = _("{0} for {1}").format(self.employee_name, self.activity_type)
|
||||
|
||||
def check_unique(self):
|
||||
if frappe.db.exists({ "doctype": "Activity Cost", "employee": self.employee, "activity_type": self.activity_type }):
|
||||
frappe.throw(_("Activity Cost exists for Employee {0} against Activity Type {1}")
|
||||
.format(self.employee, self.activity_type))
|
||||
|
@ -6,7 +6,7 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
# test_records = frappe.get_test_records('Activity Cost')
|
||||
test_records = frappe.get_test_records('Activity Cost')
|
||||
|
||||
class TestActivityCost(unittest.TestCase):
|
||||
pass
|
||||
|
9
erpnext/projects/doctype/activity_cost/test_records.json
Normal file
9
erpnext/projects/doctype/activity_cost/test_records.json
Normal file
@ -0,0 +1,9 @@
|
||||
[
|
||||
{
|
||||
"employee": "_T-Employee-0001",
|
||||
"employee_name": "_Test Employee",
|
||||
"activity_type": "_Test Activity Type",
|
||||
"billing_rate": 100,
|
||||
"costing_rate": 50
|
||||
}
|
||||
]
|
@ -5,4 +5,3 @@ from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
test_records = frappe.get_test_records('Project')
|
||||
test_ignore = ["Task"]
|
||||
|
@ -1,10 +1,12 @@
|
||||
[
|
||||
{
|
||||
"project_name": "_Test Project",
|
||||
"status": "Open"
|
||||
},
|
||||
{
|
||||
"project_name": "_Test Project 1",
|
||||
"status": "Open"
|
||||
"project_name": "_Test Project",
|
||||
"status": "Open",
|
||||
"tasks":[
|
||||
{
|
||||
"title": "_Test Task",
|
||||
"status": "Open"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -128,7 +128,7 @@
|
||||
{
|
||||
"fieldname": "task_id",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Task ID",
|
||||
"no_copy": 1,
|
||||
"options": "Task",
|
||||
@ -143,7 +143,7 @@
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"modified": "2015-03-26 04:55:36.680900",
|
||||
"modified": "2015-04-06 09:41:50.911955",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Projects",
|
||||
"name": "Project Task",
|
||||
|
@ -46,13 +46,14 @@ class Task(Document):
|
||||
project.run_method("update_percent_complete")
|
||||
|
||||
def update_project(self):
|
||||
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`
|
||||
where project = %s""",self.project)
|
||||
frappe.db.set_value("Project", self.project, "total_activity_cost", total_activity_cost)
|
||||
|
||||
total_expense_claim = frappe.db.sql("""select sum(total_expense_claim) from `tabTask`
|
||||
where project = %s""",self.project)
|
||||
frappe.db.set_value("Project", self.project, "total_expense_claim", total_expense_claim)
|
||||
if self.project:
|
||||
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`
|
||||
where project = %s""",self.project)
|
||||
frappe.db.set_value("Project", self.project, "total_activity_cost", total_activity_cost)
|
||||
|
||||
total_expense_claim = frappe.db.sql("""select sum(total_expense_claim) from `tabTask`
|
||||
where project = %s""",self.project)
|
||||
frappe.db.set_value("Project", self.project, "total_expense_claim", total_expense_claim)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_events(start, end, filters=None):
|
||||
|
@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"project": "_Test Project",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task"
|
||||
"subject": "_Test Task",
|
||||
"name": "task001"
|
||||
},
|
||||
{
|
||||
"status": "Open",
|
||||
|
@ -5,5 +5,3 @@ from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
test_records = frappe.get_test_records('Task')
|
||||
test_dependencies = ["Project"]
|
||||
test_ignore = ["Customer"]
|
||||
|
@ -5,7 +5,6 @@
|
||||
"doctype": "Time Log",
|
||||
"from_time": "2013-01-01 10:00:00.000000",
|
||||
"note": "_Test Note",
|
||||
"to_time": "2013-01-01 11:00:00.000000",
|
||||
"project": "_Test Project"
|
||||
"to_time": "2013-01-01 11:00:00.000000"
|
||||
}
|
||||
]
|
||||
|
@ -10,7 +10,6 @@ from erpnext.projects.doctype.time_log.time_log import OverlapError
|
||||
from erpnext.projects.doctype.time_log.time_log import NotSubmittedError
|
||||
from erpnext.manufacturing.doctype.workstation.workstation import WorkstationHolidayError
|
||||
from erpnext.manufacturing.doctype.workstation.workstation import NotInWorkingHoursError
|
||||
from erpnext.projects.doctype.time_log_batch.test_time_log_batch import *
|
||||
from erpnext.manufacturing.doctype.production_order.test_production_order import make_prod_order_test_record
|
||||
|
||||
|
||||
@ -85,6 +84,61 @@ class TestTimeLog(unittest.TestCase):
|
||||
test_time_log.to_time = "2013-01-01 10:00:00.000000"
|
||||
self.assertRaises(frappe.ValidationError, test_time_log.save)
|
||||
frappe.db.sql("delete from `tabTime Log`")
|
||||
|
||||
|
||||
def test_time_log_costing(self):
|
||||
frappe.db.sql("delete from `tabTask`")
|
||||
frappe.db.sql("delete from `tabProject`")
|
||||
|
||||
frappe.get_doc({
|
||||
"project_name": "_Test Project 1",
|
||||
"doctype": "Project",
|
||||
"tasks" :
|
||||
[{ "title": "_Test Project Task 1", "status": "Open" }]
|
||||
}).save()
|
||||
|
||||
task_name = frappe.db.get_value("Task",{"project": "_Test Project 1"})
|
||||
|
||||
time_log = frappe.get_doc({
|
||||
"activity_type": "_Test Activity Type",
|
||||
"docstatus": 1,
|
||||
"doctype": "Time Log",
|
||||
"from_time": "2013-02-02 09:00:00.000000",
|
||||
"to_time": "2013-02-02 11:00:00.000000",
|
||||
"employee": "_T-Employee-0001",
|
||||
"project": "_Test Project 1",
|
||||
"task": task_name,
|
||||
"billable": 1
|
||||
})
|
||||
time_log.save()
|
||||
self.assertEqual(time_log.costing_rate, 50)
|
||||
self.assertEqual(time_log.costing_amount, 100)
|
||||
self.assertEqual(time_log.billing_rate, 100)
|
||||
self.assertEqual(time_log.billing_amount, 200)
|
||||
time_log.submit()
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task_name, "actual_cost"), 200)
|
||||
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_activity_cost"), 200)
|
||||
|
||||
time_log2 = frappe.get_doc({
|
||||
"activity_type": "_Test Activity Type",
|
||||
"docstatus": 1,
|
||||
"doctype": "Time Log",
|
||||
"from_time": "2013-02-03 09:00:00.000000",
|
||||
"to_time": "2013-02-03 11:00:00.000000",
|
||||
"employee": "_T-Employee-0001",
|
||||
"project": "_Test Project 1",
|
||||
"task": task_name,
|
||||
"billable": 1
|
||||
})
|
||||
time_log2.save()
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task_name, "actual_cost"), 400)
|
||||
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_activity_cost"), 400)
|
||||
|
||||
time_log2.cancel()
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task_name, "actual_cost"), 200)
|
||||
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_activity_cost"), 200)
|
||||
|
||||
test_records = frappe.get_test_records('Time Log')
|
||||
test_ignore = ["Time Log Batch", "Sales Invoice"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user