finance/tests: adapt to new logic with allowance_to and subsidy_to

pull/104/head
Christian Merten 11 months ago
parent e02b0acefe
commit 0960646d1f
Signed by: christian.merten
GPG Key ID: D953D69721B948B3

@ -235,7 +235,7 @@ class StatementSubmittedAdmin(admin.ModelAdmin):
_("Successfully generated transactions for %(name)s") % {'name': str(statement)}) _("Successfully generated transactions for %(name)s") % {'name': str(statement)})
else: else:
messages.error(request, messages.error(request,
_("Error while generating transactions for %(name)s. Do all bills have a payer?") % {'name': str(statement)}) _("Error while generating transactions for %(name)s. Do all bills have a payer and, if this statement is attached to an excursion, was a person selected that receives the subsidies?") % {'name': str(statement)})
return HttpResponseRedirect(reverse('admin:%s_%s_change' % (self.opts.app_label, self.opts.model_name), args=(statement.pk,))) return HttpResponseRedirect(reverse('admin:%s_%s_change' % (self.opts.app_label, self.opts.model_name), args=(statement.pk,)))
context = dict(self.admin_site.each_context(request), context = dict(self.admin_site.each_context(request),
title=_('View submitted statement'), title=_('View submitted statement'),

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-18 22:42+0100\n" "POT-Creation-Date: 2025-01-19 11:40+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -114,10 +114,14 @@ msgstr "Automatisch Überweisungsträger für %(name)s generiert."
#: finance/admin.py #: finance/admin.py
#, python-format #, python-format
msgid "" msgid ""
"Error while generating transactions for %(name)s. Do all bills have a payer?" "Error while generating transactions for %(name)s. Do all bills have a payer "
"and, if this statement is attached to an excursion, was a person selected "
"that receives the subsidies?"
msgstr "" msgstr ""
"Fehler beim Erzeugen der Überweisungsträger für %(name)s. Sind für alle " "Fehler beim Erzeugen der Überweisungsträger für %(name)s. Sind für alle "
"Quittungen eine bezahlende Person eingestellt? " "Quittungen eine bezahlende Person eingestellt und, falls diese Abrechnung zu "
"einer Ausfahrt gehört, wurde eine Person als Empfänger*in der Übernachtungs- "
"und Fahrtkostenzuschüsse ausgewählt?"
#: finance/admin.py #: finance/admin.py
msgid "View submitted statement" msgid "View submitted statement"

@ -236,8 +236,11 @@ class Statement(CommonModel):
Transaction(statement=self, member=yl, amount=self.allowance_per_yl, confirmed=False, reference=ref).save() Transaction(statement=self, member=yl, amount=self.allowance_per_yl, confirmed=False, reference=ref).save()
# subsidies (i.e. night and transportation costs) # subsidies (i.e. night and transportation costs)
ref = _("Night and travel costs for %(excu)s") % {'excu': self.excursion.name} if self.subsidy_to:
Transaction(statement=self, member=self.subsidy_to, amount=self.total_subsidies, confirmed=False, reference=ref).save() ref = _("Night and travel costs for %(excu)s") % {'excu': self.excursion.name}
Transaction(statement=self, member=self.subsidy_to, amount=self.total_subsidies, confirmed=False, reference=ref).save()
else:
return False
return True return True
def reduce_transactions(self): def reduce_transactions(self):

@ -36,7 +36,7 @@ class StatementTestCase(TestCase):
tour_type=GEMEINSCHAFTS_TOUR, tour_type=GEMEINSCHAFTS_TOUR,
tour_approach=MUSKELKRAFT_ANREISE, tour_approach=MUSKELKRAFT_ANREISE,
difficulty=1) difficulty=1)
self.st3 = Statement.objects.create(night_cost=self.night_cost, excursion=ex) self.st3 = Statement.objects.create(night_cost=self.night_cost, excursion=ex, subsidy_to=self.fritz)
for i in range(self.participant_count): for i in range(self.participant_count):
m = Member.objects.create(prename='Fritz {}'.format(i), lastname='Walter', birth_date=timezone.now().date(), m = Member.objects.create(prename='Fritz {}'.format(i), lastname='Walter', birth_date=timezone.now().date(),
email=settings.TEST_MAIL, gender=MALE) email=settings.TEST_MAIL, gender=MALE)
@ -49,12 +49,14 @@ class StatementTestCase(TestCase):
amount=42.69, costs_covered=True, paid_by=m) amount=42.69, costs_covered=True, paid_by=m)
m.group.add(self.jl) m.group.add(self.jl)
ex.jugendleiter.add(m) ex.jugendleiter.add(m)
if i < 3:
self.st3.allowance_to.add(m)
ex = Freizeit.objects.create(name='Wild trip 2', kilometers_traveled=self.kilometers_traveled, ex = Freizeit.objects.create(name='Wild trip 2', kilometers_traveled=self.kilometers_traveled,
tour_type=GEMEINSCHAFTS_TOUR, tour_type=GEMEINSCHAFTS_TOUR,
tour_approach=MUSKELKRAFT_ANREISE, tour_approach=MUSKELKRAFT_ANREISE,
difficulty=2) difficulty=2)
self.st4 = Statement.objects.create(night_cost=self.night_cost, excursion=ex) self.st4 = Statement.objects.create(night_cost=self.night_cost, excursion=ex, subsidy_to=self.fritz)
for i in range(2): for i in range(2):
m = Member.objects.create(prename='Peter {}'.format(i), lastname='Walter', birth_date=timezone.now().date(), m = Member.objects.create(prename='Peter {}'.format(i), lastname='Walter', birth_date=timezone.now().date(),
email=settings.TEST_MAIL, gender=DIVERSE) email=settings.TEST_MAIL, gender=DIVERSE)
@ -74,19 +76,24 @@ class StatementTestCase(TestCase):
def test_reduce_transactions(self): def test_reduce_transactions(self):
self.st3.generate_transactions() self.st3.generate_transactions()
self.assertEqual(self.st3.transaction_set.count(), self.staff_count * 2, self.assertTrue(self.st3.allowance_to_valid, 'Configured `allowance_to` field is invalid.')
# every youth leader on `st3` paid one bill, the first three receive the allowance
# and one receives the subsidies
self.assertEqual(self.st3.transaction_set.count(), self.st3.real_staff_count + self.staff_count + 1,
'Transaction count is not twice the staff count.') 'Transaction count is not twice the staff count.')
self.st3.reduce_transactions() self.st3.reduce_transactions()
self.assertEqual(self.st3.transaction_set.count(), self.staff_count * 2, self.assertEqual(self.st3.transaction_set.count(), self.st3.real_staff_count + self.staff_count + 1,
'Transaction count after reduction is not the same as before, although no ledgers are configured.') 'Transaction count after reduction is not the same as before, although no ledgers are configured.')
for trans in self.st3.transaction_set.all(): for trans in self.st3.transaction_set.all():
trans.ledger = self.personal_account trans.ledger = self.personal_account
trans.save() trans.save()
self.st3.reduce_transactions() self.st3.reduce_transactions()
self.assertEqual(self.st3.transaction_set.count(), self.staff_count, # the three yls that receive an allowance should only receive one transaction after reducing,
'Transaction count after setting ledgers and reduction is not halved.') # the additional one is the one for the subsidies
self.assertEqual(self.st3.transaction_set.count(), self.staff_count + 1,
'Transaction count after setting ledgers and reduction is incorrect.')
self.st3.reduce_transactions() self.st3.reduce_transactions()
self.assertEqual(self.st3.transaction_set.count(), self.staff_count, self.assertEqual(self.st3.transaction_set.count(), self.staff_count + 1,
'Transaction count did change after reducing a second time.') 'Transaction count did change after reducing a second time.')
def test_confirm_statement(self): def test_confirm_statement(self):
@ -101,6 +108,8 @@ class StatementTestCase(TestCase):
for trans in self.st3.transaction_set.all(): for trans in self.st3.transaction_set.all():
trans.ledger = self.personal_account trans.ledger = self.personal_account
trans.save() trans.save()
self.assertEqual(self.st3.validity, Statement.VALID,
'Statement is not valid, although it was setup to be so.')
self.assertTrue(self.st3.confirm(confirmer=self.fritz), self.assertTrue(self.st3.confirm(confirmer=self.fritz),
'Statement was not confirmed, although it submitted and valid.') 'Statement was not confirmed, although it submitted and valid.')
self.assertEqual(self.st3.confirmed_by, self.fritz, 'Statement not confirmed by fritz.') self.assertEqual(self.st3.confirmed_by, self.fritz, 'Statement not confirmed by fritz.')

Loading…
Cancel
Save