Skip to content

Commit

Permalink
fix: query for payroll cost centers should only consider the latest s…
Browse files Browse the repository at this point in the history
…alary assignment
  • Loading branch information
ruchamahabal committed Aug 29, 2024
1 parent 58c4800 commit 938975d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,23 @@ def get_payroll_cost_centers_for_employee(self, employee, salary_structure):
if not self.employee_cost_centers.get(employee):
SalaryStructureAssignment = frappe.qb.DocType("Salary Structure Assignment")
EmployeeCostCenter = frappe.qb.DocType("Employee Cost Center")

assignment_subquery = (
frappe.qb.from_(SalaryStructureAssignment)
.select(SalaryStructureAssignment.name)
.where(
(SalaryStructureAssignment.employee == employee)
& (SalaryStructureAssignment.salary_structure == salary_structure)
& (SalaryStructureAssignment.docstatus == 1)
& (SalaryStructureAssignment.from_date <= self.end_date)
)
.orderby(SalaryStructureAssignment.from_date, order=frappe.qb.desc)
.limit(1)
)
cost_centers = dict(
(
frappe.qb.from_(SalaryStructureAssignment)
.join(EmployeeCostCenter)
.on(SalaryStructureAssignment.name == EmployeeCostCenter.parent)
frappe.qb.from_(EmployeeCostCenter)
.select(EmployeeCostCenter.cost_center, EmployeeCostCenter.percentage)
.where(
(SalaryStructureAssignment.employee == employee)
& (SalaryStructureAssignment.docstatus == 1)
& (SalaryStructureAssignment.salary_structure == salary_structure)
)
.where(EmployeeCostCenter.parent == assignment_subquery)
).run(as_list=True)
)

Expand Down

0 comments on commit 938975d

Please sign in to comment.