From ae4cc078ea23aaf34fe7ede14e46237d293a2433 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 16 Jun 2015 15:30:08 +0530 Subject: [PATCH] Activity Cost - Mandatory removed for Employee. --- .../doctype/activity_cost/activity_cost.json | 72 +++++++++---------- .../doctype/activity_cost/activity_cost.py | 25 ++++--- erpnext/projects/doctype/time_log/time_log.py | 3 + 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/erpnext/projects/doctype/activity_cost/activity_cost.json b/erpnext/projects/doctype/activity_cost/activity_cost.json index bdc147e5fb6..fafea58797a 100644 --- a/erpnext/projects/doctype/activity_cost/activity_cost.json +++ b/erpnext/projects/doctype/activity_cost/activity_cost.json @@ -9,41 +9,6 @@ "doctype": "DocType", "document_type": "Master", "fields": [ - { - "allow_on_submit": 0, - "fieldname": "employee", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Employee", - "no_copy": 0, - "options": "Employee", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0 - }, - { - "fieldname": "employee_name", - "fieldtype": "Data", - "label": "Employee Name", - "options": "", - "permlevel": 0, - "precision": "", - "read_only": 1 - }, - { - "fieldname": "column_break_2", - "fieldtype": "Column Break", - "permlevel": 0, - "precision": "" - }, { "allow_on_submit": 0, "fieldname": "activity_type", @@ -64,6 +29,41 @@ "search_index": 0, "set_only_once": 0 }, + { + "fieldname": "column_break_2", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, + { + "allow_on_submit": 0, + "fieldname": "employee", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Employee", + "no_copy": 0, + "options": "Employee", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0 + }, + { + "fieldname": "employee_name", + "fieldtype": "Data", + "label": "Employee Name", + "options": "", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, { "fieldname": "section_break_4", "fieldtype": "Section Break", @@ -136,7 +136,7 @@ "is_submittable": 0, "issingle": 0, "istable": 0, - "modified": "2015-06-11 06:50:47.999788", + "modified": "2015-06-16 03:12:25.644839", "modified_by": "Administrator", "module": "Projects", "name": "Activity Cost", diff --git a/erpnext/projects/doctype/activity_cost/activity_cost.py b/erpnext/projects/doctype/activity_cost/activity_cost.py index 8cd04f564a6..f2c50991ac3 100644 --- a/erpnext/projects/doctype/activity_cost/activity_cost.py +++ b/erpnext/projects/doctype/activity_cost/activity_cost.py @@ -15,12 +15,21 @@ class ActivityCost(Document): self.check_unique() def set_title(self): - if not self.employee_name: - self.employee_name = frappe.db.get_value("Employee", self.employee, "employee_name") - self.title = _("{0} for {1}").format(self.employee_name, self.activity_type) - + if self.employee: + if not self.employee_name: + self.employee_name = frappe.db.get_value("Employee", self.employee, "employee_name") + self.title = _("{0} for {1}").format(self.employee_name, self.activity_type) + else: + self.title = self.activity_type + def check_unique(self): - if frappe.db.sql("""select name from `tabActivity Cost` where employee_name= %s and activity_type= %s and name != %s""", - (self.employee_name, self.activity_type, self.name)): - frappe.throw(_("Activity Cost exists for Employee {0} against Activity Type - {1}") - .format(self.employee, self.activity_type), DuplicationError) + if self.employee: + if frappe.db.sql("""select name from `tabActivity Cost` where employee_name= %s and activity_type= %s and name != %s""", + (self.employee_name, self.activity_type, self.name)): + frappe.throw(_("Activity Cost exists for Employee {0} against Activity Type - {1}") + .format(self.employee, self.activity_type), DuplicationError) + else: + if frappe.db.sql("""select name from `tabActivity Cost` where employee_name IS NULL and activity_type= %s and name != %s""", + (self.activity_type, self.name)): + frappe.throw(_("Default Activity Cost exists for Activity Type - {0}") + .format(self.activity_type), DuplicationError) diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py index aa5647e8e82..e863561cb8f 100644 --- a/erpnext/projects/doctype/time_log/time_log.py +++ b/erpnext/projects/doctype/time_log/time_log.py @@ -272,4 +272,7 @@ def get_events(start, end, filters=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 and activity_type= %s""", (employee, activity_type), as_dict=1) + if not rate: + rate = frappe.db.sql("""select costing_rate, billing_rate from `tabActivity Cost` where employee IS NULL + and activity_type= %s""", (activity_type), as_dict=1) return rate[0] if rate else {}