mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 18:59:08 +00:00
Test Cases
This commit is contained in:
@@ -3,12 +3,19 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class ActivityCost(Document):
|
class ActivityCost(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.set_title()
|
self.set_title()
|
||||||
|
self.check_unique()
|
||||||
|
|
||||||
def set_title(self):
|
def set_title(self):
|
||||||
self.title = _("{0} for {1}").format(self.employee_name, self.activity_type)
|
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 frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
# test_records = frappe.get_test_records('Activity Cost')
|
test_records = frappe.get_test_records('Activity Cost')
|
||||||
|
|
||||||
class TestActivityCost(unittest.TestCase):
|
class TestActivityCost(unittest.TestCase):
|
||||||
pass
|
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
|
import frappe
|
||||||
test_records = frappe.get_test_records('Project')
|
test_records = frappe.get_test_records('Project')
|
||||||
test_ignore = ["Task"]
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"project_name": "_Test Project",
|
"project_name": "_Test Project",
|
||||||
"status": "Open"
|
"status": "Open",
|
||||||
},
|
"tasks":[
|
||||||
{
|
{
|
||||||
"project_name": "_Test Project 1",
|
"title": "_Test Task",
|
||||||
"status": "Open"
|
"status": "Open"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -128,7 +128,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "task_id",
|
"fieldname": "task_id",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"hidden": 1,
|
"hidden": 0,
|
||||||
"label": "Task ID",
|
"label": "Task ID",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"options": "Task",
|
"options": "Task",
|
||||||
@@ -143,7 +143,7 @@
|
|||||||
"is_submittable": 0,
|
"is_submittable": 0,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2015-03-26 04:55:36.680900",
|
"modified": "2015-04-06 09:41:50.911955",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Projects",
|
"module": "Projects",
|
||||||
"name": "Project Task",
|
"name": "Project Task",
|
||||||
|
|||||||
@@ -46,13 +46,14 @@ class Task(Document):
|
|||||||
project.run_method("update_percent_complete")
|
project.run_method("update_percent_complete")
|
||||||
|
|
||||||
def update_project(self):
|
def update_project(self):
|
||||||
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`
|
if self.project:
|
||||||
where project = %s""",self.project)
|
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask`
|
||||||
frappe.db.set_value("Project", self.project, "total_activity_cost", total_activity_cost)
|
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)
|
total_expense_claim = frappe.db.sql("""select sum(total_expense_claim) from `tabTask`
|
||||||
frappe.db.set_value("Project", self.project, "total_expense_claim", total_expense_claim)
|
where project = %s""",self.project)
|
||||||
|
frappe.db.set_value("Project", self.project, "total_expense_claim", total_expense_claim)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_events(start, end, filters=None):
|
def get_events(start, end, filters=None):
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"project": "_Test Project",
|
|
||||||
"status": "Open",
|
"status": "Open",
|
||||||
"subject": "_Test Task"
|
"subject": "_Test Task",
|
||||||
|
"name": "task001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"status": "Open",
|
"status": "Open",
|
||||||
|
|||||||
@@ -5,5 +5,3 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
test_records = frappe.get_test_records('Task')
|
test_records = frappe.get_test_records('Task')
|
||||||
test_dependencies = ["Project"]
|
|
||||||
test_ignore = ["Customer"]
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
"doctype": "Time Log",
|
"doctype": "Time Log",
|
||||||
"from_time": "2013-01-01 10:00:00.000000",
|
"from_time": "2013-01-01 10:00:00.000000",
|
||||||
"note": "_Test Note",
|
"note": "_Test Note",
|
||||||
"to_time": "2013-01-01 11:00:00.000000",
|
"to_time": "2013-01-01 11:00:00.000000"
|
||||||
"project": "_Test Project"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -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.projects.doctype.time_log.time_log import NotSubmittedError
|
||||||
from erpnext.manufacturing.doctype.workstation.workstation import WorkstationHolidayError
|
from erpnext.manufacturing.doctype.workstation.workstation import WorkstationHolidayError
|
||||||
from erpnext.manufacturing.doctype.workstation.workstation import NotInWorkingHoursError
|
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
|
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"
|
test_time_log.to_time = "2013-01-01 10:00:00.000000"
|
||||||
self.assertRaises(frappe.ValidationError, test_time_log.save)
|
self.assertRaises(frappe.ValidationError, test_time_log.save)
|
||||||
frappe.db.sql("delete from `tabTime Log`")
|
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_records = frappe.get_test_records('Time Log')
|
||||||
test_ignore = ["Time Log Batch", "Sales Invoice"]
|
test_ignore = ["Time Log Batch", "Sales Invoice"]
|
||||||
|
|||||||
Reference in New Issue
Block a user