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

Add PayUplift model and multiply pay periods by pay uplift #569

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 20 additions & 1 deletion core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.views.decorators.csrf import csrf_exempt

from core.export_data import export_logentry_iterator
from core.models import CommandLog, FinancialYear
from core.models import CommandLog, FinancialYear, PayUplift
from core.utils.export_helpers import (
export_csv_from_import,
export_to_csv,
Expand Down Expand Up @@ -368,6 +368,25 @@ def has_delete_permission(self, request, obj=None):
return False


class PayUpliftAdmin(admin.ModelAdmin):
list_display = (
"financial_year",
"apr",
"may",
"jun",
"jul",
"aug",
"sep",
"oct",
"nov",
"dec",
"jan",
"feb",
"mar",
)


admin.site.register(LogEntry, LogEntryAdmin)
admin.site.register(FinancialYear, FinancialYearAdmin)
admin.site.register(CommandLog, CustomLogModelAdmin)
admin.site.register(PayUplift, PayUpliftAdmin)
47 changes: 47 additions & 0 deletions core/migrations/0014_payuplift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 5.1.3 on 2024-12-06 15:33

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0013_alter_historicalgroup_options_and_more"),
]

operations = [
migrations.CreateModel(
name="PayUplift",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("apr", models.FloatField(default=1.0)),
("may", models.FloatField(default=1.0)),
("jun", models.FloatField(default=1.0)),
("jul", models.FloatField(default=1.0)),
("aug", models.FloatField(default=1.0)),
("sep", models.FloatField(default=1.0)),
("oct", models.FloatField(default=1.0)),
("nov", models.FloatField(default=1.0)),
("dec", models.FloatField(default=1.0)),
("jan", models.FloatField(default=1.0)),
("feb", models.FloatField(default=1.0)),
("mar", models.FloatField(default=1.0)),
(
"financial_year",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="core.financialyear",
),
),
],
),
]
25 changes: 25 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.db import models
from simple_history import register

from core.constants import MONTHS

from .metamodels import BaseModel


Expand Down Expand Up @@ -87,6 +89,29 @@ def __str__(self):
return str(self.financial_year_display)


class PayUplift(models.Model):
@property
def periods(self) -> list[float]:
return [getattr(self, month) for month in MONTHS]

financial_year = models.ForeignKey(
FinancialYear,
on_delete=models.PROTECT,
)
apr = models.FloatField(default=1.0)
may = models.FloatField(default=1.0)
jun = models.FloatField(default=1.0)
jul = models.FloatField(default=1.0)
aug = models.FloatField(default=1.0)
sep = models.FloatField(default=1.0)
oct = models.FloatField(default=1.0)
nov = models.FloatField(default=1.0)
dec = models.FloatField(default=1.0)
jan = models.FloatField(default=1.0)
feb = models.FloatField(default=1.0)
mar = models.FloatField(default=1.0)


# Track changes to permissions
register(Permission, app=__package__, inherit=True)
register(get_user_model(), app=__package__, inherit=True)
Expand Down
14 changes: 13 additions & 1 deletion payroll/services/payroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.db.models import Avg, Count, Q

from core.constants import MONTHS
from core.models import FinancialYear
from core.models import FinancialYear, PayUplift
from core.types import MonthsDict
from costcentre.models import CostCentre
from gifthospitality.models import Grade
Expand Down Expand Up @@ -75,10 +75,22 @@ def payroll_forecast_report(
cost_centre=cost_centre,
pay_periods__year=financial_year,
)
pay_uplift_obj = PayUplift.objects.filter(financial_year=financial_year).first()

pay_uplift = (
np.array(
PayUplift.objects.filter(financial_year=financial_year).first().periods
)
if pay_uplift_obj is not None
else np.ones(12)
)

for employee in employee_qs.iterator():
periods = employee.pay_periods.first().periods
periods = np.array(periods)

periods = periods * pay_uplift

prog_report = report[employee.programme_code_id]
prog_report[settings.PAYROLL.BASIC_PAY_NAC] += periods * employee.basic_pay
prog_report[settings.PAYROLL.PENSION_NAC] += periods * employee.pension
Expand Down
Loading