fix: warning message before changing the valuation method (backport #47340) (#47341)

fix: warning message before changing the valuation method (#47340)

(cherry picked from commit ffdc4347e8)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2025-04-30 12:54:15 +05:30
committed by GitHub
parent 0c5c34409e
commit b13e0a6b9f
2 changed files with 31 additions and 0 deletions

View File

@@ -7,6 +7,35 @@ const SALES_DOCTYPES = ["Quotation", "Sales Order", "Delivery Note", "Sales Invo
const PURCHASE_DOCTYPES = ["Purchase Order", "Purchase Receipt", "Purchase Invoice"];
frappe.ui.form.on("Item", {
valuation_method(frm) {
if (!frm.is_new() && frm.doc.valuation_method === "Moving Average") {
let stock_exists = frm.doc.__onload && frm.doc.__onload.stock_exists ? 1 : 0;
let current_valuation_method = frm.doc.__onload.current_valuation_method;
if (stock_exists && current_valuation_method !== frm.doc.valuation_method) {
let msg = __(
"Changing the valuation method to Moving Average will affect new transactions. If backdated entries are added, earlier FIFO-based entries will be reposted, which may change closing balances."
);
msg += "<br>";
msg += __(
"Also you can't switch back to FIFO after setting the valuation method to Moving Average for this item."
);
msg += "<br>";
msg += __("Do you want to change valuation method?");
frappe.confirm(
msg,
() => {
frm.set_value("valuation_method", "Moving Average");
},
() => {
frm.set_value("valuation_method", current_valuation_method);
}
);
}
}
},
setup: function (frm) {
frm.add_fetch("attribute", "numeric_values", "numeric_values");
frm.add_fetch("attribute", "from_range", "from_range");

View File

@@ -31,6 +31,7 @@ from erpnext.controllers.item_variant import (
)
from erpnext.setup.doctype.item_group.item_group import invalidate_cache_for
from erpnext.stock.doctype.item_default.item_default import ItemDefault
from erpnext.stock.utils import get_valuation_method
class DuplicateReorderRows(frappe.ValidationError):
@@ -53,6 +54,7 @@ class Item(Document):
def onload(self):
self.set_onload("stock_exists", self.stock_ledger_created())
self.set_onload("asset_naming_series", get_asset_naming_series())
self.set_onload("current_valuation_method", get_valuation_method(self.name))
def autoname(self):
if frappe.db.get_default("item_naming_by") == "Naming Series":