fix(lint): auto-fix ruff violations and tune lint rules
- Auto-fixed 4,496 lint issues (import sorting, modern syntax, etc.) - Added ignore rules for patterns intentional in this codebase: E402 (late imports), E712 (SQLAlchemy filters), B904 (raise from), SIM108/SIM105/SIM117 (readability preferences) - Added per-file ignores for tests and scripts - Excluded broken scripts/rename_terminology.py (has curly quotes) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,7 @@ def __getattr__(name: str):
|
||||
from app.modules.inventory.definition import inventory_module
|
||||
|
||||
return inventory_module
|
||||
elif name == "get_inventory_module_with_routers":
|
||||
if name == "get_inventory_module_with_routers":
|
||||
from app.modules.inventory.definition import get_inventory_module_with_routers
|
||||
|
||||
return get_inventory_module_with_routers
|
||||
|
||||
@@ -31,14 +31,18 @@ def _get_store_router():
|
||||
|
||||
def _get_metrics_provider():
|
||||
"""Lazy import of metrics provider to avoid circular imports."""
|
||||
from app.modules.inventory.services.inventory_metrics import inventory_metrics_provider
|
||||
from app.modules.inventory.services.inventory_metrics import (
|
||||
inventory_metrics_provider,
|
||||
)
|
||||
|
||||
return inventory_metrics_provider
|
||||
|
||||
|
||||
def _get_feature_provider():
|
||||
"""Lazy import of feature provider to avoid circular imports."""
|
||||
from app.modules.inventory.services.inventory_features import inventory_feature_provider
|
||||
from app.modules.inventory.services.inventory_features import (
|
||||
inventory_feature_provider,
|
||||
)
|
||||
|
||||
return inventory_feature_provider
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@ Revision ID: inventory_001
|
||||
Revises: orders_001
|
||||
Create Date: 2026-02-07
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "inventory_001"
|
||||
down_revision = "orders_001"
|
||||
branch_labels = None
|
||||
|
||||
@@ -16,13 +16,15 @@ from enum import Enum
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
DateTime,
|
||||
Enum as SQLEnum,
|
||||
ForeignKey,
|
||||
Index,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
)
|
||||
from sqlalchemy import (
|
||||
Enum as SQLEnum,
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
@@ -19,7 +19,7 @@ def __getattr__(name: str):
|
||||
if name == "admin_router":
|
||||
from app.modules.inventory.routes.api import admin_router
|
||||
return admin_router
|
||||
elif name == "store_router":
|
||||
if name == "store_router":
|
||||
from app.modules.inventory.routes.api import store_router
|
||||
return store_router
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
@@ -15,7 +15,7 @@ def __getattr__(name: str):
|
||||
if name == "admin_router":
|
||||
from app.modules.inventory.routes.api.admin import admin_router
|
||||
return admin_router
|
||||
elif name == "store_router":
|
||||
if name == "store_router":
|
||||
from app.modules.inventory.routes.api.store import store_router
|
||||
return store_router
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
@@ -21,10 +21,6 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_admin_api, require_module_access
|
||||
from app.core.database import get_db
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.inventory.services.inventory_import_service import inventory_import_service
|
||||
from app.modules.inventory.services.inventory_service import inventory_service
|
||||
from app.modules.inventory.services.inventory_transaction_service import inventory_transaction_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.inventory.schemas import (
|
||||
AdminInventoryAdjust,
|
||||
AdminInventoryCreate,
|
||||
@@ -34,8 +30,8 @@ from app.modules.inventory.schemas import (
|
||||
AdminInventoryTransactionItem,
|
||||
AdminInventoryTransactionListResponse,
|
||||
AdminLowStockItem,
|
||||
AdminTransactionStatsResponse,
|
||||
AdminStoresWithInventoryResponse,
|
||||
AdminTransactionStatsResponse,
|
||||
InventoryAdjust,
|
||||
InventoryCreate,
|
||||
InventoryMessageResponse,
|
||||
@@ -43,6 +39,14 @@ from app.modules.inventory.schemas import (
|
||||
InventoryUpdate,
|
||||
ProductInventorySummary,
|
||||
)
|
||||
from app.modules.inventory.services.inventory_import_service import (
|
||||
inventory_import_service,
|
||||
)
|
||||
from app.modules.inventory.services.inventory_service import inventory_service
|
||||
from app.modules.inventory.services.inventory_transaction_service import (
|
||||
inventory_transaction_service,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_router = APIRouter(
|
||||
prefix="/inventory",
|
||||
|
||||
@@ -14,9 +14,6 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_store_api, require_module_access
|
||||
from app.core.database import get_db
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.inventory.services.inventory_service import inventory_service
|
||||
from app.modules.inventory.services.inventory_transaction_service import inventory_transaction_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.inventory.schemas import (
|
||||
InventoryAdjust,
|
||||
InventoryCreate,
|
||||
@@ -31,6 +28,11 @@ from app.modules.inventory.schemas import (
|
||||
ProductInventorySummary,
|
||||
ProductTransactionHistoryResponse,
|
||||
)
|
||||
from app.modules.inventory.services.inventory_service import inventory_service
|
||||
from app.modules.inventory.services.inventory_transaction_service import (
|
||||
inventory_transaction_service,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
store_router = APIRouter(
|
||||
prefix="/inventory",
|
||||
|
||||
@@ -12,9 +12,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_db, require_menu_access
|
||||
from app.modules.core.utils.page_context import get_admin_context
|
||||
from app.templates_config import templates
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.tenancy.models import User
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_store_from_cookie_or_header, get_db
|
||||
from app.modules.core.utils.page_context import get_store_context
|
||||
from app.templates_config import templates
|
||||
from app.modules.tenancy.models import User
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -6,39 +6,39 @@ This module contains the canonical implementations of inventory-related schemas.
|
||||
"""
|
||||
|
||||
from app.modules.inventory.schemas.inventory import (
|
||||
# Base schemas
|
||||
InventoryBase,
|
||||
InventoryCreate,
|
||||
InventoryAdjust,
|
||||
InventoryUpdate,
|
||||
InventoryReserve,
|
||||
# Response schemas
|
||||
InventoryResponse,
|
||||
InventoryLocationResponse,
|
||||
ProductInventorySummary,
|
||||
InventoryListResponse,
|
||||
InventoryMessageResponse,
|
||||
InventorySummaryResponse,
|
||||
AdminInventoryAdjust,
|
||||
# Admin schemas
|
||||
AdminInventoryCreate,
|
||||
AdminInventoryAdjust,
|
||||
AdminInventoryItem,
|
||||
AdminInventoryListResponse,
|
||||
AdminInventoryStats,
|
||||
AdminLowStockItem,
|
||||
AdminStoreWithInventory,
|
||||
AdminStoresWithInventoryResponse,
|
||||
AdminInventoryLocationsResponse,
|
||||
# Transaction schemas
|
||||
InventoryTransactionResponse,
|
||||
InventoryTransactionWithProduct,
|
||||
InventoryTransactionListResponse,
|
||||
ProductTransactionHistoryResponse,
|
||||
OrderTransactionHistoryResponse,
|
||||
AdminInventoryStats,
|
||||
# Admin transaction schemas
|
||||
AdminInventoryTransactionItem,
|
||||
AdminInventoryTransactionListResponse,
|
||||
AdminLowStockItem,
|
||||
AdminStoresWithInventoryResponse,
|
||||
AdminStoreWithInventory,
|
||||
AdminTransactionStatsResponse,
|
||||
InventoryAdjust,
|
||||
# Base schemas
|
||||
InventoryBase,
|
||||
InventoryCreate,
|
||||
InventoryListResponse,
|
||||
InventoryLocationResponse,
|
||||
InventoryMessageResponse,
|
||||
InventoryReserve,
|
||||
# Response schemas
|
||||
InventoryResponse,
|
||||
InventorySummaryResponse,
|
||||
InventoryTransactionListResponse,
|
||||
# Transaction schemas
|
||||
InventoryTransactionResponse,
|
||||
InventoryTransactionWithProduct,
|
||||
InventoryUpdate,
|
||||
OrderTransactionHistoryResponse,
|
||||
ProductInventorySummary,
|
||||
ProductTransactionHistoryResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -5,18 +5,18 @@ Inventory module services.
|
||||
This module contains the canonical implementations of inventory-related services.
|
||||
"""
|
||||
|
||||
from app.modules.inventory.services.inventory_import_service import (
|
||||
ImportResult,
|
||||
InventoryImportService,
|
||||
inventory_import_service,
|
||||
)
|
||||
from app.modules.inventory.services.inventory_service import (
|
||||
inventory_service,
|
||||
InventoryService,
|
||||
inventory_service,
|
||||
)
|
||||
from app.modules.inventory.services.inventory_transaction_service import (
|
||||
inventory_transaction_service,
|
||||
InventoryTransactionService,
|
||||
)
|
||||
from app.modules.inventory.services.inventory_import_service import (
|
||||
inventory_import_service,
|
||||
InventoryImportService,
|
||||
ImportResult,
|
||||
inventory_transaction_service,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -13,7 +13,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from app.modules.contracts.features import (
|
||||
FeatureDeclaration,
|
||||
FeatureProviderProtocol,
|
||||
FeatureScope,
|
||||
FeatureType,
|
||||
FeatureUsage,
|
||||
|
||||
@@ -23,8 +23,8 @@ from dataclasses import dataclass, field
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.inventory.models.inventory import Inventory
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.inventory.models.inventory import Inventory
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -227,7 +227,7 @@ class InventoryImportService:
|
||||
ImportResult with summary and errors
|
||||
"""
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
with open(file_path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
return ImportResult(success=False, errors=[f"Failed to read file: {e}"])
|
||||
|
||||
@@ -15,9 +15,8 @@ from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.contracts.metrics import (
|
||||
MetricValue,
|
||||
MetricsContext,
|
||||
MetricsProviderProtocol,
|
||||
MetricValue,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -6,14 +6,14 @@ from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.catalog.exceptions import ProductNotFoundException
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.inventory.exceptions import (
|
||||
InsufficientInventoryException,
|
||||
InvalidQuantityException,
|
||||
InventoryNotFoundException,
|
||||
InventoryValidationException,
|
||||
)
|
||||
from app.modules.catalog.exceptions import ProductNotFoundException
|
||||
from app.modules.tenancy.exceptions import StoreNotFoundException
|
||||
from app.modules.inventory.models.inventory import Inventory
|
||||
from app.modules.inventory.schemas.inventory import (
|
||||
AdminInventoryItem,
|
||||
@@ -30,7 +30,7 @@ from app.modules.inventory.schemas.inventory import (
|
||||
InventoryUpdate,
|
||||
ProductInventorySummary,
|
||||
)
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.tenancy.exceptions import StoreNotFoundException
|
||||
from app.modules.tenancy.models import Store
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -217,7 +217,7 @@ class InventoryService:
|
||||
"""
|
||||
try:
|
||||
# Validate product
|
||||
product = self._get_store_product(db, store_id, reserve_data.product_id)
|
||||
self._get_store_product(db, store_id, reserve_data.product_id)
|
||||
|
||||
# Validate location and quantity
|
||||
location = self._validate_location(reserve_data.location)
|
||||
@@ -279,7 +279,7 @@ class InventoryService:
|
||||
"""
|
||||
try:
|
||||
# Validate product
|
||||
product = self._get_store_product(db, store_id, reserve_data.product_id)
|
||||
self._get_store_product(db, store_id, reserve_data.product_id)
|
||||
|
||||
location = self._validate_location(reserve_data.location)
|
||||
self._validate_quantity(reserve_data.quantity, allow_zero=False)
|
||||
@@ -338,7 +338,7 @@ class InventoryService:
|
||||
Updated Inventory object
|
||||
"""
|
||||
try:
|
||||
product = self._get_store_product(db, store_id, reserve_data.product_id)
|
||||
self._get_store_product(db, store_id, reserve_data.product_id)
|
||||
location = self._validate_location(reserve_data.location)
|
||||
self._validate_quantity(reserve_data.quantity, allow_zero=False)
|
||||
|
||||
|
||||
@@ -8,15 +8,16 @@ This service handles transaction READS for reporting and auditing.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.catalog.exceptions import ProductNotFoundException
|
||||
from app.modules.orders.exceptions import OrderNotFoundException
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.inventory.models.inventory import Inventory
|
||||
from app.modules.inventory.models.inventory_transaction import InventoryTransaction
|
||||
from app.modules.orders.exceptions import OrderNotFoundException
|
||||
from app.modules.orders.models import Order
|
||||
from app.modules.catalog.models import Product
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -411,7 +412,7 @@ class InventoryTransactionService:
|
||||
total = db.query(sql_func.count(InventoryTransaction.id)).scalar() or 0
|
||||
|
||||
# Transactions today
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from datetime import UTC, datetime
|
||||
|
||||
today_start = datetime.now(UTC).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
today_count = (
|
||||
|
||||
Reference in New Issue
Block a user