Files
ihrm/leave/scheduler.py
Horilla 2fee7c18bb [IMP] Remove inter module dependency (#274)
This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made:

1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase.
2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation.
3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules.

These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code.

**NOTE**
For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations.

- `python3 manage.py makemigrations`
- `python3 manage.py migrate base`
- `python3 manage.py migrate`





* [IMP] ASSET: Asset module dependency removal from other Horilla apps

* [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps

* [IMP] BASE: Base module dependency removal from other Horilla apps

* [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps

* [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps

* [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps

* [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps

* [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps

* [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps

* [IMP] LEAVE: Leave module dependency removal from other Horilla apps

* [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps

* [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps

* [IMP] PMS: PMS module dependency removal from other Horilla apps

* [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps

* [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps

* [IMP] HORILLA: Dependency removal updates

* [IMP] TEMPLATES: Dependency removal updates

* [IMP] STATIC: Dependency removal updates

* [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps

* [ADD] HORILLA: methods.py

* [UPDT] HORILLA: Settings.py

* [FIX] EMPLOYEE: About tab issue

* Update horilla_settings.py

* Remove dummy db init password
2024-08-05 14:22:44 +05:30

44 lines
1.6 KiB
Python

import calendar
import datetime as dt
from datetime import datetime, timedelta
from apscheduler.schedulers.background import BackgroundScheduler
from dateutil.relativedelta import relativedelta
today = datetime.now()
def leave_reset():
from leave.models import LeaveType
today_date = today.date()
leave_types = LeaveType.objects.filter(reset=True)
# Looping through filtered leave types with reset is true
for leave_type in leave_types:
# #Looping through all available leaves
available_leaves = leave_type.employee_available_leave.all()
for available_leave in available_leaves:
reset_date = available_leave.reset_date
expired_date = available_leave.expired_date
if reset_date == today_date:
available_leave.update_carryforward()
# new_reset_date = available_leave.set_reset_date(assigned_date=today_date,available_leave = available_leave)
new_reset_date = available_leave.set_reset_date(
assigned_date=today_date, available_leave=available_leave
)
available_leave.reset_date = new_reset_date
available_leave.save()
if expired_date == today_date:
new_expired_date = available_leave.set_expired_date(
available_leave=available_leave, assigned_date=today_date
)
available_leave.expired_date = new_expired_date
available_leave.save()
scheduler = BackgroundScheduler()
scheduler.add_job(leave_reset, "interval", hours=4)
scheduler.start()