From d89f64f1234b4288fe3e1e18604c1bb62519b86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sun, 2 Jun 2024 00:14:03 +0800 Subject: [PATCH] Fixed so that the default date of the journal entries is calculated based on the client-side date instead of the server-side date. --- src/accounting/journal_entry/views.py | 1 - src/accounting/static/js/journal-entry-form.js | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/accounting/journal_entry/views.py b/src/accounting/journal_entry/views.py index 6258d18..f445594 100644 --- a/src/accounting/journal_entry/views.py +++ b/src/accounting/journal_entry/views.py @@ -67,7 +67,6 @@ def show_add_journal_entry_form(journal_entry_type: JournalEntryType) -> str: form.validate() else: form = journal_entry_op.form() - form.date.data = dt.date.today() return journal_entry_op.render_create_template(form) diff --git a/src/accounting/static/js/journal-entry-form.js b/src/accounting/static/js/journal-entry-form.js index 592f710..0951333 100644 --- a/src/accounting/static/js/journal-entry-form.js +++ b/src/accounting/static/js/journal-entry-form.js @@ -135,6 +135,13 @@ class JournalEntryForm { }; this.#resetDeleteCurrencyButtons(); this.#initializeDragAndDropReordering(); + if (this.#date.value === "") { + const now = new Date(); + const year = String(now.getFullYear()).padStart(4, "0"); + const month = String(now.getMonth() + 1).padStart(2, "0"); + const day = String(now.getDate()).padStart(2, "0"); + this.#date.value = `${year}-${month}-${day}`; + } this.#date.onchange = () => this.#validateDate(); this.#note.onchange = () => this.#validateNote(); this.#element.onsubmit = () => {