forked from beba/foerderbarometer
WM-22: fixed end quartal calculation
This commit is contained in:
parent
8abc051a59
commit
8733704d2e
|
|
@ -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,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -12,6 +12,7 @@ from django.utils.html import format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
from foerderbarometer.constants import *
|
from foerderbarometer.constants import *
|
||||||
|
from input.utils.quarter import get_quarter_label
|
||||||
|
|
||||||
|
|
||||||
EMAIL_STATES = {
|
EMAIL_STATES = {
|
||||||
|
|
@ -263,7 +264,7 @@ class Project(Volunteer):
|
||||||
kwargs['using'] = using
|
kwargs['using'] = using
|
||||||
|
|
||||||
if self.end:
|
if self.end:
|
||||||
self.end_quartal = f'Q{self.end.month // 4 + 1}'
|
self.end_quartal = get_quarter_label(self.end.month)
|
||||||
else:
|
else:
|
||||||
self.end_quartal = ''
|
self.end_quartal = ''
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
Loading…
Reference in New Issue