feat: add notes to Tranfer, Recurring and Installment

This commit is contained in:
Herculino Trotta
2024-10-24 14:48:44 -03:00
parent 5ea40602ae
commit 0e0ec93b7f
2 changed files with 30 additions and 3 deletions
+26 -3
View File
@@ -194,6 +194,15 @@ class TransferForm(forms.Form):
) )
reference_date = MonthYearFormField(label=_("Reference Date"), required=False) reference_date = MonthYearFormField(label=_("Reference Date"), required=False)
description = forms.CharField(max_length=500, label=_("Description")) description = forms.CharField(max_length=500, label=_("Description"))
notes = forms.CharField(
required=False,
widget=forms.Textarea(
attrs={
"rows": 3,
}
),
label=_("Notes"),
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@@ -212,6 +221,7 @@ class TransferForm(forms.Form):
css_class="form-row", css_class="form-row",
), ),
Field("description"), Field("description"),
Field("notes"),
Row( Row(
Column( Column(
Row( Row(
@@ -285,6 +295,7 @@ class TransferForm(forms.Form):
description = self.cleaned_data["description"] description = self.cleaned_data["description"]
from_category = self.cleaned_data.get("from_category") from_category = self.cleaned_data.get("from_category")
to_category = self.cleaned_data.get("to_category") to_category = self.cleaned_data.get("to_category")
notes = self.cleaned_data.get("notes")
# Create "From" transaction # Create "From" transaction
from_transaction = Transaction.objects.create( from_transaction = Transaction.objects.create(
@@ -296,6 +307,7 @@ class TransferForm(forms.Form):
amount=from_amount, amount=from_amount,
description=description, description=description,
category=from_category, category=from_category,
notes=notes,
) )
from_transaction.tags.set(self.cleaned_data.get("from_tags", [])) from_transaction.tags.set(self.cleaned_data.get("from_tags", []))
@@ -309,6 +321,7 @@ class TransferForm(forms.Form):
amount=to_amount, amount=to_amount,
description=description, description=description,
category=to_category, category=to_category,
notes=notes,
) )
to_transaction.tags.set(self.cleaned_data.get("to_tags", [])) to_transaction.tags.set(self.cleaned_data.get("to_tags", []))
@@ -349,12 +362,14 @@ class InstallmentPlanForm(forms.ModelForm):
"installment_amount", "installment_amount",
"category", "category",
"tags", "tags",
"notes",
"installment_start", "installment_start",
] ]
widgets = { widgets = {
"start_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"), "start_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"),
"account": TomSelect(), "account": TomSelect(),
"recurrence": TomSelect(clear_button=False), "recurrence": TomSelect(clear_button=False),
"notes": forms.Textarea(attrs={"rows": 3}),
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@@ -371,15 +386,16 @@ class InstallmentPlanForm(forms.ModelForm):
), ),
"account", "account",
"description", "description",
"notes",
Row( Row(
Column("number_of_installments", css_class="form-group col-md-6 mb-0"), Column("number_of_installments", css_class="form-group col-md-6 mb-0"),
Column("installment_start", css_class="form-group col-md-6 mb-0"), Column("installment_start", css_class="form-group col-md-6 mb-0"),
css_class="form-row", css_class="form-row",
), ),
"recurrence",
Row( Row(
Column("start_date", css_class="form-group col-md-6 mb-0"), Column("start_date", css_class="form-group col-md-4 mb-0"),
Column("reference_date", css_class="form-group col-md-6 mb-0"), Column("reference_date", css_class="form-group col-md-4 mb-0"),
Column("recurrence", css_class="form-group col-md-4 mb-0"),
css_class="form-row", css_class="form-row",
), ),
"installment_amount", "installment_amount",
@@ -523,11 +539,17 @@ class RecurringTransactionForm(forms.ModelForm):
"end_date", "end_date",
"recurrence_type", "recurrence_type",
"recurrence_interval", "recurrence_interval",
"notes",
] ]
widgets = { widgets = {
"start_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"), "start_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"),
"end_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"), "end_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"),
"recurrence_type": TomSelect(clear_button=False), "recurrence_type": TomSelect(clear_button=False),
"notes": forms.Textarea(
attrs={
"rows": 3,
}
),
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@@ -549,6 +571,7 @@ class RecurringTransactionForm(forms.ModelForm):
Column("tags", css_class="form-group col-md-6 mb-0"), Column("tags", css_class="form-group col-md-6 mb-0"),
css_class="form-row", css_class="form-row",
), ),
"notes",
Row( Row(
Column("start_date", css_class="form-group col-md-6 mb-0"), Column("start_date", css_class="form-group col-md-6 mb-0"),
Column("reference_date", css_class="form-group col-md-6 mb-0"), Column("reference_date", css_class="form-group col-md-6 mb-0"),
+4
View File
@@ -182,6 +182,7 @@ class InstallmentPlan(models.Model):
verbose_name=_("Category"), verbose_name=_("Category"),
) )
tags = models.ManyToManyField(TransactionTag, verbose_name=_("Tags"), blank=True) tags = models.ManyToManyField(TransactionTag, verbose_name=_("Tags"), blank=True)
notes = models.TextField(blank=True, verbose_name=_("Notes"))
class Meta: class Meta:
verbose_name = _("Installment Plan") verbose_name = _("Installment Plan")
@@ -248,6 +249,7 @@ class InstallmentPlan(models.Model):
category=self.category, category=self.category,
installment_plan=self, installment_plan=self,
installment_id=i, installment_id=i,
notes=self.notes,
) )
new_transaction.tags.set(self.tags.all()) new_transaction.tags.set(self.tags.all())
@@ -346,6 +348,7 @@ class RecurringTransaction(models.Model):
null=True, null=True,
) )
tags = models.ManyToManyField(TransactionTag, verbose_name=_("Tags"), blank=True) tags = models.ManyToManyField(TransactionTag, verbose_name=_("Tags"), blank=True)
notes = models.TextField(blank=True, verbose_name=_("Notes"))
reference_date = models.DateField( reference_date = models.DateField(
verbose_name=_("Reference Date"), null=True, blank=True verbose_name=_("Reference Date"), null=True, blank=True
) )
@@ -414,6 +417,7 @@ class RecurringTransaction(models.Model):
category=self.category, category=self.category,
is_paid=False, is_paid=False,
recurring_transaction=self, recurring_transaction=self,
notes=self.notes,
) )
if self.tags.exists(): if self.tags.exists():
created_transaction.tags.set(self.tags.all()) created_transaction.tags.set(self.tags.all())