fix: allow recalculate valuation rate only for purchase receipts, update stock invoices and non-transfer stock entries

(cherry picked from commit 712806f9ae)
This commit is contained in:
Mihir Kandoi
2026-10-24 20:58:54 +05:30
parent bb9923f6fa
commit b96168a4aa
2 changed files with 27 additions and 2 deletions
@@ -241,7 +241,7 @@
},
{
"default": "0",
"description": "Only works for Purchase Receipt, Purchase Invoice and Stock Entry",
"description": "Only works for Purchase Receipt, Purchase Invoice with Update Stock and Stock Entry that is not a material transfer",
"fieldname": "recalculate_valuation_rate",
"fieldtype": "Check",
"label": "Recalculate Valuation Rate",
@@ -252,7 +252,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2026-06-16 17:30:42.715321",
"modified": "2026-10-24 12:00:00.000000",
"modified_by": "Administrator",
"module": "Stock",
"name": "Repost Item Valuation",
@@ -18,6 +18,7 @@ from erpnext.projects.doctype.project.project import update_consumed_material_co
from erpnext.stock.stock_ledger import (
get_affected_transactions,
get_items_to_be_repost,
is_transfer_stock_entry,
repost_future_sle,
)
from erpnext.utilities import clear_logs_with_references
@@ -78,6 +79,7 @@ class RepostItemValuation(Document):
self.set_default_posting_time()
self.set_company()
self.validate_update_stock()
self.validate_recalculate_valuation_rate()
self.validate_period_closing_voucher()
self.set_status(write=False)
self.reset_field_values()
@@ -101,6 +103,29 @@ class RepostItemValuation(Document):
).format(get_link_to_form(self.voucher_type, self.voucher_no))
frappe.throw(msg)
def validate_recalculate_valuation_rate(self):
if self.recalculate_valuation_rate and not self.can_recalculate_valuation_rate():
frappe.throw(
_(
"Recalculate Valuation Rate is only allowed for a Purchase Receipt, a Purchase Invoice with Update Stock or a Stock Entry that is not a material transfer"
)
)
def can_recalculate_valuation_rate(self):
if self.based_on != "Transaction":
return False
if self.voucher_type == "Purchase Receipt":
return True
if self.voucher_type == "Purchase Invoice":
return bool(frappe.db.get_value("Purchase Invoice", self.voucher_no, "update_stock"))
if self.voucher_type == "Stock Entry":
return not is_transfer_stock_entry(self.voucher_no)
return False
def validate_recreate_stock_ledgers(self):
if not self.recreate_stock_ledgers:
return