Skip to content

Commit

Permalink
FFT-202 Update payroll forecast on user actions (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDudley authored Feb 21, 2025
1 parent 125d39f commit 729a399
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
6 changes: 2 additions & 4 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ def clean(self):
def save(self, *args, **kwargs):
super().save(*args, **kwargs)

# TODO: Update payroll forecast when pay uplift is updated.
# Avoid circular import
# from payroll.services.payroll import update_all_payroll_forecast
from payroll.tasks import update_all_payroll_forecast

# update_all_payroll_forecast(financial_year=self.financial_year)
update_all_payroll_forecast.delay(financial_year=self.financial_year.pk)


class Attrition(PayModifiers):
Expand Down
6 changes: 0 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ services:
image: fft/web:latest
env_file:
- .env
environment:
- DATABASE_URL=psql://postgres:postgres@db:5432/fido
- CELERY_BROKER_URL=rediss://redis:redis@redis:6379/0
command: python manage.py runserver 0.0.0.0:8000
# command: granian --interface wsgi config.wsgi:application --workers 2 --host 0.0.0.0 --port 8000
ports:
Expand All @@ -27,9 +24,6 @@ services:
image: fft/web:latest
env_file:
- .env
environment:
- DATABASE_URL=psql://postgres:postgres@db:5432/fido
- CELERY_BROKER_URL=rediss://redis:redis@redis:6379/0
command: celery -A config worker -l info
volumes:
- ./:/app/
Expand Down
10 changes: 10 additions & 0 deletions payroll/services/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from django.db import transaction

from chartofaccountDIT.models import ProgrammeCode
from core.models import FinancialYear
from costcentre.models import CostCentre
from gifthospitality.models import Grade
from payroll.models import Employee
from payroll.services.payroll import update_all_employee_pay_periods
from payroll.tasks import update_all_payroll_forecast


PayrollRow = namedtuple(
Expand Down Expand Up @@ -73,6 +75,7 @@ def import_payroll(payroll_csv: File) -> ImportPayrollReport:
cost_centre_codes = set(CostCentre.objects.values_list("pk", flat=True))
programme_codes = set(ProgrammeCode.objects.values_list("pk", flat=True))
grades = set(Grade.objects.values_list("pk", flat=True))
current_financial_year = FinancialYear.objects.current()

for row in csv_reader:
if is_row_empty(row):
Expand Down Expand Up @@ -125,6 +128,13 @@ def import_payroll(payroll_csv: File) -> ImportPayrollReport:
# Stop template attr lookup of .items creating an empty list.
failed.default_factory = None

# Queue up a refresh of the whole payroll forecast.
transaction.on_commit(
lambda: update_all_payroll_forecast.delay(
financial_year=current_financial_year.pk
)
)

return {
"failed": failed,
"created": len(created),
Expand Down
5 changes: 0 additions & 5 deletions payroll/services/payroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ def update_payroll_forecast_figure(
).update(forecast)


def update_all_payroll_forecast(*, financial_year: FinancialYear):
for cost_centre in CostCentre.objects.all():
update_payroll_forecast(financial_year=financial_year, cost_centre=cost_centre)


def get_attrition_instance(
financial_year: FinancialYear, cost_centre: CostCentre
) -> Attrition | None:
Expand Down
13 changes: 13 additions & 0 deletions payroll/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from celery import shared_task

from core.models import FinancialYear
from costcentre.models import CostCentre
from payroll.services.payroll import update_payroll_forecast


@shared_task
def update_all_payroll_forecast(*, financial_year: int):
financial_year = FinancialYear(pk=financial_year)

for cost_centre in CostCentre.objects.all():
update_payroll_forecast(financial_year=financial_year, cost_centre=cost_centre)

0 comments on commit 729a399

Please sign in to comment.