Skip to content

Commit

Permalink
Add PayUplift model and multiply pay periods by pay uplift
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard committed Dec 6, 2024
1 parent c264ec1 commit 402f14e
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
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",
),
),
],
),
]
19 changes: 19 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ def __str__(self):
return str(self.financial_year_display)


class PayUplift(models.Model):
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
29 changes: 28 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,15 @@ 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 = pay_uplift_to_numpy_array(pay_uplift_obj)

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 Expand Up @@ -109,6 +114,28 @@ def payroll_forecast_report(
)


def pay_uplift_to_numpy_array(instance):
if instance is None:
return np.ones(12)

fields = [
"apr",
"may",
"jun",
"jul",
"aug",
"sep",
"oct",
"nov",
"dec",
"jan",
"feb",
"mar",
]

return np.array([getattr(instance, field, 1.0) for field in fields])


# TODO (FFT-131): Apply caching to the average salary calculation
def get_average_salary_for_grade(grade: Grade, cost_centre: CostCentre) -> int:
employee_count_threshold = settings.PAYROLL.AVERAGE_SALARY_THRESHOLD
Expand Down

0 comments on commit 402f14e

Please sign in to comment.