feat: enable item wise inventory account

This commit is contained in:
Rohit Waghchaure
2025-10-22 11:20:51 +05:30
parent 5b6979c700
commit 74192547ce
19 changed files with 831 additions and 98 deletions

View File

@@ -114,10 +114,11 @@
"stock_tab",
"auto_accounting_for_stock_settings",
"enable_perpetual_inventory",
"enable_item_wise_inventory_account",
"enable_provisional_accounting_for_non_stock_items",
"default_inventory_account",
"stock_adjustment_account",
"column_break_32",
"stock_adjustment_account",
"stock_received_but_not_billed",
"default_provisional_account",
"default_in_transit_warehouse",
@@ -877,6 +878,13 @@
"fieldtype": "Link",
"label": "Service Expense Account",
"options": "Account"
},
{
"default": "0",
"description": "If enabled, the system will use the inventory account set in the Item Master or Item Group or Brand. Otherwise, it will use the inventory account set in the Warehouse.",
"fieldname": "enable_item_wise_inventory_account",
"fieldtype": "Check",
"label": "Enable Item-wise Inventory Account"
}
],
"icon": "fa fa-building",
@@ -884,7 +892,7 @@
"image_field": "company_logo",
"is_tree": 1,
"links": [],
"modified": "2025-10-10 15:12:37.941251",
"modified": "2025-10-23 13:15:52.411984",
"modified_by": "Administrator",
"module": "Setup",
"name": "Company",

View File

@@ -6,7 +6,7 @@ import json
import frappe
import frappe.defaults
from frappe import _
from frappe import _, bold
from frappe.cache_manager import clear_defaults_cache
from frappe.contacts.address_and_contact import load_address_and_contact
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
@@ -73,6 +73,7 @@ class Company(NestedSet):
disposal_account: DF.Link | None
domain: DF.Data | None
email: DF.Data | None
enable_item_wise_inventory_account: DF.Check
enable_perpetual_inventory: DF.Check
enable_provisional_accounting_for_non_stock_items: DF.Check
exception_budget_approver_role: DF.Link | None
@@ -158,6 +159,24 @@ class Company(NestedSet):
self.set_chart_of_accounts()
self.validate_parent_company()
self.set_reporting_currency()
self.validate_inventory_account_settings()
def validate_inventory_account_settings(self):
doc_before_save = self.get_doc_before_save()
if not doc_before_save:
return
if (
doc_before_save.enable_item_wise_inventory_account != self.enable_item_wise_inventory_account
and frappe.db.get_value("Stock Ledger Entry", {"is_cancelled": 0, "company": self.name}, "name")
and doc_before_save.enable_perpetual_inventory
):
frappe.throw(
_(
"Cannot enable Item-wise Inventory Account, as there are existing Stock Ledger Entries for the company {0} with Warehouse-wise Inventory Account. Please cancel the stock transactions first and try again."
).format(bold(self.name)),
title=_("Cannot Change Inventory Account Setting"),
)
def validate_abbr(self):
if not self.abbr:
@@ -455,6 +474,22 @@ class Company(NestedSet):
_("Set default inventory account for perpetual inventory"), alert=True, indicator="orange"
)
doc_before_save = self.get_doc_before_save()
if not doc_before_save:
return
if (
doc_before_save.enable_perpetual_inventory
and not self.enable_perpetual_inventory
and doc_before_save.enable_item_wise_inventory_account != self.enable_item_wise_inventory_account
):
if frappe.db.get_value("Stock Ledger Entry", {"is_cancelled": 0, "company": self.name}, "name"):
frappe.throw(
_(
"Cannot disable perpetual inventory, as there are existing Stock Ledger Entries for the company {0}. Please cancel the stock transactions first and try again."
).format(bold(self.name))
)
def validate_provisional_account_for_non_stock_items(self):
if not self.get("__islocal"):
if (