Skip to content

Commit

Permalink
feat: set withholding doc ref & status in salary slip
Browse files Browse the repository at this point in the history
Co-authored-by: Viny Selopal <viny0698@gmail.com>
(cherry picked from commit f358d1d)
  • Loading branch information
ruchamahabal authored and mergify[bot] committed Jul 23, 2024
1 parent 609e71d commit 390fc29
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
44 changes: 30 additions & 14 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,7 @@ def fill_employee_details(self):
return self.get_employees_with_unmarked_attendance()

def update_employees_with_withheld_salaries(self):
Withholding = frappe.qb.DocType("Salary Withholding")
WithholdingCycle = frappe.qb.DocType("Salary Withholding Cycle")
withheld_salaries = (
frappe.qb.from_(Withholding)
.join(WithholdingCycle)
.on(WithholdingCycle.parent == Withholding.name)
.select(Withholding.employee)
.where(
(WithholdingCycle.from_date == self.start_date)
& (WithholdingCycle.to_date == self.end_date)
& (WithholdingCycle.docstatus == 1)
& (WithholdingCycle.is_salary_released != 1)
)
).run(pluck=True)
withheld_salaries = get_salary_withholdings(self.start_date, self.end_date, pluck="employee")

for employee in self.employees:
if employee.employee in withheld_salaries:
Expand Down Expand Up @@ -1591,3 +1578,32 @@ def employee_query(doctype, txt, searchfield, start, page_len, filters):
)

return employee_list


def get_salary_withholdings(
start_date: str,
end_date: str,
employee: str | None = None,
pluck: str | None = None,
) -> list[str] | list[dict]:
Withholding = frappe.qb.DocType("Salary Withholding")
WithholdingCycle = frappe.qb.DocType("Salary Withholding Cycle")
withheld_salaries = (
frappe.qb.from_(Withholding)
.join(WithholdingCycle)
.on(WithholdingCycle.parent == Withholding.name)
.select(Withholding.employee, Withholding.name)
.where(
(WithholdingCycle.from_date == start_date)
& (WithholdingCycle.to_date == end_date)
& (WithholdingCycle.docstatus == 1)
& (WithholdingCycle.is_salary_released != 1)
)
)

if employee:
withheld_salaries = withheld_salaries.where(Withholding.employee == employee)

if pluck:
return withheld_salaries.run(pluck=pluck)
return withheld_salaries.run(as_dict=True)
26 changes: 18 additions & 8 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
get_benefit_claim_amount,
get_last_payroll_period_benefits,
)
from hrms.payroll.doctype.payroll_entry.payroll_entry import get_start_end_dates
from hrms.payroll.doctype.payroll_entry.payroll_entry import get_salary_withholdings, get_start_end_dates
from hrms.payroll.doctype.payroll_period.payroll_period import (
get_payroll_period,
get_period_factor,
Expand Down Expand Up @@ -132,6 +132,7 @@ def actual_end_date(self):
return self.__actual_end_date

def validate(self):
self.check_salary_withholding()
self.status = self.get_status()
validate_active_employee(self.employee)
self.validate_dates()
Expand Down Expand Up @@ -166,6 +167,13 @@ def validate(self):
alert=True,
)

def check_salary_withholding(self):
salary_withholding = get_salary_withholdings(self.start_date, self.end_date, self.employee)
if salary_withholding:
self.salary_withholding = salary_withholding[0].name
else:
self.salary_withholding = None

def set_net_total_in_words(self):
doc_currency = self.currency
company_currency = erpnext.get_company_currency(self.company)
Expand Down Expand Up @@ -236,13 +244,15 @@ def on_trash(self):
revert_series_if_last(self.series, self.name)

def get_status(self):
if self.docstatus == 0:
status = "Draft"
elif self.docstatus == 1:
status = "Submitted"
elif self.docstatus == 2:
status = "Cancelled"
return status
if self.docstatus == 2:
return "Cancelled"
else:
if self.salary_withholding:
return "Withheld"
elif self.docstatus == 0:
return "Draft"
elif self.docstatus == 1:
return "Submitted"

def validate_dates(self):
self.validate_from_to_dates("start_date", "end_date")
Expand Down

0 comments on commit 390fc29

Please sign in to comment.