mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-21 10:26:30 +00:00
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:
@@ -7,6 +7,35 @@ const SALES_DOCTYPES = ["Quotation", "Sales Order", "Delivery Note", "Sales Invo
|
|||||||
const PURCHASE_DOCTYPES = ["Purchase Order", "Purchase Receipt", "Purchase Invoice"];
|
const PURCHASE_DOCTYPES = ["Purchase Order", "Purchase Receipt", "Purchase Invoice"];
|
||||||
|
|
||||||
frappe.ui.form.on("Item", {
|
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) {
|
setup: function (frm) {
|
||||||
frm.add_fetch("attribute", "numeric_values", "numeric_values");
|
frm.add_fetch("attribute", "numeric_values", "numeric_values");
|
||||||
frm.add_fetch("attribute", "from_range", "from_range");
|
frm.add_fetch("attribute", "from_range", "from_range");
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ from erpnext.controllers.item_variant import (
|
|||||||
validate_item_variant_attributes,
|
validate_item_variant_attributes,
|
||||||
)
|
)
|
||||||
from erpnext.stock.doctype.item_default.item_default import ItemDefault
|
from erpnext.stock.doctype.item_default.item_default import ItemDefault
|
||||||
|
from erpnext.stock.utils import get_valuation_method
|
||||||
|
|
||||||
|
|
||||||
class DuplicateReorderRows(frappe.ValidationError):
|
class DuplicateReorderRows(frappe.ValidationError):
|
||||||
@@ -153,6 +154,7 @@ class Item(Document):
|
|||||||
def onload(self):
|
def onload(self):
|
||||||
self.set_onload("stock_exists", self.stock_ledger_created())
|
self.set_onload("stock_exists", self.stock_ledger_created())
|
||||||
self.set_onload("asset_naming_series", get_asset_naming_series())
|
self.set_onload("asset_naming_series", get_asset_naming_series())
|
||||||
|
self.set_onload("current_valuation_method", get_valuation_method(self.name))
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
if frappe.db.get_default("item_naming_by") == "Naming Series":
|
if frappe.db.get_default("item_naming_by") == "Naming Series":
|
||||||
|
|||||||
Reference in New Issue
Block a user