finance: catch if bills have no set paid_by field

pull/73/head
Christian Merten 1 year ago
parent 3a9fca0a1e
commit 8a58a43bcd
Signed by: christian.merten
GPG Key ID: D953D69721B948B3

@ -205,9 +205,13 @@ class StatementSubmittedAdmin(admin.ModelAdmin):
messages.error(request, messages.error(request,
_("%(name)s already has transactions. Please delete them first, if you want to generate new ones") % {'name': str(statement)}) _("%(name)s already has transactions. Please delete them first, if you want to generate new ones") % {'name': str(statement)})
else: else:
statement.generate_transactions() success = statement.generate_transactions()
messages.success(request, if success:
_("Successfully generated transactions for %(name)s") % {'name': str(statement)}) messages.success(request,
_("Successfully generated transactions for %(name)s") % {'name': str(statement)})
else:
messages.error(request,
_("Error while generating transactions for %(name)s. Do all bills have a payer?") % {'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: 2024-11-17 16:46+0100\n" "POT-Creation-Date: 2024-11-24 01:34+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"
@ -90,33 +90,41 @@ msgstr ""
"%(name)s hat bereits Überweisungen. Bitte lösche diese zunächst, bevor du " "%(name)s hat bereits Überweisungen. Bitte lösche diese zunächst, bevor du "
"neue generierst." "neue generierst."
#: finance/admin.py:210 #: finance/admin.py:211
#, python-format #, python-format
msgid "Successfully generated transactions for %(name)s" msgid "Successfully generated transactions for %(name)s"
msgstr "Automatisch Überweisungsträger für %(name)s generiert." msgstr "Automatisch Überweisungsträger für %(name)s generiert."
#: finance/admin.py:213 #: finance/admin.py:214
#, python-format
msgid ""
"Error while generating transactions for %(name)s. Do all bills have a payer?"
msgstr ""
"Fehler beim Erzeugen der Überweisungsträger für %(name)s. Sind für alle "
"Quittungen eine bezahlende Person eingestellt? "
#: finance/admin.py:217
msgid "View submitted statement" msgid "View submitted statement"
msgstr "Eingereichte Abrechnung einsehen" msgstr "Eingereichte Abrechnung einsehen"
#: finance/admin.py:241 #: finance/admin.py:245
#, python-format #, python-format
msgid "Successfully reduced transactions for %(name)s." msgid "Successfully reduced transactions for %(name)s."
msgstr "Überweisungsträger für %(name)s minimiert." msgstr "Überweisungsträger für %(name)s minimiert."
#: finance/admin.py:285 #: finance/admin.py:289
#, python-format #, python-format
msgid "%(name)s is not yet confirmed." msgid "%(name)s is not yet confirmed."
msgstr "%(name)s ist noch nicht bestätigt." msgstr "%(name)s ist noch nicht bestätigt."
#: finance/admin.py:294 #: finance/admin.py:298
#, python-format #, python-format
msgid "Successfully unconfirmed %(name)s. I hope you know what you are doing." msgid "Successfully unconfirmed %(name)s. I hope you know what you are doing."
msgstr "" msgstr ""
"Erfolgreich die Bestätigung von %(name)s zurückgenommen. Ich hoffe du weißt " "Erfolgreich die Bestätigung von %(name)s zurückgenommen. Ich hoffe du weißt "
"was du machst." "was du machst."
#: finance/admin.py:299 finance/templates/admin/unconfirm_statement.html:26 #: finance/admin.py:303 finance/templates/admin/unconfirm_statement.html:26
msgid "Unconfirm statement" msgid "Unconfirm statement"
msgstr "Bestätigung zurücknehmen" msgstr "Bestätigung zurücknehmen"
@ -128,7 +136,7 @@ msgstr "Finanzen"
msgid "Name" msgid "Name"
msgstr "Name" msgstr "Name"
#: finance/models.py:25 finance/models.py:438 finance/models.py:462 #: finance/models.py:25 finance/models.py:441 finance/models.py:465
#: finance/templates/admin/confirmed_statement.html:38 #: finance/templates/admin/confirmed_statement.html:38
#: finance/templates/admin/overview_submitted_statement.html:100 #: finance/templates/admin/overview_submitted_statement.html:100
msgid "Ledger" msgid "Ledger"
@ -138,11 +146,11 @@ msgstr "Geldtopf"
msgid "Ledgers" msgid "Ledgers"
msgstr "Geldtöpfe" msgstr "Geldtöpfe"
#: finance/models.py:46 finance/models.py:381 finance/models.py:461 #: finance/models.py:46 finance/models.py:384 finance/models.py:464
msgid "Short description" msgid "Short description"
msgstr "Kurzbeschreibung" msgstr "Kurzbeschreibung"
#: finance/models.py:49 finance/models.py:382 #: finance/models.py:49 finance/models.py:385
msgid "Explanation" msgid "Explanation"
msgstr "Erklärung" msgstr "Erklärung"
@ -166,7 +174,7 @@ msgstr "Eingereicht am"
msgid "Confirmed" msgid "Confirmed"
msgstr "Abgewickelt" msgstr "Abgewickelt"
#: finance/models.py:61 finance/models.py:445 #: finance/models.py:61 finance/models.py:448
msgid "Paid on" msgid "Paid on"
msgstr "Bezahlt am" msgstr "Bezahlt am"
@ -178,11 +186,11 @@ msgstr "Erstellt von"
msgid "Submitted by" msgid "Submitted by"
msgstr "Eingereicht bei" msgstr "Eingereicht bei"
#: finance/models.py:73 finance/models.py:446 #: finance/models.py:73 finance/models.py:449
msgid "Authorized by" msgid "Authorized by"
msgstr "Autorisiert von" msgstr "Autorisiert von"
#: finance/models.py:80 finance/models.py:380 finance/models.py:441 #: finance/models.py:80 finance/models.py:383 finance/models.py:444
msgid "Statement" msgid "Statement"
msgstr "Abrechnung" msgstr "Abrechnung"
@ -199,90 +207,90 @@ msgstr "Abrechnung: %(excursion)s"
msgid "Ready to confirm" msgid "Ready to confirm"
msgstr "Bereit zur Abwicklung" msgstr "Bereit zur Abwicklung"
#: finance/models.py:190 #: finance/models.py:192
#, python-format #, python-format
msgid "Compensation for %(excu)s" msgid "Compensation for %(excu)s"
msgstr "Entschädigung für %(excu)s" msgstr "Entschädigung für %(excu)s"
#: finance/models.py:322 #: finance/models.py:325
#: finance/templates/admin/overview_submitted_statement.html:78 #: finance/templates/admin/overview_submitted_statement.html:78
msgid "Total" msgid "Total"
msgstr "Gesamtbetrag" msgstr "Gesamtbetrag"
#: finance/models.py:335 #: finance/models.py:338
msgid "Statement in preparation" msgid "Statement in preparation"
msgstr "Abrechnung in Vorbereitung" msgstr "Abrechnung in Vorbereitung"
#: finance/models.py:336 #: finance/models.py:339
msgid "Statements in preparation" msgid "Statements in preparation"
msgstr "Abrechnungen in Vorbereitung" msgstr "Abrechnungen in Vorbereitung"
#: finance/models.py:355 #: finance/models.py:358
msgid "Submitted statement" msgid "Submitted statement"
msgstr "Eingereichte Abrechnung" msgstr "Eingereichte Abrechnung"
#: finance/models.py:356 #: finance/models.py:359
msgid "Submitted statements" msgid "Submitted statements"
msgstr "Eingereichte Abrechnungen" msgstr "Eingereichte Abrechnungen"
#: finance/models.py:372 #: finance/models.py:375
msgid "Paid statement" msgid "Paid statement"
msgstr "Bezahlte Abrechnung" msgstr "Bezahlte Abrechnung"
#: finance/models.py:373 #: finance/models.py:376
msgid "Paid statements" msgid "Paid statements"
msgstr "Bezahlte Abrechnungen" msgstr "Bezahlte Abrechnungen"
#: finance/models.py:385 #: finance/models.py:388
msgid "Paid by" msgid "Paid by"
msgstr "Bezahlt von" msgstr "Bezahlt von"
#: finance/models.py:387 #: finance/models.py:390
msgid "Covered" msgid "Covered"
msgstr "Übernommen" msgstr "Übernommen"
#: finance/models.py:388 #: finance/models.py:391
msgid "Refunded" msgid "Refunded"
msgstr "Ausgezahlt" msgstr "Ausgezahlt"
#: finance/models.py:390 #: finance/models.py:393
msgid "Proof" msgid "Proof"
msgstr "Beleg" msgstr "Beleg"
#: finance/models.py:398 finance/models.py:435 #: finance/models.py:401 finance/models.py:438
#: finance/templates/admin/confirmed_statement.html:36 #: finance/templates/admin/confirmed_statement.html:36
#: finance/templates/admin/overview_submitted_statement.html:31 #: finance/templates/admin/overview_submitted_statement.html:31
#: finance/templates/admin/overview_submitted_statement.html:98 #: finance/templates/admin/overview_submitted_statement.html:98
msgid "Amount" msgid "Amount"
msgstr "Betrag" msgstr "Betrag"
#: finance/models.py:401 finance/models.py:408 finance/models.py:421 #: finance/models.py:404 finance/models.py:411 finance/models.py:424
msgid "Bill" msgid "Bill"
msgstr "Quittung" msgstr "Quittung"
#: finance/models.py:402 finance/models.py:409 finance/models.py:422 #: finance/models.py:405 finance/models.py:412 finance/models.py:425
#: finance/templates/admin/overview_submitted_statement.html:26 #: finance/templates/admin/overview_submitted_statement.html:26
msgid "Bills" msgid "Bills"
msgstr "Quittungen" msgstr "Quittungen"
#: finance/models.py:434 finance/templates/admin/confirmed_statement.html:37 #: finance/models.py:437 finance/templates/admin/confirmed_statement.html:37
#: finance/templates/admin/overview_submitted_statement.html:99 #: finance/templates/admin/overview_submitted_statement.html:99
msgid "Reference" msgid "Reference"
msgstr "Verwendungszweck" msgstr "Verwendungszweck"
#: finance/models.py:436 #: finance/models.py:439
msgid "Recipient" msgid "Recipient"
msgstr "Empfänger" msgstr "Empfänger"
#: finance/models.py:444 #: finance/models.py:447
msgid "Paid" msgid "Paid"
msgstr "Bezahlt" msgstr "Bezahlt"
#: finance/models.py:456 #: finance/models.py:459
msgid "Transaction" msgid "Transaction"
msgstr "Überweisung" msgstr "Überweisung"
#: finance/models.py:457 #: finance/models.py:460
#: finance/templates/admin/overview_submitted_statement.html:84 #: finance/templates/admin/overview_submitted_statement.html:84
msgid "Transactions" msgid "Transactions"
msgstr "Überweisungen" msgstr "Überweisungen"

@ -28,7 +28,7 @@ class Ledger(models.Model):
class TransactionIssue: class TransactionIssue:
def __init__(self, member, current, target): def __init__(self, member, current, target):
self.member, self.current, self. target = member, current, target self.member, self.current, self.target = member, current, target
@property @property
def difference(self): def difference(self):
@ -105,7 +105,7 @@ class Statement(CommonModel):
@property @property
def transaction_issues(self): def transaction_issues(self):
needed_paiments = [(b.paid_by, b.amount) for b in self.bill_set.all() if b.costs_covered] needed_paiments = [(b.paid_by, b.amount) for b in self.bill_set.all() if b.costs_covered and b.paid_by]
if self.excursion is not None: if self.excursion is not None:
needed_paiments.extend([(yl, self.real_per_yl) for yl in self.excursion.jugendleiter.all()]) needed_paiments.extend([(yl, self.real_per_yl) for yl in self.excursion.jugendleiter.all()])
@ -179,6 +179,8 @@ class Statement(CommonModel):
for bill in self.bill_set.all(): for bill in self.bill_set.all():
if not bill.costs_covered: if not bill.costs_covered:
continue continue
if not bill.paid_by:
return False
ref = "{}: {}".format(str(self), bill.short_description) ref = "{}: {}".format(str(self), bill.short_description)
Transaction(statement=self, member=bill.paid_by, amount=bill.amount, confirmed=False, reference=ref).save() Transaction(statement=self, member=bill.paid_by, amount=bill.amount, confirmed=False, reference=ref).save()
@ -189,6 +191,7 @@ class Statement(CommonModel):
for yl in self.excursion.jugendleiter.all(): for yl in self.excursion.jugendleiter.all():
ref = _("Compensation for %(excu)s") % {'excu': self.excursion.name} ref = _("Compensation for %(excu)s") % {'excu': self.excursion.name}
Transaction(statement=self, member=yl, amount=self.real_per_yl, confirmed=False, reference=ref).save() Transaction(statement=self, member=yl, amount=self.real_per_yl, confirmed=False, reference=ref).save()
return True
def reduce_transactions(self): def reduce_transactions(self):
# to minimize the number of needed bank transactions, we bundle transactions from same ledger to # to minimize the number of needed bank transactions, we bundle transactions from same ledger to

Loading…
Cancel
Save