Skip to content

Commit

Permalink
feat: update withholding status in payroll employee table
Browse files Browse the repository at this point in the history
- rename `salary_withheld` to `is_salary_withheld`
  • Loading branch information
ruchamahabal committed Jul 22, 2024
1 parent 7daf23a commit a0fef7c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -50,16 +51,17 @@
"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": [],
"modified": "2024-07-01 11:52:24.730907",
"modified": "2024-07-22 13:28:40.573807",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Employee Detail",
Expand Down
14 changes: 7 additions & 7 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions hrms/payroll/doctype/salary_withholding/salary_withholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit a0fef7c

Please sign in to comment.