parent
93c4b43fa3
commit
46ea394422
6 changed files with 57 additions and 4 deletions
|
@ -14,6 +14,7 @@
|
||||||
<p>
|
<p>
|
||||||
{% blocktranslate %}Are you sure you want do delete <strong>{{ object }}</strong> ?{% endblocktranslate %}
|
{% blocktranslate %}Are you sure you want do delete <strong>{{ object }}</strong> ?{% endblocktranslate %}
|
||||||
</p>
|
</p>
|
||||||
|
{% block additionalinfo %}{% endblock %}
|
||||||
{{ form }}
|
{{ form }}
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{{ object.get_absolute_url }}">{% translate "Cancel" %}</a>
|
<a href="{{ object.get_absolute_url }}">{% translate "Cancel" %}</a>
|
||||||
|
|
|
@ -23,7 +23,9 @@ class StatementForm(NummiForm):
|
||||||
self.fields["transactions"] = forms.MultipleChoiceField(
|
self.fields["transactions"] = forms.MultipleChoiceField(
|
||||||
choices=(
|
choices=(
|
||||||
((_transaction.id), _transaction)
|
((_transaction.id), _transaction)
|
||||||
for _transaction in Transaction.objects.filter(user=_user)
|
for _transaction in Transaction.objects.filter(
|
||||||
|
user=_user, statement=None
|
||||||
|
)
|
||||||
),
|
),
|
||||||
label=_("Add transactions"),
|
label=_("Add transactions"),
|
||||||
required=False,
|
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):
|
class StatementDeleteView(NummiDeleteView):
|
||||||
|
template_name = "statement/confirm_delete.html"
|
||||||
model = Statement
|
model = Statement
|
||||||
pk_url_kwarg = "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 = models.ForeignKey(
|
||||||
Statement,
|
Statement,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
verbose_name=_("Statement"),
|
verbose_name=_("Statement"),
|
||||||
)
|
)
|
||||||
account = models.ForeignKey(
|
account = models.ForeignKey(
|
||||||
Account,
|
Account,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
verbose_name=_("Account"),
|
verbose_name=_("Account"),
|
||||||
editable=False,
|
editable=False,
|
||||||
)
|
)
|
||||||
|
@ -54,10 +58,12 @@ class Transaction(UserModel):
|
||||||
prev_self = Transaction.objects.get(pk=self.pk)
|
prev_self = Transaction.objects.get(pk=self.pk)
|
||||||
else:
|
else:
|
||||||
prev_self = None
|
prev_self = None
|
||||||
|
if self.statement:
|
||||||
self.account = self.statement.account
|
self.account = self.statement.account
|
||||||
super().save(*args, **kwargs)
|
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()
|
prev_self.statement.update_sum()
|
||||||
|
if self.statement:
|
||||||
self.statement.update_sum()
|
self.statement.update_sum()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
Loading…
Reference in a new issue