From c6b52d55b306ccd3ab448200dca66546d857b2d6 Mon Sep 17 00:00:00 2001 From: krantheman Date: Fri, 5 Jan 2024 13:10:38 +0530 Subject: [PATCH 01/16] refactor: remove 'Create Employee' step (cherry picked from commit 63d28f1a9b55686b7efd7f64774cebdd8a932b33) --- hrms/payroll/module_onboarding/payroll/payroll.json | 5 +---- .../assign_salary_structure/assign_salary_structure.json | 2 +- .../create_income_tax_slab/create_income_tax_slab.json | 2 +- .../create_payroll_period/create_payroll_period.json | 2 +- .../create_salary_component/create_salary_component.json | 2 +- .../create_salary_slip/create_salary_slip.json | 2 +- .../create_salary_structure/create_salary_structure.json | 2 +- .../onboarding_step/payroll_settings/payroll_settings.json | 2 +- 8 files changed, 8 insertions(+), 11 deletions(-) diff --git a/hrms/payroll/module_onboarding/payroll/payroll.json b/hrms/payroll/module_onboarding/payroll/payroll.json index b5226b2aca..2ef3720d8c 100644 --- a/hrms/payroll/module_onboarding/payroll/payroll.json +++ b/hrms/payroll/module_onboarding/payroll/payroll.json @@ -13,15 +13,12 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/human-resources/payroll-entry", "idx": 0, "is_complete": 0, - "modified": "2020-07-08 14:06:13.994310", + "modified": "2024-01-05 13:05:01.281209", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll", "owner": "Administrator", "steps": [ - { - "step": "Create Employee" - }, { "step": "Create Salary Component" }, diff --git a/hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json b/hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json index 8a07b10276..824f259f0d 100644 --- a/hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json +++ b/hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, "modified": "2020-06-01 11:58:43.927590", @@ -13,6 +12,7 @@ "name": "Assign Salary Structure", "owner": "Administrator", "reference_document": "Salary Structure Assignment", + "show_form_tour": 0, "show_full_form": 1, "title": "Assign Salary Structure", "validate_action": 1 diff --git a/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json b/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json index faada7e411..91e2d840b4 100644 --- a/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json +++ b/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-06-01 11:54:54.823796", @@ -13,6 +12,7 @@ "name": "Create Income Tax Slab", "owner": "Administrator", "reference_document": "Income Tax Slab", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Income Tax Slab", "validate_action": 1 diff --git a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json index b1a7cc2734..944776676e 100644 --- a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json +++ b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, "modified": "2020-06-29 11:53:54.553947", @@ -13,6 +12,7 @@ "name": "Create Payroll Period", "owner": "Administrator", "reference_document": "Payroll Period", + "show_form_tour": 0, "show_full_form": 0, "title": "Create Payroll Period", "validate_action": 1 diff --git a/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json b/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json index 002d819618..e5538c7e57 100644 --- a/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json +++ b/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-06-01 11:57:04.002073", @@ -13,6 +12,7 @@ "name": "Create Salary Component", "owner": "Administrator", "reference_document": "Salary Component", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Salary Component", "validate_action": 1 diff --git a/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json b/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json index 2aa31f485f..e55ff7799b 100644 --- a/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json +++ b/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, "modified": "2020-06-01 11:59:29.972393", @@ -13,6 +12,7 @@ "name": "Create Salary Slip", "owner": "Administrator", "reference_document": "Salary Slip", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Salary Slip", "validate_action": 1 diff --git a/hrms/payroll/onboarding_step/create_salary_structure/create_salary_structure.json b/hrms/payroll/onboarding_step/create_salary_structure/create_salary_structure.json index 11d8327259..9629b07aea 100644 --- a/hrms/payroll/onboarding_step/create_salary_structure/create_salary_structure.json +++ b/hrms/payroll/onboarding_step/create_salary_structure/create_salary_structure.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, "modified": "2020-06-01 11:57:54.527808", @@ -13,6 +12,7 @@ "name": "Create Salary Structure", "owner": "Administrator", "reference_document": "Salary Structure", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Salary Structure", "validate_action": 1 diff --git a/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json b/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json index a7cf7bf988..a31098f2dc 100644 --- a/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json +++ b/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 1, "is_skipped": 0, "modified": "2020-06-29 16:34:29.664917", @@ -13,6 +12,7 @@ "name": "Payroll Settings", "owner": "Administrator", "reference_document": "Payroll Settings", + "show_form_tour": 0, "show_full_form": 0, "title": "Payroll Settings", "validate_action": 0 From 99dfea1aaa7fa5b193f2f9511c7f4b9141788955 Mon Sep 17 00:00:00 2001 From: krantheman Date: Fri, 5 Jan 2024 16:55:00 +0530 Subject: [PATCH 02/16] feat: Preview Salary Slip from Salary Structure Assignment (cherry picked from commit 65547990cb1699f37214b5ccdf6dff7aea832e35) # Conflicts: # hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js --- .../salary_structure_assignment.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js index c5cc87f2ba..b216566d2f 100644 --- a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js +++ b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js @@ -59,6 +59,7 @@ frappe.ui.form.on("Salary Structure Assignment", { frm.trigger("set_earnings_and_taxation_section_visibility"); } +<<<<<<< HEAD if (frm.doc.docstatus != 1) return; frm.add_custom_button( __("Payroll Entry"), @@ -71,6 +72,12 @@ frappe.ui.form.on("Salary Structure Assignment", { __("Create"), ); frm.page.set_inner_btn_group_as_primary(__("Create")); +======= + if (frm.doc.docstatus === 1) + frm.add_custom_button(__("Preview Salary Slip"), function () { + frm.trigger("preview_salary_slip"); + }); +>>>>>>> 65547990c (feat: Preview Salary Slip from Salary Structure Assignment) }, employee: function (frm) { @@ -89,6 +96,7 @@ frappe.ui.form.on("Salary Structure Assignment", { frm.doc.company, "default_payroll_payable_account", (r) => { +<<<<<<< HEAD frm.set_value("payroll_payable_account", r.default_payroll_payable_account); }, ); @@ -107,6 +115,60 @@ frappe.ui.form.on("Salary Structure Assignment", { } }, +======= + frm.set_value( + "payroll_payable_account", + r.default_payroll_payable_account + ); + } + ); + } + }, + + preview_salary_slip: function (frm) { + frappe.db.get_value( + "Salary Structure", + frm.doc.salary_structure, + "salary_slip_based_on_timesheet", + (r) => { + const print_format = r.salary_slip_based_on_timesheet + ? "Salary Slip based on Timesheet" + : "Salary Slip Standard"; + frappe.call({ + method: + "hrms.payroll.doctype.salary_structure.salary_structure.make_salary_slip", + args: { + source_name: frm.doc.salary_structure, + employee: frm.doc.employee, + as_print: 1, + print_format: print_format, + for_preview: 1, + }, + callback: function (r) { + const new_window = window.open(); + new_window.document.write(r.message); + }, + }); + } + ); + }, + + set_payroll_cost_centers: function (frm) { + if ( + frm.doc.payroll_cost_centers && + frm.doc.payroll_cost_centers.length < 1 + ) { + frappe.call({ + method: "set_payroll_cost_centers", + doc: frm.doc, + callback: function (data) { + refresh_field("payroll_cost_centers"); + }, + }); + } + }, + +>>>>>>> 65547990c (feat: Preview Salary Slip from Salary Structure Assignment) valiadte_joining_date_and_salary_slips: function (frm) { frappe.call({ method: "earning_and_deduction_entries_does_not_exists", From 11b3ba61876ebe77fc1ed66ae6a1f7b0d61029bf Mon Sep 17 00:00:00 2001 From: krantheman Date: Thu, 11 Jan 2024 13:38:05 +0530 Subject: [PATCH 03/16] refactor: combine Create & Assign Salary Structure step (cherry picked from commit 9bf03cc704bab5278971052e9b3158fe7427feb4) --- .../module_onboarding/payroll/payroll.json | 7 ++----- .../assign_salary_structure.json | 19 ------------------- .../create_&_assign_salary_structure.json} | 10 +++++----- .../create_employee/create_employee.json | 19 ------------------- .../create_income_tax_slab.json | 2 +- .../create_payroll_period.json | 2 +- .../create_salary_component.json | 4 ++-- .../create_salary_slip.json | 2 +- .../payroll_settings/payroll_settings.json | 2 +- 9 files changed, 13 insertions(+), 54 deletions(-) delete mode 100644 hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json rename hrms/payroll/onboarding_step/{create_salary_structure/create_salary_structure.json => create_&_assign_salary_structure/create_&_assign_salary_structure.json} (59%) delete mode 100644 hrms/payroll/onboarding_step/create_employee/create_employee.json diff --git a/hrms/payroll/module_onboarding/payroll/payroll.json b/hrms/payroll/module_onboarding/payroll/payroll.json index 2ef3720d8c..bd0fabcf0f 100644 --- a/hrms/payroll/module_onboarding/payroll/payroll.json +++ b/hrms/payroll/module_onboarding/payroll/payroll.json @@ -13,7 +13,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/human-resources/payroll-entry", "idx": 0, "is_complete": 0, - "modified": "2024-01-05 13:05:01.281209", + "modified": "2024-01-11 13:25:33.806391", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll", @@ -29,10 +29,7 @@ "step": "Create Income Tax Slab" }, { - "step": "Create Salary Structure" - }, - { - "step": "Assign Salary Structure" + "step": "Create & Assign Salary Structure" }, { "step": "Create Salary Slip" diff --git a/hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json b/hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json deleted file mode 100644 index 824f259f0d..0000000000 --- a/hrms/payroll/onboarding_step/assign_salary_structure/assign_salary_structure.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "action": "Create Entry", - "creation": "2020-06-01 11:58:43.927590", - "docstatus": 0, - "doctype": "Onboarding Step", - "idx": 0, - "is_complete": 0, - "is_single": 0, - "is_skipped": 0, - "modified": "2020-06-01 11:58:43.927590", - "modified_by": "Administrator", - "name": "Assign Salary Structure", - "owner": "Administrator", - "reference_document": "Salary Structure Assignment", - "show_form_tour": 0, - "show_full_form": 1, - "title": "Assign Salary Structure", - "validate_action": 1 -} \ No newline at end of file diff --git a/hrms/payroll/onboarding_step/create_salary_structure/create_salary_structure.json b/hrms/payroll/onboarding_step/create_&_assign_salary_structure/create_&_assign_salary_structure.json similarity index 59% rename from hrms/payroll/onboarding_step/create_salary_structure/create_salary_structure.json rename to hrms/payroll/onboarding_step/create_&_assign_salary_structure/create_&_assign_salary_structure.json index 9629b07aea..c6689448c3 100644 --- a/hrms/payroll/onboarding_step/create_salary_structure/create_salary_structure.json +++ b/hrms/payroll/onboarding_step/create_&_assign_salary_structure/create_&_assign_salary_structure.json @@ -1,19 +1,19 @@ { "action": "Create Entry", - "creation": "2020-06-01 11:57:54.527808", + "creation": "2024-01-11 13:25:28.533290", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-06-01 11:57:54.527808", + "modified": "2024-01-11 13:25:28.533290", "modified_by": "Administrator", - "name": "Create Salary Structure", + "name": "Create & Assign Salary Structure", "owner": "Administrator", "reference_document": "Salary Structure", "show_form_tour": 0, - "show_full_form": 1, - "title": "Create Salary Structure", + "show_full_form": 0, + "title": "Create & Assign Salary Structure", "validate_action": 1 } \ No newline at end of file diff --git a/hrms/payroll/onboarding_step/create_employee/create_employee.json b/hrms/payroll/onboarding_step/create_employee/create_employee.json deleted file mode 100644 index 3aa33c6d86..0000000000 --- a/hrms/payroll/onboarding_step/create_employee/create_employee.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "action": "Create Entry", - "creation": "2020-05-14 11:43:25.561152", - "docstatus": 0, - "doctype": "Onboarding Step", - "idx": 0, - "is_complete": 0, - "is_mandatory": 1, - "is_single": 0, - "is_skipped": 0, - "modified": "2020-05-14 12:26:28.629074", - "modified_by": "Administrator", - "name": "Create Employee", - "owner": "Administrator", - "reference_document": "Employee", - "show_full_form": 0, - "title": "Create Employee", - "validate_action": 0 -} \ No newline at end of file diff --git a/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json b/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json index 91e2d840b4..696e3b5edf 100644 --- a/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json +++ b/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json @@ -3,7 +3,7 @@ "creation": "2020-06-01 11:54:54.823796", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 0, + "idx": 1, "is_complete": 0, "is_single": 0, "is_skipped": 0, diff --git a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json index 944776676e..64cd21770e 100644 --- a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json +++ b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json @@ -3,7 +3,7 @@ "creation": "2020-06-01 11:53:54.553947", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 0, + "idx": 1, "is_complete": 0, "is_single": 0, "is_skipped": 0, diff --git a/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json b/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json index e5538c7e57..8aafabc1ce 100644 --- a/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json +++ b/hrms/payroll/onboarding_step/create_salary_component/create_salary_component.json @@ -3,11 +3,11 @@ "creation": "2020-06-01 11:57:04.002073", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 0, + "idx": 1, "is_complete": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-06-01 11:57:04.002073", + "modified": "2024-01-05 13:16:07.648744", "modified_by": "Administrator", "name": "Create Salary Component", "owner": "Administrator", diff --git a/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json b/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json index e55ff7799b..37ddada05a 100644 --- a/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json +++ b/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json @@ -3,7 +3,7 @@ "creation": "2020-06-01 11:59:29.972393", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 0, + "idx": 1, "is_complete": 0, "is_single": 0, "is_skipped": 0, diff --git a/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json b/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json index a31098f2dc..2f8cc3dc1c 100644 --- a/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json +++ b/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json @@ -3,7 +3,7 @@ "creation": "2020-06-04 16:34:29.664917", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 0, + "idx": 1, "is_complete": 0, "is_single": 1, "is_skipped": 0, From e91def28e9ed518f0d61b83e1ca544c5a1851914 Mon Sep 17 00:00:00 2001 From: krantheman Date: Fri, 12 Jan 2024 13:24:54 +0530 Subject: [PATCH 04/16] feat(Create Payroll Period): set Start & End Date as that of Fiscal Year if no Payroll Period exists (cherry picked from commit a3060da3d5d30af939d77d46210e7f3d440e1a17) # Conflicts: # hrms/payroll/doctype/payroll_period/payroll_period.js --- .../doctype/payroll_period/payroll_period.js | 15 +++++++++++++++ .../create_payroll_period.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hrms/payroll/doctype/payroll_period/payroll_period.js b/hrms/payroll/doctype/payroll_period/payroll_period.js index 5f4bc7c113..eae5ff48e3 100644 --- a/hrms/payroll/doctype/payroll_period/payroll_period.js +++ b/hrms/payroll/doctype/payroll_period/payroll_period.js @@ -2,5 +2,20 @@ // For license information, please see license.txt frappe.ui.form.on("Payroll Period", { +<<<<<<< HEAD refresh: function (frm) {}, +======= + refresh: function (frm) { + // sets start date and end date as that of the current fiscal year if no payroll period exists + frappe.db.exists("Payroll Period").then((period_exists) => { + if (!period_exists) { + frm.set_value( + "start_date", + frappe.defaults.get_default("year_start_date") + ); + frm.set_value("end_date", frappe.defaults.get_default("year_end_date")); + } + }); + }, +>>>>>>> a3060da3d (feat(Create Payroll Period): set Start & End Date as that of Fiscal Year if no Payroll Period exists) }); diff --git a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json index 64cd21770e..0fd83732cf 100644 --- a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json +++ b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json @@ -13,7 +13,7 @@ "owner": "Administrator", "reference_document": "Payroll Period", "show_form_tour": 0, - "show_full_form": 0, + "show_full_form": 1, "title": "Create Payroll Period", "validate_action": 1 } \ No newline at end of file From e2991a5098f879a90142b14fa089257994b49316 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 3 May 2024 14:44:08 +0530 Subject: [PATCH 05/16] chore: fix linter (cherry picked from commit 6f0cab593f7e512f495043aa59db3160cba56792) # Conflicts: # hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js --- .../doctype/payroll_period/payroll_period.js | 5 +---- .../salary_structure_assignment.js | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hrms/payroll/doctype/payroll_period/payroll_period.js b/hrms/payroll/doctype/payroll_period/payroll_period.js index eae5ff48e3..21b5711dc2 100644 --- a/hrms/payroll/doctype/payroll_period/payroll_period.js +++ b/hrms/payroll/doctype/payroll_period/payroll_period.js @@ -9,10 +9,7 @@ frappe.ui.form.on("Payroll Period", { // sets start date and end date as that of the current fiscal year if no payroll period exists frappe.db.exists("Payroll Period").then((period_exists) => { if (!period_exists) { - frm.set_value( - "start_date", - frappe.defaults.get_default("year_start_date") - ); + frm.set_value("start_date", frappe.defaults.get_default("year_start_date")); frm.set_value("end_date", frappe.defaults.get_default("year_end_date")); } }); diff --git a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js index b216566d2f..c73c9ccff7 100644 --- a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js +++ b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js @@ -76,8 +76,14 @@ frappe.ui.form.on("Salary Structure Assignment", { if (frm.doc.docstatus === 1) frm.add_custom_button(__("Preview Salary Slip"), function () { frm.trigger("preview_salary_slip"); +<<<<<<< HEAD }); >>>>>>> 65547990c (feat: Preview Salary Slip from Salary Structure Assignment) +======= + }, + __("Actions"), + ); +>>>>>>> 6f0cab593 (chore: fix linter) }, employee: function (frm) { @@ -96,6 +102,7 @@ frappe.ui.form.on("Salary Structure Assignment", { frm.doc.company, "default_payroll_payable_account", (r) => { +<<<<<<< HEAD <<<<<<< HEAD frm.set_value("payroll_payable_account", r.default_payroll_payable_account); }, @@ -121,6 +128,10 @@ frappe.ui.form.on("Salary Structure Assignment", { r.default_payroll_payable_account ); } +======= + frm.set_value("payroll_payable_account", r.default_payroll_payable_account); + }, +>>>>>>> 6f0cab593 (chore: fix linter) ); } }, @@ -135,8 +146,7 @@ frappe.ui.form.on("Salary Structure Assignment", { ? "Salary Slip based on Timesheet" : "Salary Slip Standard"; frappe.call({ - method: - "hrms.payroll.doctype.salary_structure.salary_structure.make_salary_slip", + method: "hrms.payroll.doctype.salary_structure.salary_structure.make_salary_slip", args: { source_name: frm.doc.salary_structure, employee: frm.doc.employee, @@ -149,15 +159,12 @@ frappe.ui.form.on("Salary Structure Assignment", { new_window.document.write(r.message); }, }); - } + }, ); }, set_payroll_cost_centers: function (frm) { - if ( - frm.doc.payroll_cost_centers && - frm.doc.payroll_cost_centers.length < 1 - ) { + if (frm.doc.payroll_cost_centers && frm.doc.payroll_cost_centers.length < 1) { frappe.call({ method: "set_payroll_cost_centers", doc: frm.doc, From 15c8163000049ca57244f120a6e137e0ecce1bf4 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 7 May 2024 17:48:36 +0530 Subject: [PATCH 06/16] fix: set payroll period dates based on last payroll period/current fiscal year - disable quick entry for payroll period to make the form scripts work (cherry picked from commit 22a9000b370ecc28dafdc9600e1dd8679407675b) # Conflicts: # hrms/payroll/doctype/payroll_period/payroll_period.js # hrms/payroll/doctype/payroll_period/payroll_period.json --- .../doctype/payroll_period/payroll_period.js | 33 +++++++++++++++++++ .../payroll_period/payroll_period.json | 8 +++++ 2 files changed, 41 insertions(+) diff --git a/hrms/payroll/doctype/payroll_period/payroll_period.js b/hrms/payroll/doctype/payroll_period/payroll_period.js index 21b5711dc2..651d3bdbb8 100644 --- a/hrms/payroll/doctype/payroll_period/payroll_period.js +++ b/hrms/payroll/doctype/payroll_period/payroll_period.js @@ -2,6 +2,7 @@ // For license information, please see license.txt frappe.ui.form.on("Payroll Period", { +<<<<<<< HEAD <<<<<<< HEAD refresh: function (frm) {}, ======= @@ -13,6 +14,38 @@ frappe.ui.form.on("Payroll Period", { frm.set_value("end_date", frappe.defaults.get_default("year_end_date")); } }); +======= + onload: function (frm) { + frm.trigger("set_start_date"); + }, + + set_start_date: function (frm) { + if (!frm.doc.__islocal) return; + + frappe.db + .get_list("Payroll Period", { + fields: ["end_date"], + order_by: "end_date desc", + limit: 1, + }) + .then((result) => { + // set start date based on end date of the last payroll period if found + // else set it based on the current fiscal year's start date + if (result.length) { + const last_end_date = result[0].end_date; + frm.set_value("start_date", frappe.datetime.add_days(last_end_date, 1)); + } else { + frm.set_value("start_date", frappe.defaults.get_default("year_start_date")); + } + }); + }, + + start_date: function (frm) { + frm.set_value( + "end_date", + frappe.datetime.add_days(frappe.datetime.add_months(frm.doc.start_date, 12), -1), + ); +>>>>>>> 22a9000b3 (fix: set payroll period dates based on last payroll period/current fiscal year) }, >>>>>>> a3060da3d (feat(Create Payroll Period): set Start & End Date as that of Fiscal Year if no Payroll Period exists) }); diff --git a/hrms/payroll/doctype/payroll_period/payroll_period.json b/hrms/payroll/doctype/payroll_period/payroll_period.json index ee729a586d..ed0ca4e433 100644 --- a/hrms/payroll/doctype/payroll_period/payroll_period.json +++ b/hrms/payroll/doctype/payroll_period/payroll_period.json @@ -53,7 +53,11 @@ } ], "links": [], +<<<<<<< HEAD "modified": "2024-05-05 14:50:12.419714", +======= + "modified": "2024-05-07 17:27:51.903593", +>>>>>>> 22a9000b3 (fix: set payroll period dates based on last payroll period/current fiscal year) "modified_by": "Administrator", "module": "Payroll", "name": "Payroll Period", @@ -105,8 +109,12 @@ "write": 1 } ], +<<<<<<< HEAD "quick_entry": 1, "sort_field": "modified", +======= + "sort_field": "creation", +>>>>>>> 22a9000b3 (fix: set payroll period dates based on last payroll period/current fiscal year) "sort_order": "DESC", "track_changes": 1 } \ No newline at end of file From ef828ea63d069f0f56a2c9f6d638eead4f6c192a Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 7 May 2024 17:48:46 +0530 Subject: [PATCH 07/16] fix: open full forms instead of quick entries in onboarding, update button labels (cherry picked from commit 1dad38556c09b1ea5017aee72f9011b4bfbfaace) --- hrms/payroll/module_onboarding/payroll/payroll.json | 4 ++-- .../create_&_assign_salary_structure.json | 4 ++-- .../create_income_tax_slab/create_income_tax_slab.json | 4 ++-- .../create_payroll_period/create_payroll_period.json | 4 ++-- .../create_salary_slip/create_salary_slip.json | 4 ++-- .../onboarding_step/payroll_settings/payroll_settings.json | 5 +++-- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hrms/payroll/module_onboarding/payroll/payroll.json b/hrms/payroll/module_onboarding/payroll/payroll.json index bd0fabcf0f..0f31eada41 100644 --- a/hrms/payroll/module_onboarding/payroll/payroll.json +++ b/hrms/payroll/module_onboarding/payroll/payroll.json @@ -10,10 +10,10 @@ "creation": "2020-06-01 12:10:52.560472", "docstatus": 0, "doctype": "Module Onboarding", - "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/human-resources/payroll-entry", + "documentation_url": "https://frappehr.com/docs/v14/en/payroll-entry", "idx": 0, "is_complete": 0, - "modified": "2024-01-11 13:25:33.806391", + "modified": "2024-05-07 17:44:05.258878", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll", diff --git a/hrms/payroll/onboarding_step/create_&_assign_salary_structure/create_&_assign_salary_structure.json b/hrms/payroll/onboarding_step/create_&_assign_salary_structure/create_&_assign_salary_structure.json index c6689448c3..493fb76815 100644 --- a/hrms/payroll/onboarding_step/create_&_assign_salary_structure/create_&_assign_salary_structure.json +++ b/hrms/payroll/onboarding_step/create_&_assign_salary_structure/create_&_assign_salary_structure.json @@ -7,13 +7,13 @@ "is_complete": 0, "is_single": 0, "is_skipped": 0, - "modified": "2024-01-11 13:25:28.533290", + "modified": "2024-05-07 17:34:43.473732", "modified_by": "Administrator", "name": "Create & Assign Salary Structure", "owner": "Administrator", "reference_document": "Salary Structure", "show_form_tour": 0, - "show_full_form": 0, + "show_full_form": 1, "title": "Create & Assign Salary Structure", "validate_action": 1 } \ No newline at end of file diff --git a/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json b/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json index 696e3b5edf..d52f38ace8 100644 --- a/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json +++ b/hrms/payroll/onboarding_step/create_income_tax_slab/create_income_tax_slab.json @@ -3,11 +3,11 @@ "creation": "2020-06-01 11:54:54.823796", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 1, + "idx": 0, "is_complete": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-06-01 11:54:54.823796", + "modified": "2023-12-11 16:07:30.639441", "modified_by": "Administrator", "name": "Create Income Tax Slab", "owner": "Administrator", diff --git a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json index 0fd83732cf..6050e37ce9 100644 --- a/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json +++ b/hrms/payroll/onboarding_step/create_payroll_period/create_payroll_period.json @@ -3,11 +3,11 @@ "creation": "2020-06-01 11:53:54.553947", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 1, + "idx": 0, "is_complete": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-06-29 11:53:54.553947", + "modified": "2024-05-07 17:32:29.087876", "modified_by": "Administrator", "name": "Create Payroll Period", "owner": "Administrator", diff --git a/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json b/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json index 37ddada05a..c4ea06e8ea 100644 --- a/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json +++ b/hrms/payroll/onboarding_step/create_salary_slip/create_salary_slip.json @@ -3,11 +3,11 @@ "creation": "2020-06-01 11:59:29.972393", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 1, + "idx": 0, "is_complete": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-06-01 11:59:29.972393", + "modified": "2023-12-11 16:07:30.648979", "modified_by": "Administrator", "name": "Create Salary Slip", "owner": "Administrator", diff --git a/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json b/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json index 2f8cc3dc1c..9c4a9f7a3f 100644 --- a/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json +++ b/hrms/payroll/onboarding_step/payroll_settings/payroll_settings.json @@ -1,13 +1,14 @@ { "action": "Update Settings", + "action_label": "Review Payroll Settings", "creation": "2020-06-04 16:34:29.664917", "docstatus": 0, "doctype": "Onboarding Step", - "idx": 1, + "idx": 0, "is_complete": 0, "is_single": 1, "is_skipped": 0, - "modified": "2020-06-29 16:34:29.664917", + "modified": "2024-05-07 17:43:49.900487", "modified_by": "Administrator", "name": "Payroll Settings", "owner": "Administrator", From 9b9baafce6ee13575040a5db50e7b33b191e2c94 Mon Sep 17 00:00:00 2001 From: krantheman Date: Fri, 10 May 2024 11:42:47 +0530 Subject: [PATCH 08/16] fix: merge conflicts --- .../doctype/payroll_period/payroll_period.js | 9 +--- .../payroll_period/payroll_period.json | 11 +---- .../salary_structure_assignment.js | 44 +++---------------- 3 files changed, 8 insertions(+), 56 deletions(-) diff --git a/hrms/payroll/doctype/payroll_period/payroll_period.js b/hrms/payroll/doctype/payroll_period/payroll_period.js index 651d3bdbb8..47425ce69b 100644 --- a/hrms/payroll/doctype/payroll_period/payroll_period.js +++ b/hrms/payroll/doctype/payroll_period/payroll_period.js @@ -2,10 +2,6 @@ // For license information, please see license.txt frappe.ui.form.on("Payroll Period", { -<<<<<<< HEAD -<<<<<<< HEAD - refresh: function (frm) {}, -======= refresh: function (frm) { // sets start date and end date as that of the current fiscal year if no payroll period exists frappe.db.exists("Payroll Period").then((period_exists) => { @@ -14,7 +10,8 @@ frappe.ui.form.on("Payroll Period", { frm.set_value("end_date", frappe.defaults.get_default("year_end_date")); } }); -======= + }, + onload: function (frm) { frm.trigger("set_start_date"); }, @@ -45,7 +42,5 @@ frappe.ui.form.on("Payroll Period", { "end_date", frappe.datetime.add_days(frappe.datetime.add_months(frm.doc.start_date, 12), -1), ); ->>>>>>> 22a9000b3 (fix: set payroll period dates based on last payroll period/current fiscal year) }, ->>>>>>> a3060da3d (feat(Create Payroll Period): set Start & End Date as that of Fiscal Year if no Payroll Period exists) }); diff --git a/hrms/payroll/doctype/payroll_period/payroll_period.json b/hrms/payroll/doctype/payroll_period/payroll_period.json index ed0ca4e433..46f06349d0 100644 --- a/hrms/payroll/doctype/payroll_period/payroll_period.json +++ b/hrms/payroll/doctype/payroll_period/payroll_period.json @@ -53,11 +53,7 @@ } ], "links": [], -<<<<<<< HEAD - "modified": "2024-05-05 14:50:12.419714", -======= "modified": "2024-05-07 17:27:51.903593", ->>>>>>> 22a9000b3 (fix: set payroll period dates based on last payroll period/current fiscal year) "modified_by": "Administrator", "module": "Payroll", "name": "Payroll Period", @@ -109,12 +105,7 @@ "write": 1 } ], -<<<<<<< HEAD - "quick_entry": 1, - "sort_field": "modified", -======= "sort_field": "creation", ->>>>>>> 22a9000b3 (fix: set payroll period dates based on last payroll period/current fiscal year) "sort_order": "DESC", "track_changes": 1 -} \ No newline at end of file +} diff --git a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js index c73c9ccff7..7f84ade402 100644 --- a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js +++ b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js @@ -59,8 +59,8 @@ frappe.ui.form.on("Salary Structure Assignment", { frm.trigger("set_earnings_and_taxation_section_visibility"); } -<<<<<<< HEAD if (frm.doc.docstatus != 1) return; + frm.add_custom_button( __("Payroll Entry"), () => { @@ -72,18 +72,14 @@ frappe.ui.form.on("Salary Structure Assignment", { __("Create"), ); frm.page.set_inner_btn_group_as_primary(__("Create")); -======= - if (frm.doc.docstatus === 1) - frm.add_custom_button(__("Preview Salary Slip"), function () { + + frm.add_custom_button( + __("Preview Salary Slip"), + function () { frm.trigger("preview_salary_slip"); -<<<<<<< HEAD - }); ->>>>>>> 65547990c (feat: Preview Salary Slip from Salary Structure Assignment) -======= }, __("Actions"), ); ->>>>>>> 6f0cab593 (chore: fix linter) }, employee: function (frm) { @@ -102,40 +98,12 @@ frappe.ui.form.on("Salary Structure Assignment", { frm.doc.company, "default_payroll_payable_account", (r) => { -<<<<<<< HEAD -<<<<<<< HEAD frm.set_value("payroll_payable_account", r.default_payroll_payable_account); }, ); } }, - set_payroll_cost_centers: function (frm) { - if (frm.doc.payroll_cost_centers && frm.doc.payroll_cost_centers.length < 1) { - frappe.call({ - method: "set_payroll_cost_centers", - doc: frm.doc, - callback: function (data) { - refresh_field("payroll_cost_centers"); - }, - }); - } - }, - -======= - frm.set_value( - "payroll_payable_account", - r.default_payroll_payable_account - ); - } -======= - frm.set_value("payroll_payable_account", r.default_payroll_payable_account); - }, ->>>>>>> 6f0cab593 (chore: fix linter) - ); - } - }, - preview_salary_slip: function (frm) { frappe.db.get_value( "Salary Structure", @@ -174,8 +142,6 @@ frappe.ui.form.on("Salary Structure Assignment", { }); } }, - ->>>>>>> 65547990c (feat: Preview Salary Slip from Salary Structure Assignment) valiadte_joining_date_and_salary_slips: function (frm) { frappe.call({ method: "earning_and_deduction_entries_does_not_exists", From 0554db1b1765bdec810f8ad73c1905284cdf0c26 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 14:15:08 +0530 Subject: [PATCH 09/16] fix(patch): set/update user type limit while updating lending perm config (backport #1769) (#1770) (cherry picked from commit 8133cdee4c70510d8932337534cbf1ae08fd27de) Co-authored-by: Rucha Mahabal --- hrms/patches.txt | 2 +- hrms/patches/v15_0/add_loan_docperms_to_ess.py | 3 ++- hrms/setup.py | 16 +++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hrms/patches.txt b/hrms/patches.txt index b26178d765..8ca18becf8 100644 --- a/hrms/patches.txt +++ b/hrms/patches.txt @@ -23,4 +23,4 @@ hrms.patches.v14_0.update_title_in_employee_onboarding_and_separation_templates hrms.patches.v15_0.make_hr_settings_tab_in_company_master hrms.patches.v15_0.enable_allow_checkin_setting hrms.patches.v15_0.set_default_asset_action_in_fnf -hrms.patches.v15_0.add_loan_docperms_to_ess +hrms.patches.v15_0.add_loan_docperms_to_ess #2024-05-14 diff --git a/hrms/patches/v15_0/add_loan_docperms_to_ess.py b/hrms/patches/v15_0/add_loan_docperms_to_ess.py index 898eb26a88..a037612290 100644 --- a/hrms/patches/v15_0/add_loan_docperms_to_ess.py +++ b/hrms/patches/v15_0/add_loan_docperms_to_ess.py @@ -1,8 +1,9 @@ import frappe -from hrms.setup import add_lending_docperms_to_ess +from hrms.setup import add_lending_docperms_to_ess, update_user_type_doctype_limit def execute(): if "lending" in frappe.get_installed_apps(): + update_user_type_doctype_limit() add_lending_docperms_to_ess() diff --git a/hrms/setup.py b/hrms/setup.py index 9f8489b436..2791350300 100644 --- a/hrms/setup.py +++ b/hrms/setup.py @@ -602,17 +602,23 @@ def remove_lending_docperms_from_ess(): # ESS USER TYPE SETUP & CLEANUP def add_non_standard_user_types(): user_types = get_user_types_data() + update_user_type_doctype_limit(user_types) + + for user_type, data in user_types.items(): + create_custom_role(data) + create_user_type(user_type, data) + + +def update_user_type_doctype_limit(user_types=None): + if not user_types: + user_types = get_user_types_data() user_type_limit = {} for user_type, __ in user_types.items(): - user_type_limit.setdefault(frappe.scrub(user_type), 30) + user_type_limit.setdefault(frappe.scrub(user_type), 40) update_site_config("user_type_doctype_limit", user_type_limit) - for user_type, data in user_types.items(): - create_custom_role(data) - create_user_type(user_type, data) - def get_user_types_data(): return { From c5a055cf490924bf09b52efe3f85c6fc697e6e5e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 14:15:19 +0530 Subject: [PATCH 10/16] fix(Payroll): handle empty condition/formula updates from salary components (backport #1766) (#1772) 1. Creat a new Salary Component, w/o condition or formula defined yet (value is undefined) 2. Use the component in some Salary Structure 3. Attempt to Update Salary Structures with Sync Condition/Formula will show errors. ``` TypeError: SalaryComponent.update_salary_structures() missing 1 required positional argument: 'value' ``` (cherry picked from commit adca67eba8c5438e11e06eb819d55ab6048a3131) Co-authored-by: Kitti U. @ Ecosoft --- hrms/payroll/doctype/salary_component/salary_component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hrms/payroll/doctype/salary_component/salary_component.js b/hrms/payroll/doctype/salary_component/salary_component.js index 9ecb1aae28..036cbf9df9 100644 --- a/hrms/payroll/doctype/salary_component/salary_component.js +++ b/hrms/payroll/doctype/salary_component/salary_component.js @@ -125,7 +125,7 @@ frappe.ui.form.on("Salary Component", { args: { structures: structures, field: df.toLowerCase(), - value: frm.get_field(df.toLowerCase()).value, + value: frm.get_field(df.toLowerCase()).value || "", }, }) .then((r) => { From eb99caabbcf005064448e18974076157371f7900 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 14 May 2024 16:45:41 +0530 Subject: [PATCH 11/16] chore: remove redundant code for setting payroll period --- hrms/payroll/doctype/payroll_period/payroll_period.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hrms/payroll/doctype/payroll_period/payroll_period.js b/hrms/payroll/doctype/payroll_period/payroll_period.js index 47425ce69b..5dafc19ed7 100644 --- a/hrms/payroll/doctype/payroll_period/payroll_period.js +++ b/hrms/payroll/doctype/payroll_period/payroll_period.js @@ -2,16 +2,6 @@ // For license information, please see license.txt frappe.ui.form.on("Payroll Period", { - refresh: function (frm) { - // sets start date and end date as that of the current fiscal year if no payroll period exists - frappe.db.exists("Payroll Period").then((period_exists) => { - if (!period_exists) { - frm.set_value("start_date", frappe.defaults.get_default("year_start_date")); - frm.set_value("end_date", frappe.defaults.get_default("year_end_date")); - } - }); - }, - onload: function (frm) { frm.trigger("set_start_date"); }, From 18cb376f8d4b0a042c3e2c27fe875a3e1855cecc Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 18:30:37 +0530 Subject: [PATCH 12/16] feat(minor): allow using `rounded` function in salary slip formulae (backport #1774) (#1776) - the `round` function does Banker's rounding. Allow usage of `rounded` to respect System Settings & allow Commercial Rounding (cherry picked from commit c1704c9767b9c78b23d67cb6b0514afc084cc0dd) Co-authored-by: Rucha Mahabal --- hrms/payroll/doctype/salary_slip/salary_slip.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hrms/payroll/doctype/salary_slip/salary_slip.py b/hrms/payroll/doctype/salary_slip/salary_slip.py index e4c45e3612..e1690f359d 100644 --- a/hrms/payroll/doctype/salary_slip/salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/salary_slip.py @@ -70,6 +70,7 @@ def __init__(self, *args, **kwargs): "float": float, "long": int, "round": round, + "rounded": rounded, "date": date, "getdate": getdate, "ceil": ceil, From be36cea79fa56513292600fea70cef4d16e9e994 Mon Sep 17 00:00:00 2001 From: krantheman Date: Fri, 10 May 2024 11:58:42 +0530 Subject: [PATCH 13/16] fix: validation of overlapping shift dates (cherry picked from commit 0e560efd3ca0c86c2af5174e012336569416a2e3) --- .../shift_assignment/shift_assignment.py | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/hrms/hr/doctype/shift_assignment/shift_assignment.py b/hrms/hr/doctype/shift_assignment/shift_assignment.py index 5cdd5d7d9b..321a8df7db 100644 --- a/hrms/hr/doctype/shift_assignment/shift_assignment.py +++ b/hrms/hr/doctype/shift_assignment/shift_assignment.py @@ -80,33 +80,12 @@ def get_overlapping_dates(self): & (shift.docstatus == 1) & (shift.name != self.name) & (shift.status == "Active") + & ((shift.end_date >= self.start_date) | (shift.end_date.isnull())) ) ) if self.end_date: - query = query.where( - Criterion.any( - [ - Criterion.any( - [ - shift.end_date.isnull(), - ((self.start_date >= shift.start_date) & (self.start_date <= shift.end_date)), - ] - ), - Criterion.any( - [ - ((self.end_date >= shift.start_date) & (self.end_date <= shift.end_date)), - shift.start_date.between(self.start_date, self.end_date), - ] - ), - ] - ) - ) - else: - query = query.where( - shift.end_date.isnull() - | ((self.start_date >= shift.start_date) & (self.start_date <= shift.end_date)) - ) + query = query.where(shift.start_date <= self.end_date) return query.run(as_dict=True) From 71a675433832b96e0ee4c05e61045b7e11237f20 Mon Sep 17 00:00:00 2001 From: krantheman Date: Fri, 10 May 2024 12:30:08 +0530 Subject: [PATCH 14/16] test: test definite shifts before an indefinite one (cherry picked from commit e0e82f4d581a374e8f2d345cb2d176e0197a6743) --- .../shift_assignment/test_shift_assignment.py | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/hrms/hr/doctype/shift_assignment/test_shift_assignment.py b/hrms/hr/doctype/shift_assignment/test_shift_assignment.py index a33aba7abf..dbfa355d74 100644 --- a/hrms/hr/doctype/shift_assignment/test_shift_assignment.py +++ b/hrms/hr/doctype/shift_assignment/test_shift_assignment.py @@ -41,21 +41,15 @@ def test_make_shift_assignment(self): def test_overlapping_for_ongoing_shift(self): # shift should be Ongoing if Only start_date is present and status = Active setup_shift_type(shift_type="Day Shift") - shift_assignment_1 = frappe.get_doc( - { - "doctype": "Shift Assignment", - "shift_type": "Day Shift", - "company": "_Test Company", - "employee": "_T-Employee-00001", - "start_date": nowdate(), - "status": "Active", - } - ).insert() - shift_assignment_1.submit() + make_shift_assignment("Day Shift", "_T-Employee-00001", nowdate()) - self.assertEqual(shift_assignment_1.docstatus, 1) + # shift ends before ongoing shift starts + non_overlapping_shift = make_shift_assignment( + "Day Shift", "_T-Employee-00001", add_days(nowdate(), -1), add_days(nowdate(), -1) + ) + self.assertEqual(non_overlapping_shift.docstatus, 1) - shift_assignment = frappe.get_doc( + overlapping_shift = frappe.get_doc( { "doctype": "Shift Assignment", "shift_type": "Day Shift", @@ -64,8 +58,7 @@ def test_overlapping_for_ongoing_shift(self): "start_date": add_days(nowdate(), 2), } ) - - self.assertRaises(OverlappingShiftError, shift_assignment.save) + self.assertRaises(OverlappingShiftError, overlapping_shift.save) def test_multiple_shift_assignments_for_same_date(self): setup_shift_type(shift_type="Day Shift") From d940b9d466946ac91772397637b06360b08b6d8d Mon Sep 17 00:00:00 2001 From: krantheman Date: Sun, 12 May 2024 10:53:08 +0530 Subject: [PATCH 15/16] test: remove redundant code (cherry picked from commit 428546ee4b1d8962208a859e5651b8d4bbb5c12b) --- .../shift_assignment/test_shift_assignment.py | 41 +------------------ 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/hrms/hr/doctype/shift_assignment/test_shift_assignment.py b/hrms/hr/doctype/shift_assignment/test_shift_assignment.py index dbfa355d74..19bac6a8c8 100644 --- a/hrms/hr/doctype/shift_assignment/test_shift_assignment.py +++ b/hrms/hr/doctype/shift_assignment/test_shift_assignment.py @@ -23,21 +23,6 @@ def setUp(self): frappe.db.delete("Shift Assignment") frappe.db.delete("Shift Type") - def test_make_shift_assignment(self): - setup_shift_type(shift_type="Day Shift") - shift_assignment = frappe.get_doc( - { - "doctype": "Shift Assignment", - "shift_type": "Day Shift", - "company": "_Test Company", - "employee": "_T-Employee-00001", - "start_date": nowdate(), - } - ).insert() - shift_assignment.submit() - - self.assertEqual(shift_assignment.docstatus, 1) - def test_overlapping_for_ongoing_shift(self): # shift should be Ongoing if Only start_date is present and status = Active setup_shift_type(shift_type="Day Shift") @@ -62,18 +47,7 @@ def test_overlapping_for_ongoing_shift(self): def test_multiple_shift_assignments_for_same_date(self): setup_shift_type(shift_type="Day Shift") - shift_assignment_1 = frappe.get_doc( - { - "doctype": "Shift Assignment", - "shift_type": "Day Shift", - "company": "_Test Company", - "employee": "_T-Employee-00001", - "start_date": nowdate(), - "end_date": add_days(nowdate(), 30), - "status": "Active", - } - ).insert() - shift_assignment_1.submit() + make_shift_assignment("Day Shift", "_T-Employee-00001", nowdate(), add_days(nowdate(), 30)) setup_shift_type(shift_type="Night Shift", start_time="19:00:00", end_time="23:00:00") shift_assignment_2 = frappe.get_doc( @@ -96,18 +70,7 @@ def test_multiple_shift_assignments_for_same_date(self): def test_overlapping_for_fixed_period_shift(self): # shift should is for Fixed period if Only start_date and end_date both are present and status = Active setup_shift_type(shift_type="Day Shift") - shift_assignment_1 = frappe.get_doc( - { - "doctype": "Shift Assignment", - "shift_type": "Day Shift", - "company": "_Test Company", - "employee": "_T-Employee-00001", - "start_date": nowdate(), - "end_date": add_days(nowdate(), 30), - "status": "Active", - } - ).insert() - shift_assignment_1.submit() + make_shift_assignment("Day Shift", "_T-Employee-00001", nowdate(), add_days(nowdate(), 30)) # it should not allowed within period of any shift. shift_assignment_3 = frappe.get_doc( From edc8f72f2f578d20c6ef26f7a4762553bdfd09c5 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 16 May 2024 12:32:10 +0530 Subject: [PATCH 16/16] fix: simplify shift request overlapping validation (cherry picked from commit e832b935c2d962e6219f6ebf7c1ef20e96488d1d) --- .../hr/doctype/shift_request/shift_request.py | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/hrms/hr/doctype/shift_request/shift_request.py b/hrms/hr/doctype/shift_request/shift_request.py index 225c2f1d89..5974768190 100644 --- a/hrms/hr/doctype/shift_request/shift_request.py +++ b/hrms/hr/doctype/shift_request/shift_request.py @@ -93,33 +93,16 @@ def get_overlapping_dates(self): query = ( frappe.qb.from_(shift) .select(shift.name, shift.shift_type) - .where((shift.employee == self.employee) & (shift.docstatus < 2) & (shift.name != self.name)) + .where( + (shift.employee == self.employee) + & (shift.docstatus < 2) + & (shift.name != self.name) + & ((shift.to_date >= self.from_date) | (shift.to_date.isnull())) + ) ) if self.to_date: - query = query.where( - Criterion.any( - [ - Criterion.any( - [ - shift.to_date.isnull(), - ((self.from_date >= shift.from_date) & (self.from_date <= shift.to_date)), - ] - ), - Criterion.any( - [ - ((self.to_date >= shift.from_date) & (self.to_date <= shift.to_date)), - shift.from_date.between(self.from_date, self.to_date), - ] - ), - ] - ) - ) - else: - query = query.where( - shift.to_date.isnull() - | ((self.from_date >= shift.from_date) & (self.from_date <= shift.to_date)) - ) + query = query.where(shift.from_date <= self.to_date) return query.run(as_dict=True)