From 6c2cc0b5c27d3b941d19bde444c63de0c989d456 Mon Sep 17 00:00:00 2001 From: mariusrklein <47218379+mariusrklein@users.noreply.github.com> Date: Thu, 23 Jan 2025 23:48:01 +0100 Subject: [PATCH] changed model to allow missing subsidy receiver --- ...8_alter_statement_allowance_to_and_more.py | 25 +++++++++++++++++++ jdav_web/finance/models.py | 8 ++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 jdav_web/finance/migrations/0008_alter_statement_allowance_to_and_more.py diff --git a/jdav_web/finance/migrations/0008_alter_statement_allowance_to_and_more.py b/jdav_web/finance/migrations/0008_alter_statement_allowance_to_and_more.py new file mode 100644 index 0000000..faf7504 --- /dev/null +++ b/jdav_web/finance/migrations/0008_alter_statement_allowance_to_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.1 on 2025-01-23 22:16 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('members', '0033_freizeit_approved_extra_youth_leader_count'), + ('finance', '0007_alter_statement_allowance_to'), + ] + + operations = [ + migrations.AlterField( + model_name='statement', + name='allowance_to', + field=models.ManyToManyField(blank=True, help_text='The youth leaders to which an allowance should be paid.', related_name='receives_allowance_for_statements', to='members.Member', verbose_name='Pay allowance to'), + ), + migrations.AlterField( + model_name='statement', + name='subsidy_to', + field=models.ForeignKey(blank=True, help_text='The person that should receive the subsidy for night and travel costs. Typically the person who paid for them.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='receives_subsidy_for_statements', to='members.member', verbose_name='Pay subsidy to'), + ), + ] diff --git a/jdav_web/finance/models.py b/jdav_web/finance/models.py index 8be4291..de10941 100644 --- a/jdav_web/finance/models.py +++ b/jdav_web/finance/models.py @@ -62,9 +62,10 @@ class Statement(CommonModel): allowance_to = models.ManyToManyField(Member, verbose_name=_('Pay allowance to'), related_name='receives_allowance_for_statements', blank=True, - help_text=_('The youth leaders to which an allowance should be paid. The count must match the number of permitted youth leaders.')) + help_text=_('The youth leaders to which an allowance should be paid.')) subsidy_to = models.ForeignKey(Member, verbose_name=_('Pay subsidy to'), null=True, + blank=True, on_delete=models.SET_NULL, related_name='receives_subsidy_for_statements', help_text=_('The person that should receive the subsidy for night and travel costs. Typically the person who paid for them.')) @@ -341,7 +342,10 @@ class Statement(CommonModel): The total amount of subsidies excluding the allowance, i.e. the transportation and night costs per youth leader multiplied with the real number of youth leaders. """ - return (self.transportation_per_yl + self.nights_per_yl) * self.real_staff_count + if self.subsidy_to: + return (self.transportation_per_yl + self.nights_per_yl) * self.real_staff_count + else: + return cvt_to_decimal(0) @property def total_staff(self):