Fix #21
This commit is contained in:
parent
bac3b59358
commit
090f1a3a5c
2 changed files with 19 additions and 13 deletions
|
@ -0,0 +1,16 @@
|
||||||
|
# Generated by Django 4.2 on 2025-01-02 13:03
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("transaction", "0003_alter_transaction_account_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="transaction",
|
||||||
|
name="account",
|
||||||
|
),
|
||||||
|
]
|
|
@ -2,7 +2,6 @@ import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from account.models import Account
|
|
||||||
from category.models import Category
|
from category.models import Category
|
||||||
from django.core.validators import FileExtensionValidator
|
from django.core.validators import FileExtensionValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -44,22 +43,12 @@ class Transaction(UserModel):
|
||||||
null=True,
|
null=True,
|
||||||
verbose_name=_("Statement"),
|
verbose_name=_("Statement"),
|
||||||
)
|
)
|
||||||
account = models.ForeignKey(
|
|
||||||
Account,
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
verbose_name=_("Account"),
|
|
||||||
editable=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if Transaction.objects.filter(pk=self.pk):
|
if Transaction.objects.filter(pk=self.pk):
|
||||||
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
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
if prev_self is not None and prev_self.statement:
|
if prev_self is not None and prev_self.statement:
|
||||||
prev_self.statement.update_sum()
|
prev_self.statement.update_sum()
|
||||||
|
@ -76,8 +65,9 @@ class Transaction(UserModel):
|
||||||
return reverse("del_transaction", args=(self.pk,))
|
return reverse("del_transaction", args=(self.pk,))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def invoices(self):
|
def account(self):
|
||||||
return Invoice.objects.filter(transaction=self)
|
if self.statement:
|
||||||
|
return self.statement.account
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_invoice(self):
|
def has_invoice(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue