diff --git a/app/WYGIWYH/settings.py b/app/WYGIWYH/settings.py index 6875bc0..bb5ddf1 100644 --- a/app/WYGIWYH/settings.py +++ b/app/WYGIWYH/settings.py @@ -363,7 +363,13 @@ PWA_APP_SPLASH_SCREEN = [ ] PWA_APP_DIR = "ltr" PWA_APP_LANG = "en-US" -PWA_APP_SHORTCUTS = [] +PWA_APP_SHORTCUTS = [ + { + "name": "New Transaction", + "url": "/add/", + "description": "Add new transaction", + } +] PWA_APP_SCREENSHOTS = [ { "src": "/static/img/pwa/splash-750x1334.png", diff --git a/app/apps/transactions/forms.py b/app/apps/transactions/forms.py index 6fbdcff..50ba2f1 100644 --- a/app/apps/transactions/forms.py +++ b/app/apps/transactions/forms.py @@ -1,5 +1,5 @@ -from crispy_bootstrap5.bootstrap5 import Switch -from crispy_forms.bootstrap import FormActions +from crispy_bootstrap5.bootstrap5 import Switch, BS5Accordion +from crispy_forms.bootstrap import FormActions, AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import ( Layout, @@ -136,6 +136,46 @@ class TransactionForm(forms.ModelForm): "notes", ) + self.helper_simple = FormHelper() + self.helper_simple.form_tag = False + self.helper_simple.form_method = "post" + self.helper_simple.layout = Layout( + Field( + "type", + template="transactions/widgets/income_expense_toggle_buttons.html", + ), + Field("is_paid", template="transactions/widgets/paid_toggle_button.html"), + "account", + Row( + Column(Field("date"), css_class="form-group col-md-6 mb-0"), + Column(Field("reference_date"), css_class="form-group col-md-6 mb-0"), + css_class="form-row", + ), + "description", + Field("amount", inputmode="decimal"), + BS5Accordion( + AccordionGroup( + _("More"), + "entities", + Row( + Column("category", css_class="form-group col-md-6 mb-0"), + Column("tags", css_class="form-group col-md-6 mb-0"), + css_class="form-row", + ), + "notes", + active=False, + ), + flush=False, + always_open=False, + css_class="mb-3", + ), + FormActions( + NoClassSubmit( + "submit", _("Add"), css_class="btn btn-outline-primary w-100" + ), + ), + ) + self.fields["reference_date"].required = False self.fields["date"].widget = AirDatePickerInput(clear_button=False, user=user) diff --git a/app/apps/transactions/urls.py b/app/apps/transactions/urls.py index 44a6884..d9a524c 100644 --- a/app/apps/transactions/urls.py +++ b/app/apps/transactions/urls.py @@ -51,6 +51,11 @@ urlpatterns = [ views.transaction_add, name="transaction_add", ), + path( + "add/", + views.transaction_simple_add, + name="transaction_simple_add", + ), path( "transactions/transfer", views.transactions_transfer, diff --git a/app/apps/transactions/views/transactions.py b/app/apps/transactions/views/transactions.py index d6c3b83..f07442e 100644 --- a/app/apps/transactions/views/transactions.py +++ b/app/apps/transactions/views/transactions.py @@ -65,6 +65,50 @@ def transaction_add(request): ) +@login_required +@require_http_methods(["GET", "POST"]) +def transaction_simple_add(request): + month = int(request.GET.get("month", timezone.localdate(timezone.now()).month)) + year = int(request.GET.get("year", timezone.localdate(timezone.now()).year)) + transaction_type = Transaction.Type(request.GET.get("type", "IN")) + + now = timezone.localdate(timezone.now()) + expected_date = datetime.datetime( + day=now.day if month == now.month and year == now.year else 1, + month=month, + year=year, + ).date() + + if request.method == "POST": + form = TransactionForm(request.POST, user=request.user) + if form.is_valid(): + form.save() + messages.success(request, _("Transaction added successfully")) + + form = TransactionForm( + user=request.user, + initial={ + "date": expected_date, + "type": transaction_type, + }, + ) + + else: + form = TransactionForm( + user=request.user, + initial={ + "date": expected_date, + "type": transaction_type, + }, + ) + + return render( + request, + "transactions/pages/add.html", + {"form": form}, + ) + + @only_htmx @login_required @require_http_methods(["GET", "POST"]) diff --git a/app/templates/transactions/pages/add.html b/app/templates/transactions/pages/add.html new file mode 100644 index 0000000..011ea04 --- /dev/null +++ b/app/templates/transactions/pages/add.html @@ -0,0 +1,15 @@ +{% extends 'layouts/base.html' %} +{% load crispy_forms_tags %} +{% load i18n %} + +{% block title %}{% translate 'New transaction' %}{% endblock %} + +{% block content %} +
+
+ {% crispy form form.helper_simple %} +
+
+{% endblock %}