Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow salary slip preview for draft salary structure assignments #1827

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ def add_earning_for_hourly_wages(self, doc, salary_component, amount):
}
doc.append("earnings", wages_row)

def set_salary_structure_assignment(self):
def set_salary_structure_assignment(self,docstatus=1):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also allow passing any custom salary structure assignment?
Just passing in draft would not allow use the preview salary slip for a particular salary structure assignment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

self._salary_structure_assignment = frappe.db.get_value(
"Salary Structure Assignment",
{
"employee": self.employee,
"salary_structure": self.salary_structure,
"from_date": ("<=", self.actual_start_date),
"docstatus": 1,
"docstatus": docstatus,
},
"*",
order_by="from_date desc",
Expand All @@ -749,9 +749,9 @@ def set_salary_structure_assignment(self):
)
)

def calculate_net_pay(self):
def calculate_net_pay(self, docstatus=1):
if self.salary_structure:
self.calculate_component_amounts("earnings")
self.calculate_component_amounts("earnings", docstatus)

# get remaining numbers of sub-period (period for which one salary is processed)
if self.payroll_period:
Expand All @@ -771,7 +771,7 @@ def calculate_net_pay(self):
)

if self.salary_structure:
self.calculate_component_amounts("deductions")
self.calculate_component_amounts("deductions", docstatus)

set_loan_repayment(self)

Expand Down Expand Up @@ -1054,19 +1054,19 @@ def get_income_tax_deducted_till_date(self):
)
return tax_deducted

def calculate_component_amounts(self, component_type):
def calculate_component_amounts(self, component_type, docstatus=1):
if not getattr(self, "_salary_structure_doc", None):
self._salary_structure_doc = frappe.get_cached_doc("Salary Structure", self.salary_structure)

self.add_structure_components(component_type)
self.add_structure_components(component_type, docstatus)
self.add_additional_salary_components(component_type)
if component_type == "earnings":
self.add_employee_benefits()
else:
self.add_tax_components()

def add_structure_components(self, component_type):
self.data, self.default_data = self.get_data_for_eval()
def add_structure_components(self, component_type, docstatus=1):
self.data, self.default_data = self.get_data_for_eval(docstatus)
timesheet_component = self._salary_structure_doc.salary_component

for struct_row in self._salary_structure_doc.get(component_type):
Expand Down Expand Up @@ -1111,13 +1111,13 @@ def add_structure_components(self, component_type):
remove_if_zero_valued=remove_if_zero_valued,
)

def get_data_for_eval(self):
def get_data_for_eval(self,docstatus=1):
"""Returns data for evaluating formula"""
data = frappe._dict()
employee = frappe.get_cached_doc("Employee", self.employee).as_dict()

if not hasattr(self, "_salary_structure_assignment"):
self.set_salary_structure_assignment()
self.set_salary_structure_assignment(docstatus)

data.update(self._salary_structure_assignment)
data.update(self.as_dict())
Expand Down Expand Up @@ -1870,13 +1870,13 @@ def set_status(self, status=None):
status = self.get_status()
self.db_set("status", status)

def process_salary_structure(self, for_preview=0):
def process_salary_structure(self, for_preview=0, docstatus=1):
"""Calculate salary after salary structure details have been updated"""
if not self.salary_slip_based_on_timesheet:
self.get_date_details()
self.pull_emp_details()
self.get_working_days_details(for_preview=for_preview)
self.calculate_net_pay()
self.calculate_net_pay(docstatus)

def pull_emp_details(self):
account_details = frappe.get_cached_value(
Expand Down
3 changes: 2 additions & 1 deletion hrms/payroll/doctype/salary_structure/salary_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,15 @@ def make_salary_slip(
print_format=None,
for_preview=0,
ignore_permissions=False,
docstatus=1
):
def postprocess(source, target):
if employee:
target.employee = employee
if posting_date:
target.posting_date = posting_date

target.run_method("process_salary_structure", for_preview=for_preview)
target.run_method("process_salary_structure", for_preview=for_preview, docstatus=docstatus)

doc = get_mapped_doc(
"Salary Structure",
Expand Down
Loading