- services/fiscal/: one driver interface (prepare_receipt / prepare_credit_note -> send,
credit_notes flag, status); the dTEC100extra folder bridge moved into txt_file.py as the
first driver, same command files. fiscal_service.py removed, callers moved.
- Refunds: models/refund.py + Alembic 0016 (refunds, refund_items; ordering.refunds for
existing owners/managers). services/refunds.py: today's business day, the cashier's open
shift, partial quantities, items from another shift need ordering.refunds or a manager's
approval (check()/authorize() return the override row). Paid items are never edited.
- POS: GET /api/pos/receipts, GET /api/pos/receipts/{id}, POST /api/pos/orders/{id}/refund
(cash opens the drawer; fiscal "manual" when the driver can't issue credit notes).
- Shift totals subtract refunds and now count discounts; day close and business-day
reports carry refunds.
- Terminal: Receipts mode (ReceiptsView, ReceiptPanel, logic/refunds.js), en/el texts.
- Tests: test_pos_refunds.py (12), terminal unit +1, terminal.mjs +7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
"""The one access decision (APPS_PLATFORM §3.1)."""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any, Optional
|
|
|
|
from core.errors import XeniaError
|
|
from core.modules.registry import all_permissions
|
|
|
|
|
|
@dataclass
|
|
class AccessContext:
|
|
user: Any = None # User row, or the support account (routers.deps.make_support_user); None for device-only calls
|
|
session: Any = None # session id (sid) of the user's login
|
|
device: Any = None # Device row when the call comes from a paired device (D-8)
|
|
override_token: Optional[str] = None # X-Xenia-Override (D-10); consumed by check() when needed
|
|
target: Optional[str] = None # what the request acts on, for the override audit row
|
|
|
|
|
|
def module_of(key: str) -> str:
|
|
try:
|
|
return all_permissions()[key][1]
|
|
except KeyError:
|
|
raise ValueError(f"unknown permission key {key!r}: declare it in a module manifest") from None
|
|
|
|
|
|
def holds(user, key: str) -> bool:
|
|
"""Does the user have the key (ignoring modules)? Superadmin has every key (D-7)."""
|
|
if user is None:
|
|
return False
|
|
if getattr(user, "role", None) == "superadmin":
|
|
return True
|
|
return key in user_keys(user)
|
|
|
|
|
|
def user_keys(user) -> frozenset[str]:
|
|
rows = getattr(user, "permission_rows", None) or []
|
|
return frozenset(r.key for r in rows)
|
|
|
|
|
|
def can(user, key: str, db=None) -> bool:
|
|
"""Full check without raising: module effective AND user holds the key."""
|
|
from core.modules.state import is_effective
|
|
return is_effective(module_of(key), db) and holds(user, key)
|
|
|
|
|
|
def check(ctx: AccessContext, key: str, db=None):
|
|
"""Raise the right XeniaError unless `key` is allowed for this request. Returns the
|
|
AccessOverride row when a manager's approval was used (else None)."""
|
|
from core.modules.state import blocked_error, is_effective
|
|
module = module_of(key)
|
|
if not is_effective(module, db):
|
|
raise blocked_error(module, db)
|
|
if ctx.device is not None:
|
|
from core.access.context import in_scope
|
|
if not in_scope(ctx.device.app_key, key):
|
|
raise XeniaError("device.out_of_scope", app=ctx.device.app_key, key=key)
|
|
if holds(ctx.user, key):
|
|
return
|
|
from core.access.override import consume, is_overridable
|
|
if is_overridable(key):
|
|
if ctx.override_token:
|
|
return consume(db, ctx.override_token, key, ctx.session, ctx.target)
|
|
raise XeniaError("access.override_possible", key=key)
|
|
raise XeniaError("access.denied", key=key)
|