Alpha6 barcode non scaffalate e bypass login

This commit is contained in:
2026-06-18 16:13:47 +02:00
parent cc9680c49a
commit 466778ae5f
19 changed files with 1614 additions and 48 deletions

View File

@@ -7,6 +7,7 @@ possible while keeping SQL isolated from the UI.
from __future__ import annotations
from dataclasses import dataclass
from runtime_support import log_exception, log_runtime_event
from typing import Any
from version_info import module_version
@@ -58,8 +59,42 @@ WHERE Pallet = :pallet
ORDER BY Lotto;
"""
SQL_CURRENT_LOCATION_BY_PALLET = """
SELECT TOP (1)
g.BarcodePallet,
g.IDCella,
RTRIM(c.Corsia) AS Corsia,
RTRIM(CAST(c.Colonna AS varchar(32))) AS Colonna,
RTRIM(CAST(c.Fila AS varchar(32))) AS Fila
FROM dbo.XMag_GiacenzaPallet AS g
LEFT JOIN dbo.Celle AS c
ON c.ID = g.IDCella
WHERE g.BarcodePallet = :pallet;
"""
SQL_RESOLVE_PHYSICAL_CELL = """
DECLARE @raw int = TRY_CONVERT(int, :destination);
DECLARE @cell_id int =
CASE
WHEN @raw IS NULL THEN NULL
WHEN @raw >= 9000000 THEN @raw - 9000000
ELSE @raw
END;
SELECT TOP (1)
c.ID AS IDCella,
CAST(9000000 + c.ID AS varchar(8)) AS BarcodeCella,
9000000 + c.ID AS NumeroCella,
CONCAT(RTRIM(c.Corsia), '.', RTRIM(CAST(c.Colonna AS varchar(32))), '.', RTRIM(CAST(c.Fila AS varchar(32)))) AS Ubicazione
FROM dbo.Celle AS c
WHERE c.ID = @cell_id
AND c.ID <> 9999
AND c.DelDataOra IS NULL;
"""
SQL_LEGACY_MOVE = """
SET NOCOUNT ON;
SET XACT_ABORT ON;
DECLARE @RC int = 0;
EXEC dbo.sp_xMagGestioneMagazziniPallet
@@ -105,6 +140,16 @@ class LegacyMoveResult:
numero_cella: int
@dataclass
class DestinationCell:
"""Resolved warehouse cell accepted by the legacy movement procedure."""
barcode_cella: str
numero_cella: int
id_cella: int
ubicazione: str
class BarcodeRepository:
"""Thin async repository used by the lightweight barcode client."""
@@ -132,6 +177,28 @@ class BarcodeRepository:
rows = _rows_to_dicts(res)
return rows[0] if rows else None
async def fetch_current_location_by_pallet(self, pallet: str) -> dict[str, Any] | None:
"""Return the current stock location for a pallet, if it exists in giacenza."""
res = await self.db_client.query_json(SQL_CURRENT_LOCATION_BY_PALLET, {"pallet": str(pallet or "").strip()})
rows = _rows_to_dicts(res)
return rows[0] if rows else None
async def resolve_physical_cell(self, destination: str) -> DestinationCell | None:
"""Accept either an internal cell ID or the scanned legacy cell barcode."""
res = await self.db_client.query_json(SQL_RESOLVE_PHYSICAL_CELL, {"destination": str(destination or "").strip()})
rows = _rows_to_dicts(res)
if not rows:
return None
row = rows[0]
return DestinationCell(
barcode_cella=str(row.get("BarcodeCella") or ""),
numero_cella=int(row.get("NumeroCella") or 0),
id_cella=int(row.get("IDCella") or 0),
ubicazione=str(row.get("Ubicazione") or ""),
)
async def execute_legacy_move(
self,
*,
@@ -148,12 +215,44 @@ class BarcodeRepository:
"barcode_pallet": str(barcode_pallet or "").strip(),
"numero_cella": int(numero_cella),
}
res = await self.db_client.query_json(SQL_LEGACY_MOVE, params, commit=True)
log_runtime_event(
"Barcode WMS",
(
"MOVE START "
f"operator={params['id_operatore']} "
f"cell={params['barcode_cella']} "
f"pallet={params['barcode_pallet']}"
),
)
try:
res = await self.db_client.query_json(SQL_LEGACY_MOVE, params, commit=True)
except Exception as exc:
log_exception(
"Barcode WMS",
exc,
context=(
"execute_legacy_move "
f"operator={params['id_operatore']} "
f"cell={params['barcode_cella']} "
f"pallet={params['barcode_pallet']}"
),
)
raise
rows = _rows_to_dicts(res)
row = rows[0] if rows else {}
return LegacyMoveResult(
result = LegacyMoveResult(
rc=int(row.get("RC") or 0),
barcode_cella=str(row.get("BarcodeCella") or params["barcode_cella"]),
barcode_pallet=str(row.get("BarcodePallet") or params["barcode_pallet"]),
numero_cella=int(row.get("NumeroCella") or params["numero_cella"]),
)
log_runtime_event(
"Barcode WMS",
(
"MOVE OK "
f"rc={result.rc} "
f"cell={result.barcode_cella} "
f"pallet={result.barcode_pallet}"
),
)
return result