From 6529b288c2df5532de9f2397697f637eb8a2fba8 Mon Sep 17 00:00:00 2001 From: Debin Robert <69695920+debinnn@users.noreply.github.com> Date: Tue, 10 Jun 2025 15:20:18 +0530 Subject: [PATCH] feat: confirm with user before resetting posting date (#47667) * feat: confirm with user before resetting posting date * chore: pre-commit * changes made as per review --------- Co-authored-by: ruthra kumar --- .../accounts_settings/accounts_settings.json | 8 ++++++ .../accounts_settings/accounts_settings.py | 1 + erpnext/patches.txt | 1 + erpnext/public/js/controllers/transaction.js | 27 +++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 33d356108d9..fb9491b8ad1 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -19,6 +19,7 @@ "column_break_17", "enable_common_party_accounting", "allow_multi_currency_invoices_against_single_party_account", + "confirm_before_resetting_posting_date", "journals_section", "merge_similar_account_heads", "deferred_accounting_settings_section", @@ -606,6 +607,13 @@ "fieldtype": "Check", "label": "Use New Budget Controller" }, + { + "default": "1", + "description": "If enabled, user will be alerted before resetting posting date to current date in relevant transactions", + "fieldname": "confirm_before_resetting_posting_date", + "fieldtype": "Check", + "label": "Confirm before resetting posting date" + }, { "fieldname": "item_price_settings_section", "fieldtype": "Section Break", diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py index 07bfc44465a..4fdc3eef0b1 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py @@ -37,6 +37,7 @@ class AccountsSettings(Document): book_tax_discount_loss: DF.Check calculate_depr_using_total_days: DF.Check check_supplier_invoice_uniqueness: DF.Check + confirm_before_resetting_posting_date: DF.Check create_pr_in_draft_status: DF.Check credit_controller: DF.Link | None delete_linked_ledger_entries: DF.Check diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 64360334c9c..2a86e8ee537 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -419,3 +419,4 @@ erpnext.patches.v15_0.rename_group_by_to_categorize_by_in_custom_reports erpnext.patches.v15_0.remove_agriculture_roles erpnext.patches.v14_0.update_full_name_in_contract erpnext.patches.v15_0.drop_sle_indexes +execute:frappe.db.set_single_value("Accounts Settings", "confirm_before_resetting_posting_date", 1) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 81dad0a9476..7992678dff2 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -875,6 +875,33 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe async validate() { await this.calculate_taxes_and_totals(false); + await this.confirm_posting_date_change() + } + + async confirm_posting_date_change() { + if (!frappe.meta.has_field(this.frm.doc.doctype, "set_posting_time")) return; + if (this.frm.doc.set_posting_time) return; + if (frappe.datetime.get_today() == this.frm.doc.posting_date) return; + + let is_confirmation_reqd = await frappe.db.get_single_value( + 'Accounts Settings', 'confirm_before_resetting_posting_date' + ) + + if (!is_confirmation_reqd) return; + + return new Promise((resolve, reject) => { + frappe.confirm( + __( + "Posting Date will change to today's date as Edit Posting Date and Time is unchecked. Are you sure want to proceed?" + ), + () => { + this.frm.doc.posting_date = frappe.datetime.get_today(); + this.frm.refresh_field("posting_date"); + resolve(); + }, + () => reject() + ); + }); } update_stock() {