[UPDT] ATTENDANCE: Add HorillaCompanyManager and auto-create AttendanceGeneralSetting for companies
This commit is contained in:
@@ -32,5 +32,21 @@ class AttendanceConfig(AppConfig):
|
||||
MIDDLEWARE.append(middleware_path)
|
||||
|
||||
APP_URLS.append("attendance.urls") # Used to remove Dynamically Added Urls
|
||||
|
||||
self.create_enable_disable_check_in()
|
||||
super().ready()
|
||||
|
||||
def create_enable_disable_check_in(self):
|
||||
"""
|
||||
Checks if an AttendanceGeneralSetting object exists for each company.
|
||||
If it doesn't exist, creates one.
|
||||
"""
|
||||
from attendance.models import AttendanceGeneralSetting
|
||||
from base.models import Company
|
||||
|
||||
companies = Company.objects.all()
|
||||
for company in companies:
|
||||
if not AttendanceGeneralSetting.objects.filter(company_id=company).exists():
|
||||
try:
|
||||
AttendanceGeneralSetting.objects.create(company_id=company)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -909,6 +909,7 @@ class AttendanceGeneralSetting(HorillaModel):
|
||||
),
|
||||
)
|
||||
company_id = models.ForeignKey(Company, on_delete=models.CASCADE, null=True)
|
||||
objects = HorillaCompanyManager()
|
||||
|
||||
|
||||
if apps.is_installed("leave") and apps.is_installed("payroll"):
|
||||
|
||||
@@ -36,6 +36,15 @@
|
||||
{% if perms.attendance.change_attendancegeneralsetting %}
|
||||
hx-post="{% url 'enable-disable-check-in' %}" hx-target="#attendance-activity-container" hx-trigger="change"
|
||||
hx-include="#companyId{{att_setting.id}}" hx-on-htmx-after-request="setTimeout(() => { reloadMessage(); }, 200);"
|
||||
{% if request.session.selected_company == 'all' %}
|
||||
{% if not att_setting.company_id %}
|
||||
hx-swap="innerHTML"
|
||||
{% else %}
|
||||
hx-swap="none"
|
||||
{% endif %}
|
||||
{% else %}
|
||||
hx-swap="innerHTML"
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
>
|
||||
</div>
|
||||
|
||||
@@ -34,7 +34,12 @@ from django.core.validators import validate_ipv46_address
|
||||
from django.db import transaction
|
||||
from django.db.models import ProtectedError
|
||||
from django.forms import ValidationError
|
||||
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.http import (
|
||||
HttpResponse,
|
||||
HttpResponseBadRequest,
|
||||
HttpResponseRedirect,
|
||||
JsonResponse,
|
||||
)
|
||||
from django.shortcuts import redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
@@ -2357,8 +2362,11 @@ def work_records_change_month(request):
|
||||
@login_required
|
||||
@permission_required("attendance.view_workrecords")
|
||||
def work_record_export(request):
|
||||
month = int(request.GET.get("month", date.today().month))
|
||||
year = int(request.GET.get("year", date.today().year))
|
||||
try:
|
||||
month = int(request.GET.get("month") or date.today().month)
|
||||
year = int(request.GET.get("year") or date.today().year)
|
||||
except ValueError:
|
||||
return HttpResponseBadRequest("Invalid month or year parameter.")
|
||||
|
||||
employees = EmployeeFilter(request.GET).qs
|
||||
records = WorkRecords.objects.filter(date__month=month, date__year=year)
|
||||
|
||||
Reference in New Issue
Block a user