parent
93c4b43fa3
commit
46ea394422
6 changed files with 57 additions and 4 deletions
|
@ -14,6 +14,7 @@
|
|||
<p>
|
||||
{% blocktranslate %}Are you sure you want do delete <strong>{{ object }}</strong> ?{% endblocktranslate %}
|
||||
</p>
|
||||
{% block additionalinfo %}{% endblock %}
|
||||
{{ form }}
|
||||
<div class="buttons">
|
||||
<a href="{{ object.get_absolute_url }}">{% translate "Cancel" %}</a>
|
||||
|
|
|
@ -23,7 +23,9 @@ class StatementForm(NummiForm):
|
|||
self.fields["transactions"] = forms.MultipleChoiceField(
|
||||
choices=(
|
||||
((_transaction.id), _transaction)
|
||||
for _transaction in Transaction.objects.filter(user=_user)
|
||||
for _transaction in Transaction.objects.filter(
|
||||
user=_user, statement=None
|
||||
)
|
||||
),
|
||||
label=_("Add transactions"),
|
||||
required=False,
|
||||
|
|
5
nummi/statement/templates/statement/confirm_delete.html
Normal file
5
nummi/statement/templates/statement/confirm_delete.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% extends "main/confirm_delete.html" %}
|
||||
{% load i18n %}
|
||||
{% block additionalinfo %}
|
||||
<p>{% blocktranslate %}This will delete all transactions in this statement.{% endblocktranslate %}</p>
|
||||
{% endblock %}
|
|
@ -52,6 +52,7 @@ class StatementUpdateView(NummiUpdateView):
|
|||
|
||||
|
||||
class StatementDeleteView(NummiDeleteView):
|
||||
template_name = "statement/confirm_delete.html"
|
||||
model = Statement
|
||||
pk_url_kwarg = "statement"
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
# Generated by Django 4.2 on 2024-12-30 15:29
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("statement", "0002_alter_statement_table"),
|
||||
("account", "0003_account_archived"),
|
||||
("transaction", "0002_alter_invoice_table_alter_transaction_table"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="transaction",
|
||||
name="account",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
editable=False,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="account.account",
|
||||
verbose_name="Account",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="transaction",
|
||||
name="statement",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="statement.statement",
|
||||
verbose_name="Statement",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -40,11 +40,15 @@ class Transaction(UserModel):
|
|||
statement = models.ForeignKey(
|
||||
Statement,
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Statement"),
|
||||
)
|
||||
account = models.ForeignKey(
|
||||
Account,
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Account"),
|
||||
editable=False,
|
||||
)
|
||||
|
@ -54,11 +58,13 @@ class Transaction(UserModel):
|
|||
prev_self = Transaction.objects.get(pk=self.pk)
|
||||
else:
|
||||
prev_self = None
|
||||
self.account = self.statement.account
|
||||
if self.statement:
|
||||
self.account = self.statement.account
|
||||
super().save(*args, **kwargs)
|
||||
if prev_self is not None:
|
||||
if prev_self is not None and prev_self.statement:
|
||||
prev_self.statement.update_sum()
|
||||
self.statement.update_sum()
|
||||
if self.statement:
|
||||
self.statement.update_sum()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
|
|
Loading…
Reference in a new issue