refactor(stock): use central erpnext/exceptions.py for stock exceptions

Merge the stock exceptions into the existing app-wide erpnext/exceptions.py (under a
'# stock' section) instead of a separate erpnext/stock/exceptions.py, matching the
established convention. stock_controller still re-exports them for backward
compatibility; services import from erpnext.exceptions.

Verified: ledger snapshots, quality inspection suite, stock_entry batch-expiry stay green.
This commit is contained in:
Nabin Hait
2026-06-05 14:34:27 +05:30
parent 8db05fc4da
commit b82b2c2ebd
5 changed files with 25 additions and 35 deletions

View File

@@ -19,18 +19,18 @@ from erpnext.controllers.sales_and_purchase_return import (
filter_serial_batches,
make_serial_batch_bundle_for_return,
)
from erpnext.setup.doctype.brand.brand import get_brand_defaults
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
from erpnext.stock import get_warehouse_account_map
from erpnext.stock.doctype.item.item import get_item_defaults
# Re-exported for backward compatibility; canonical home is erpnext.stock.exceptions.
from erpnext.stock.exceptions import (
# Re-exported for backward compatibility; canonical home is erpnext.exceptions.
from erpnext.exceptions import (
BatchExpiredError,
QualityInspectionNotSubmittedError,
QualityInspectionRejectedError,
QualityInspectionRequiredError,
)
from erpnext.setup.doctype.brand.brand import get_brand_defaults
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
from erpnext.stock import get_warehouse_account_map
from erpnext.stock.doctype.item.item import get_item_defaults
from erpnext.stock.services.internal_transfer import StockInternalTransferService
from erpnext.stock.stock_ledger import get_items_to_be_repost

View File

@@ -28,3 +28,20 @@ class MandatoryAccountDimensionError(frappe.ValidationError):
class ReportingCurrencyExchangeNotFoundError(frappe.ValidationError):
pass
# stock
class QualityInspectionRequiredError(frappe.ValidationError):
pass
class QualityInspectionRejectedError(frappe.ValidationError):
pass
class QualityInspectionNotSubmittedError(frappe.ValidationError):
pass
class BatchExpiredError(frappe.ValidationError):
pass

View File

@@ -1,27 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
"""Shared exceptions for stock transactions.
Raised by the stock services (serial/batch bundle, quality inspection) and
re-exported from ``stock_controller`` for backward compatibility, so the services
do not have to import back from the controller they were extracted out of.
"""
import frappe
class QualityInspectionRequiredError(frappe.ValidationError):
pass
class QualityInspectionRejectedError(frappe.ValidationError):
pass
class QualityInspectionNotSubmittedError(frappe.ValidationError):
pass
class BatchExpiredError(frappe.ValidationError):
pass

View File

@@ -10,7 +10,7 @@ inspection have a present / submitted / non-rejected Quality Inspection.
import frappe
from frappe import _
from erpnext.stock.exceptions import (
from erpnext.exceptions import (
QualityInspectionNotSubmittedError,
QualityInspectionRejectedError,
QualityInspectionRequiredError,

View File

@@ -102,8 +102,8 @@ class SerialBatchBundleService:
)
def validate_serialized_batch(self):
from erpnext.exceptions import BatchExpiredError
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
from erpnext.stock.exceptions import BatchExpiredError
is_material_issue = False
if self.doc.doctype == "Stock Entry" and self.doc.purpose in ["Material Issue", "Material Transfer"]: