From 8733704d2eed76d3a8ee956fc67f9d1f25f3d9d7 Mon Sep 17 00:00:00 2001 From: Oliver Zander Date: Tue, 6 Jan 2026 14:03:11 +0100 Subject: [PATCH] WM-22: fixed end quartal calculation --- .../0108_fix_project_end_quartal.py | 31 +++++++++++++++++++ input/models.py | 3 +- input/utils/quarter.py | 6 ++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 input/migrations/0108_fix_project_end_quartal.py create mode 100644 input/utils/quarter.py diff --git a/input/migrations/0108_fix_project_end_quartal.py b/input/migrations/0108_fix_project_end_quartal.py new file mode 100644 index 0000000..86cd54c --- /dev/null +++ b/input/migrations/0108_fix_project_end_quartal.py @@ -0,0 +1,31 @@ +# Generated by Django 5.2.5 on 2026-01-06 10:31 + +from django.db import migrations + +from input.utils.migrations import get_queryset +from input.utils.quarter import get_quarter_label + + +def fix_project_end_quartal(apps, schema_editor): + projects = get_queryset(apps, schema_editor, 'input', 'Project').exclude(end=None).only('end', 'end_quartal') + + for project in projects: + end_quartal = get_quarter_label(project.end.month) + + if project.end_quartal != end_quartal: + project.end_quartal = end_quartal + project.save(update_fields=['end_quartal'], force_update=True) + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0107_alter_category_other_fields'), + ] + + operations = [ + migrations.RunPython( + code=fix_project_end_quartal, + reverse_code=migrations.RunPython.noop, + ), + ] diff --git a/input/models.py b/input/models.py index 3ed7335..8835f91 100755 --- a/input/models.py +++ b/input/models.py @@ -12,6 +12,7 @@ from django.utils.html import format_html from django.utils.safestring import mark_safe from foerderbarometer.constants import * +from input.utils.quarter import get_quarter_label EMAIL_STATES = { @@ -263,7 +264,7 @@ class Project(Volunteer): kwargs['using'] = using if self.end: - self.end_quartal = f'Q{self.end.month // 4 + 1}' + self.end_quartal = get_quarter_label(self.end.month) else: self.end_quartal = '' diff --git a/input/utils/quarter.py b/input/utils/quarter.py new file mode 100644 index 0000000..31f98c6 --- /dev/null +++ b/input/utils/quarter.py @@ -0,0 +1,6 @@ +def get_quarter(month: int): + return (month - 1) // 3 + 1 + + +def get_quarter_label(month: int): + return 'Q%d' % get_quarter(month)