fix: warning message for new item standard cost (#56885)

This commit is contained in:
rohitwaghchaure
2026-07-04 23:29:32 +05:30
committed by GitHub
parent 486a1c78b0
commit 29be72fae4
2 changed files with 48 additions and 0 deletions

View File

@@ -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"
);
},
});

View File

@@ -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"):