Split backend in applications
This commit is contained in:
parent
a0d0b5d594
commit
b05c3e6760
47 changed files with 1463 additions and 866 deletions
41
nummi/statement/forms.py
Normal file
41
nummi/statement/forms.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from account.models import Account
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from main.forms import NummiFileInput, NummiForm
|
||||
from transaction.models import Transaction
|
||||
|
||||
from .models import Statement
|
||||
|
||||
|
||||
class StatementForm(NummiForm):
|
||||
class Meta:
|
||||
model = Statement
|
||||
fields = ["account", "start_date", "date", "start_value", "value", "file"]
|
||||
widgets = {
|
||||
"file": NummiFileInput,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
_user = kwargs.get("user")
|
||||
_disable_account = kwargs.pop("disable_account", False)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["account"].queryset = Account.objects.filter(user=_user)
|
||||
self.fields["transactions"] = forms.MultipleChoiceField(
|
||||
choices=(
|
||||
((_transaction.id), _transaction)
|
||||
for _transaction in Transaction.objects.filter(user=_user)
|
||||
),
|
||||
label=_("Add transactions"),
|
||||
required=False,
|
||||
)
|
||||
if _disable_account:
|
||||
self.fields["account"].disabled = True
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
instance = super().save(*args, **kwargs)
|
||||
new_transactions = Transaction.objects.filter(
|
||||
id__in=self.cleaned_data["transactions"]
|
||||
)
|
||||
|
||||
instance.transaction_set.add(*new_transactions, bulk=False)
|
||||
return instance
|
Loading…
Add table
Add a link
Reference in a new issue