From da8c6f6ae2333f91fac3944483a414ae0f9bcfb4 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 16 Apr 2015 11:25:34 +0530 Subject: [PATCH] test case fix for Time Log --- .../doctype/time_log/test_time_log.py | 11 +++++++++ erpnext/projects/doctype/time_log/time_log.py | 23 ++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/erpnext/projects/doctype/time_log/test_time_log.py b/erpnext/projects/doctype/time_log/test_time_log.py index 019d59694f..3d9e0be5f9 100644 --- a/erpnext/projects/doctype/time_log/test_time_log.py +++ b/erpnext/projects/doctype/time_log/test_time_log.py @@ -88,6 +88,17 @@ class TestTimeLog(unittest.TestCase): def test_total_activity_cost_for_project(self): frappe.db.sql("""delete from `tabTask` where project = "_Test Project 1" """) frappe.db.sql("""delete from `tabProject` where name = "_Test Project 1" """) + frappe.db.sql("""delete from `tabActivity Cost` where employee = "_T-Employee-0001" and activity_type = "_Test Activity Type" """) + + activity_cost = frappe.new_doc('Activity Cost') + activity_cost.update({ + "employee": "_T-Employee-0001", + "employee_name": "_Test Employee", + "activity_type": "_Test Activity Type", + "billing_rate": 100, + "costing_rate": 50 + }) + activity_cost.insert() frappe.get_doc({ "project_name": "_Test Project 1", diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py index 2018425055..1ee825f6eb 100644 --- a/erpnext/projects/doctype/time_log/time_log.py +++ b/erpnext/projects/doctype/time_log/time_log.py @@ -28,16 +28,12 @@ class TimeLog(Document): self.validate_cost() def on_submit(self): - if self.for_manufacturing: - self.update_production_order() - if self.task: - self.update_task() + self.update_production_order() + self.update_task() def on_cancel(self): - if self.for_manufacturing: - self.update_production_order() - if self.task: - self.update_task() + self.update_production_order() + self.update_task() def before_update_after_submit(self): self.set_status() @@ -132,8 +128,8 @@ class TimeLog(Document): def update_production_order(self): """Updates `start_date`, `end_date`, `status` for operation in Production Order.""" - - if self.production_order: + + if self.production_order and self.for_manufacturing: if not self.operation_id: frappe.throw(_("Operation ID not set")) @@ -231,9 +227,10 @@ class TimeLog(Document): frappe.throw(_("Task is Mandatory if Time Log is against a project")) def update_task(self): - task = frappe.get_doc("Task", self.task) - task.update_time_and_costing() - task.save() + if self.task and frappe.db.exists("Task", self.task): + task = frappe.get_doc("Task", self.task) + task.update_time_and_costing() + task.save() @frappe.whitelist() def get_events(start, end, filters=None):