From cf414cc4994d517ccf378ab7df6270b0db21b6be Mon Sep 17 00:00:00 2001 From: Jamsheer Date: Tue, 22 May 2018 14:22:42 +0530 Subject: [PATCH] Payroll Period - fields refactor --- ...test_employee_tax_exemption_declaration.py | 6 +- .../payroll_period/payroll_period.json | 127 +++++++++++++++++- .../doctype/payroll_period/payroll_period.py | 9 +- erpnext/hr/utils.py | 7 +- 4 files changed, 133 insertions(+), 16 deletions(-) diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py b/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py index 84970d85fd..dff02eac14 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py +++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py @@ -84,10 +84,8 @@ def create_payroll_period(): doctype = 'Payroll Period', name = "_Test Payroll Period", company = "_Test Company", - periods = [ - dict(start_date = date(date.today().year, 1, 1), - end_date = date(date.today().year, 12, 31)) - ] + start_date = date(date.today().year, 1, 1), + end_date = date(date.today().year, 12, 31) )).insert() def create_exemption_category(): diff --git a/erpnext/hr/doctype/payroll_period/payroll_period.json b/erpnext/hr/doctype/payroll_period/payroll_period.json index 44ead2bc27..61d07631c0 100644 --- a/erpnext/hr/doctype/payroll_period/payroll_period.json +++ b/erpnext/hr/doctype/payroll_period/payroll_period.json @@ -45,6 +45,129 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "column_break_2", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "start_date", + "fieldtype": "Date", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Start Date", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "end_date", + "fieldtype": "Date", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "End Date", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "section_break_5", + "fieldtype": "Section Break", + "hidden": 1, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Payroll Periods", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -71,7 +194,7 @@ "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 1, + "reqd": 0, "search_index": 0, "set_only_once": 0, "translatable": 0, @@ -88,7 +211,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-04-13 19:38:28.013664", + "modified": "2018-05-22 14:15:59.968204", "modified_by": "Administrator", "module": "HR", "name": "Payroll Period", diff --git a/erpnext/hr/doctype/payroll_period/payroll_period.py b/erpnext/hr/doctype/payroll_period/payroll_period.py index a818bc4276..0bf2b7958e 100644 --- a/erpnext/hr/doctype/payroll_period/payroll_period.py +++ b/erpnext/hr/doctype/payroll_period/payroll_period.py @@ -12,13 +12,10 @@ class PayrollPeriod(Document): def get_payroll_period_days(start_date, end_date, company): payroll_period_dates = frappe.db.sql(""" - select ppd.start_date, ppd.end_date from `tabPayroll Period Date` ppd, `tabPayroll Period` pp - where pp.company=%(company)s - and ppd.parent = pp.name + select start_date, end_date from `tabPayroll Period` + where company=%(company)s and ( - (%(start_date)s between ppd.start_date and ppd.end_date) - or (%(end_date)s between ppd.start_date and ppd.end_date) - or (ppd.start_date between %(start_date)s and %(end_date)s) + start_date between %(start_date)s and %(end_date)s )""", { 'company': company, 'start_date': start_date, diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index 20fe666d2b..bf37c126ea 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -236,8 +236,7 @@ def get_leave_period(from_date, to_date, company): return leave_period def get_payroll_period(from_date, to_date, company): - payroll_period = frappe.db.sql("""select pp.name, pd.start_date, pd.end_date from - `tabPayroll Period Date` pd join `tabPayroll Period` pp on - pd.parent=pp.name where pd.start_date<=%s and pd.end_date>= %s - and pp.company=%s""", (from_date, to_date, company), as_dict=1) + payroll_period = frappe.db.sql("""select name, start_date, end_date from + `tabPayroll Period` + where start_date<=%s and end_date>= %s and company=%s""", (from_date, to_date, company), as_dict=1) return payroll_period[0] if payroll_period else None