From 29be72fae4dea8e7f5dcced4043d9b186a4c17e4 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Sat, 4 Jul 2026 23:29:32 +0530 Subject: [PATCH] fix: warning message for new item standard cost (#56885) --- .../item_standard_cost/item_standard_cost.js | 29 +++++++++++++++++++ .../item_standard_cost/item_standard_cost.py | 19 ++++++++++++ 2 files changed, 48 insertions(+) diff --git a/erpnext/stock/doctype/item_standard_cost/item_standard_cost.js b/erpnext/stock/doctype/item_standard_cost/item_standard_cost.js index f867de3ab67..1d7267732b0 100644 --- a/erpnext/stock/doctype/item_standard_cost/item_standard_cost.js +++ b/erpnext/stock/doctype/item_standard_cost/item_standard_cost.js @@ -13,4 +13,33 @@ frappe.ui.form.on("Item Standard Cost", { }; }); }, + + refresh(frm) { + frm.trigger("show_backdated_block_warning"); + }, + + item_code(frm) { + frm.trigger("show_backdated_block_warning"); + }, + + effective_date(frm) { + frm.trigger("show_backdated_block_warning"); + }, + + show_backdated_block_warning(frm) { + if (frm.doc.docstatus !== 0 || !frm.doc.item_code || !frm.doc.effective_date) { + frm.set_intro(""); + return; + } + frm.set_intro( + __( + "On submission, stock transactions for Item {0} cannot be posted with a date before {1} — backdated entries will be blocked.", + [ + frappe.utils.escape_html(frm.doc.item_code).bold(), + frappe.datetime.str_to_user(frm.doc.effective_date).bold(), + ] + ), + "yellow" + ); + }, }); diff --git a/erpnext/stock/doctype/item_standard_cost/item_standard_cost.py b/erpnext/stock/doctype/item_standard_cost/item_standard_cost.py index 62fb8e02903..c1a7a35506b 100644 --- a/erpnext/stock/doctype/item_standard_cost/item_standard_cost.py +++ b/erpnext/stock/doctype/item_standard_cost/item_standard_cost.py @@ -33,6 +33,25 @@ class ItemStandardCost(Document): self.validate_item() self.validate_effective_date() self.validate_rate() + self.warn_backdated_transactions_will_be_blocked() + + def warn_backdated_transactions_will_be_blocked(self): + # Heads-up while creating (R2 enforces it later on every stock voucher): once this rate is + # effective, the item's stock transactions cannot be dated before the effective date. + if not self.is_new(): + return + frappe.msgprint( + _( + "Once this Standard Cost is submitted, stock transactions for Item {0} in {1} cannot be posted with a date before the Effective Date {2}. Post any backdated entries before submitting." + ).format( + get_link_to_form("Item", self.item_code), + frappe.bold(self.company), + frappe.bold(frappe.format(self.effective_date, "Date")), + ), + title=_("Backdated Entries Will Be Blocked"), + indicator="orange", + alert=True, + ) def validate_item(self): if not frappe.get_cached_value("Item", self.item_code, "is_stock_item"):