From 0e0ec93b7f41abcae253ec3b8a2f54f8170319b8 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Thu, 24 Oct 2024 14:48:44 -0300 Subject: [PATCH] feat: add notes to Tranfer, Recurring and Installment --- app/apps/transactions/forms.py | 29 ++++++++++++++++++++++++++--- app/apps/transactions/models.py | 4 ++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/apps/transactions/forms.py b/app/apps/transactions/forms.py index bfdc134..8c7b73b 100644 --- a/app/apps/transactions/forms.py +++ b/app/apps/transactions/forms.py @@ -194,6 +194,15 @@ class TransferForm(forms.Form): ) reference_date = MonthYearFormField(label=_("Reference Date"), required=False) 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): super().__init__(*args, **kwargs) @@ -212,6 +221,7 @@ class TransferForm(forms.Form): css_class="form-row", ), Field("description"), + Field("notes"), Row( Column( Row( @@ -285,6 +295,7 @@ class TransferForm(forms.Form): description = self.cleaned_data["description"] from_category = self.cleaned_data.get("from_category") to_category = self.cleaned_data.get("to_category") + notes = self.cleaned_data.get("notes") # Create "From" transaction from_transaction = Transaction.objects.create( @@ -296,6 +307,7 @@ class TransferForm(forms.Form): amount=from_amount, description=description, category=from_category, + notes=notes, ) from_transaction.tags.set(self.cleaned_data.get("from_tags", [])) @@ -309,6 +321,7 @@ class TransferForm(forms.Form): amount=to_amount, description=description, category=to_category, + notes=notes, ) to_transaction.tags.set(self.cleaned_data.get("to_tags", [])) @@ -349,12 +362,14 @@ class InstallmentPlanForm(forms.ModelForm): "installment_amount", "category", "tags", + "notes", "installment_start", ] widgets = { "start_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"), "account": TomSelect(), "recurrence": TomSelect(clear_button=False), + "notes": forms.Textarea(attrs={"rows": 3}), } def __init__(self, *args, **kwargs): @@ -371,15 +386,16 @@ class InstallmentPlanForm(forms.ModelForm): ), "account", "description", + "notes", Row( 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"), css_class="form-row", ), - "recurrence", Row( - 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("start_date", css_class="form-group col-md-4 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", ), "installment_amount", @@ -523,11 +539,17 @@ class RecurringTransactionForm(forms.ModelForm): "end_date", "recurrence_type", "recurrence_interval", + "notes", ] widgets = { "start_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), + "notes": forms.Textarea( + attrs={ + "rows": 3, + } + ), } def __init__(self, *args, **kwargs): @@ -549,6 +571,7 @@ class RecurringTransactionForm(forms.ModelForm): Column("tags", css_class="form-group col-md-6 mb-0"), css_class="form-row", ), + "notes", Row( Column("start_date", css_class="form-group col-md-6 mb-0"), Column("reference_date", css_class="form-group col-md-6 mb-0"), diff --git a/app/apps/transactions/models.py b/app/apps/transactions/models.py index 8dd0782..52cb21c 100644 --- a/app/apps/transactions/models.py +++ b/app/apps/transactions/models.py @@ -182,6 +182,7 @@ class InstallmentPlan(models.Model): verbose_name=_("Category"), ) tags = models.ManyToManyField(TransactionTag, verbose_name=_("Tags"), blank=True) + notes = models.TextField(blank=True, verbose_name=_("Notes")) class Meta: verbose_name = _("Installment Plan") @@ -248,6 +249,7 @@ class InstallmentPlan(models.Model): category=self.category, installment_plan=self, installment_id=i, + notes=self.notes, ) new_transaction.tags.set(self.tags.all()) @@ -346,6 +348,7 @@ class RecurringTransaction(models.Model): null=True, ) tags = models.ManyToManyField(TransactionTag, verbose_name=_("Tags"), blank=True) + notes = models.TextField(blank=True, verbose_name=_("Notes")) reference_date = models.DateField( verbose_name=_("Reference Date"), null=True, blank=True ) @@ -414,6 +417,7 @@ class RecurringTransaction(models.Model): category=self.category, is_paid=False, recurring_transaction=self, + notes=self.notes, ) if self.tags.exists(): created_transaction.tags.set(self.tags.all())