feat: company wise valuation method

This commit is contained in:
Mihir Kandoi
2025-11-13 11:59:58 +05:30
parent 5dcb766b9f
commit 316b6d6867
12 changed files with 74 additions and 22 deletions

View File

@@ -117,6 +117,7 @@
"enable_item_wise_inventory_account",
"enable_provisional_accounting_for_non_stock_items",
"default_inventory_account",
"valuation_method",
"column_break_32",
"stock_adjustment_account",
"stock_received_but_not_billed",
@@ -890,6 +891,14 @@
"fieldtype": "Check",
"label": "Enable Item-wise Inventory Account"
},
{
"default": "FIFO",
"fieldname": "valuation_method",
"fieldtype": "Select",
"label": "Default Stock Valuation Method",
"options": "FIFO\nMoving Average\nLIFO",
"reqd": 1
},
{
"fieldname": "default_wip_warehouse",
"fieldtype": "Link",

View File

@@ -116,6 +116,7 @@ class Company(NestedSet):
transactions_annual_history: DF.Code | None
unrealized_exchange_gain_loss_account: DF.Link | None
unrealized_profit_loss_account: DF.Link | None
valuation_method: DF.Literal["FIFO", "Moving Average", "LIFO"]
website: DF.Data | None
write_off_account: DF.Link | None
# end: auto-generated types
@@ -166,6 +167,32 @@ class Company(NestedSet):
self.validate_parent_company()
self.set_reporting_currency()
self.validate_inventory_account_settings()
self.cant_change_valuation_method()
def cant_change_valuation_method(self):
doc_before_save = self.get_doc_before_save()
if not doc_before_save:
return
previous_valuation_method = doc_before_save.get("valuation_method")
if previous_valuation_method and previous_valuation_method != self.valuation_method:
# check if there are any stock ledger entries against items
# which does not have it's own valuation method
sle = frappe.db.sql(
"""select name from `tabStock Ledger Entry` sle
where exists(select name from tabItem
where name=sle.item_code and (valuation_method is null or valuation_method='')) and sle.company=%s limit 1
""",
self.name,
)
if sle:
frappe.throw(
_(
"Can't change the valuation method, as there are transactions against some items which do not have its own valuation method"
)
)
def validate_inventory_account_settings(self):
doc_before_save = self.get_doc_before_save()