From 574176dddcced9ce494b4b9211985db7ff451b76 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 18 Oct 2024 18:59:56 +0530 Subject: [PATCH] fix: show opening balances section if employee joined after payroll period --- .../salary_structure_assignment.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py index d462c3042c..961a4871a0 100644 --- a/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py +++ b/hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py @@ -7,6 +7,8 @@ from frappe.model.document import Document from frappe.utils import cint, flt, get_link_to_form, getdate +from hrms.payroll.doctype.payroll_period.payroll_period import get_payroll_period + class DuplicateAssignment(frappe.ValidationError): pass @@ -150,7 +152,7 @@ def warn_about_missing_opening_entries(self): @frappe.whitelist() def are_opening_entries_required(self) -> bool: - if not self.emp_joined_in_the_same_month() and not self.has_existing_salary_slips(): + if self.has_emp_joined_after_payroll_period_start() and not self.has_existing_salary_slips(): return True else: if not self.docstatus.is_draft() and ( @@ -167,16 +169,11 @@ def has_existing_salary_slips(self) -> bool: ) ) - def emp_joined_in_the_same_month(self) -> bool: - date_of_joining = frappe.db.get_value("Employee", self.employee, "date_of_joining") - from_date = getdate(self.from_date) + def has_emp_joined_after_payroll_period_start(self) -> bool: + date_of_joining = getdate(frappe.db.get_value("Employee", self.employee, "date_of_joining")) + payroll_period = get_payroll_period(self.from_date, self.from_date, self.company) - if ( - self.from_date - and date_of_joining - and date_of_joining.month == from_date.month - and date_of_joining.year == from_date.year - ): + if date_of_joining and date_of_joining > payroll_period.start_date: return True return False