From a8695aad30e8ffcb512721f94b40fae342c556e1 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 22 Jul 2024 13:30:27 +0530 Subject: [PATCH] feat: update withholding status in payroll employee table - rename `salary_withheld` to `is_salary_withheld` (cherry picked from commit a0fef7c96197777e49f4fddd8021862c7f4910fb) # Conflicts: # hrms/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json --- .../payroll_employee_detail.json | 12 +++++++++--- .../payroll/doctype/payroll_entry/payroll_entry.py | 14 +++++++------- .../salary_withholding/salary_withholding.py | 13 +++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/hrms/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json b/hrms/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json index 1ec8eda8f5..49a630ac1b 100644 --- a/hrms/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json +++ b/hrms/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json @@ -10,10 +10,11 @@ "column_break_3", "department", "designation", - "salary_withheld" + "is_salary_withheld" ], "fields": [ { + "columns": 2, "fieldname": "employee", "fieldtype": "Link", "in_list_view": 1, @@ -50,20 +51,25 @@ "read_only": 1 }, { + "columns": 2, "default": "0", - "fieldname": "salary_withheld", + "fieldname": "is_salary_withheld", "fieldtype": "Check", "in_list_view": 1, - "label": "Salary Withheld" + "label": "Is Salary Withheld" } ], "istable": 1, "links": [], +<<<<<<< HEAD <<<<<<< HEAD "modified": "2020-12-17 15:43:29.542977", ======= "modified": "2024-07-01 11:52:24.730907", >>>>>>> 9c5e4c87a (feat: fetch employees with withheld salaries in payroll entry) +======= + "modified": "2024-07-22 13:28:40.573807", +>>>>>>> a0fef7c96 (feat: update withholding status in payroll employee table) "modified_by": "Administrator", "module": "Payroll", "name": "Payroll Employee Detail", diff --git a/hrms/payroll/doctype/payroll_entry/payroll_entry.py b/hrms/payroll/doctype/payroll_entry/payroll_entry.py index 5381257c15..0e1b8e4fba 100644 --- a/hrms/payroll/doctype/payroll_entry/payroll_entry.py +++ b/hrms/payroll/doctype/payroll_entry/payroll_entry.py @@ -211,7 +211,7 @@ def update_employees_with_withheld_salaries(self): for employee in self.employees: if employee.employee in withheld_salaries: - employee.salary_withheld = 1 + employee.is_salary_withheld = 1 @frappe.whitelist() def create_salary_slips(self): @@ -850,12 +850,12 @@ def has_bank_entries(self) -> dict[str, bool]: ) ).run(as_dict=True) - response = {"has_bank_entries": bool(bank_entries)} - - if any(employee.salary_withheld for employee in self.employees): - response["has_bank_entries_for_withheld_salaries"] = False - - return response + return { + "has_bank_entries": bool(bank_entries), + "has_bank_entries_for_withheld_salaries": not any( + employee.is_salary_withheld for employee in self.employees + ), + } @frappe.whitelist() def make_bank_entry(self, for_withheld_salaries=False): diff --git a/hrms/payroll/doctype/salary_withholding/salary_withholding.py b/hrms/payroll/doctype/salary_withholding/salary_withholding.py index de863a6456..2f6937d567 100644 --- a/hrms/payroll/doctype/salary_withholding/salary_withholding.py +++ b/hrms/payroll/doctype/salary_withholding/salary_withholding.py @@ -105,12 +105,16 @@ def link_bank_entry_in_salary_withholdings(salary_slips: list[dict], bank_entry: def update_salary_withholding_payment_status(doc: "SalaryWithholding", method: str | None = None): """update withholding status on bank entry submission/cancellation. Called from hooks""" + Withholding = frappe.qb.DocType("Salary Withholding") WithholdingCycle = frappe.qb.DocType("Salary Withholding Cycle") withholdings = ( frappe.qb.from_(WithholdingCycle) + .inner_join(Withholding) + .on(WithholdingCycle.parent == Withholding.name) .select( WithholdingCycle.name.as_("salary_withholding_cycle"), WithholdingCycle.parent.as_("salary_withholding"), + Withholding.employee, ) .where((WithholdingCycle.journal_entry == doc.name) & (WithholdingCycle.docstatus == 1)) ).run(as_dict=True) @@ -137,6 +141,15 @@ def _update_payment_status_in_payroll(withholdings: list[dict], cancel: bool = F ) ).run() + employees = [withholding.employee for withholding in withholdings] + is_salary_withheld = 1 if cancel else 0 + PayrollEmployee = frappe.qb.DocType("Payroll Employee Detail") + ( + frappe.qb.update(PayrollEmployee) + .set(PayrollEmployee.is_salary_withheld, is_salary_withheld) + .where(PayrollEmployee.employee.isin(employees)) + ).run() + def _update_salary_withholdings(withholdings: list[dict], cancel: bool = False) -> None: is_salary_released = 0 if cancel else 1