Alpha6 barcode non scaffalate e bypass login
This commit is contained in:
@@ -6,6 +6,7 @@ from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
|
||||
from barcode_repository import BarcodeRepository, LegacyMoveResult
|
||||
from runtime_support import log_exception
|
||||
from version_info import module_version
|
||||
|
||||
__version__ = module_version(__name__)
|
||||
@@ -27,6 +28,8 @@ class BarcodeViewState:
|
||||
expected_pallet: str = ""
|
||||
destination_barcode: str = ""
|
||||
scanned_pallet: str = ""
|
||||
auto_advance_delay_ms: int = 0
|
||||
destination_readonly: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -41,6 +44,8 @@ class BarcodeActionResult:
|
||||
class BarcodeService:
|
||||
"""Faithful, but cleaner, port of the legacy barcode form logic."""
|
||||
|
||||
NON_SCAFFALATA_BARCODE = "9001000"
|
||||
SHIPPED_BARCODE = "9000000"
|
||||
GRAY = "#d9d9d9"
|
||||
RED = "#f4cccc"
|
||||
LIGHT_GREEN = "#d9ead3"
|
||||
@@ -82,7 +87,7 @@ class BarcodeService:
|
||||
return self._state
|
||||
|
||||
def begin_manual_unload(self) -> BarcodeViewState:
|
||||
"""Prepare a direct unload toward the virtual outbound cell 9000000."""
|
||||
"""Prepare a direct unload toward the conventional non-shelved cell."""
|
||||
|
||||
self._current_priority_state = 0
|
||||
self._state = BarcodeViewState(
|
||||
@@ -90,7 +95,8 @@ class BarcodeService:
|
||||
queue_label="Prelievo diretto",
|
||||
status_text="OP Scarico",
|
||||
status_color=self.GRAY,
|
||||
destination_barcode="9000000",
|
||||
destination_barcode=self.NON_SCAFFALATA_BARCODE,
|
||||
destination_readonly=True,
|
||||
)
|
||||
return self._state
|
||||
|
||||
@@ -102,11 +108,12 @@ class BarcodeService:
|
||||
queue_label = "Alta priorita' (F1)" if int(id_stato) == 1 else "Bassa priorita' (F2)"
|
||||
if not row:
|
||||
self._state = BarcodeViewState(
|
||||
mode="priority_high" if int(id_stato) == 1 else "priority_low",
|
||||
mode="manual_unload",
|
||||
queue_label=queue_label,
|
||||
status_text="Pronto.",
|
||||
status_color=self.RED,
|
||||
destination_barcode="9000000",
|
||||
destination_barcode=self.NON_SCAFFALATA_BARCODE,
|
||||
destination_readonly=False,
|
||||
)
|
||||
return BarcodeActionResult(True, self._state)
|
||||
|
||||
@@ -124,7 +131,8 @@ class BarcodeService:
|
||||
document=str(row.get("Documento") or ""),
|
||||
customer=customer,
|
||||
expected_pallet=str(row.get("Pallet") or ""),
|
||||
destination_barcode="9000000",
|
||||
destination_barcode=self.SHIPPED_BARCODE,
|
||||
destination_readonly=True,
|
||||
)
|
||||
return BarcodeActionResult(True, self._state)
|
||||
|
||||
@@ -140,31 +148,80 @@ class BarcodeService:
|
||||
if not destination.isdigit():
|
||||
return BarcodeActionResult(False, self._state, "La destinazione deve essere numerica.")
|
||||
|
||||
if self._state.mode in ("priority_high", "priority_low") and destination == "9000000":
|
||||
expected = str(self._state.expected_pallet or "").strip()
|
||||
if expected and expected != pallet:
|
||||
is_priority_mode = self._state.mode in ("priority_high", "priority_low")
|
||||
expected_before_move = str(self._state.expected_pallet or "").strip()
|
||||
is_picking_unload = bool(is_priority_mode and expected_before_move and destination == self.SHIPPED_BARCODE)
|
||||
is_direct_unload = bool(destination == self.NON_SCAFFALATA_BARCODE and not is_picking_unload)
|
||||
is_direct_load = bool(destination not in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) and not is_picking_unload)
|
||||
|
||||
if is_priority_mode and destination == self.SHIPPED_BARCODE:
|
||||
if expected_before_move and expected_before_move != pallet:
|
||||
self._state.scanned_pallet = pallet
|
||||
self._state.status_text = "Errata lettura: il pallet letto non coincide con quello atteso."
|
||||
self._state.status_color = self.RED
|
||||
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||
|
||||
move = await self.repository.execute_legacy_move(
|
||||
operator_id=self.operator_id,
|
||||
barcode_cella=destination,
|
||||
barcode_pallet=pallet,
|
||||
numero_cella=int(destination),
|
||||
)
|
||||
if move.rc != 0:
|
||||
current_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
||||
picking_before_move = await self.repository.fetch_picking_by_pallet(pallet)
|
||||
if not current_location and not picking_before_move:
|
||||
self._state.scanned_pallet = pallet
|
||||
self._state.status_text = f"Operazione non riuscita (RC={move.rc})."
|
||||
self._state.status_text = "UDC non presente a magazzino."
|
||||
self._state.status_color = self.RED
|
||||
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||
|
||||
self._state = await self._build_post_move_state(
|
||||
target_barcode = destination
|
||||
target_numero_cella = int(destination)
|
||||
target_id_cella = 9999 if destination == self.SHIPPED_BARCODE else (1000 if destination == self.NON_SCAFFALATA_BARCODE else None)
|
||||
target_display = destination
|
||||
if destination not in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE):
|
||||
resolved_cell = await self.repository.resolve_physical_cell(destination)
|
||||
if not resolved_cell:
|
||||
self._state.scanned_pallet = pallet
|
||||
self._state.status_text = f"Cella non valida: {destination}."
|
||||
self._state.status_color = self.RED
|
||||
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||
target_barcode = resolved_cell.barcode_cella
|
||||
target_numero_cella = resolved_cell.numero_cella
|
||||
target_id_cella = resolved_cell.id_cella
|
||||
target_display = resolved_cell.ubicazione or destination
|
||||
|
||||
move = await self.repository.execute_legacy_move(
|
||||
operator_id=self.operator_id,
|
||||
barcode_cella=target_barcode,
|
||||
barcode_pallet=pallet,
|
||||
destination_barcode=destination,
|
||||
last_priority_state=self._current_priority_state,
|
||||
numero_cella=target_numero_cella,
|
||||
)
|
||||
|
||||
final_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
||||
try:
|
||||
final_cell = int((final_location or {}).get("IDCella") or 0)
|
||||
except Exception:
|
||||
final_cell = 0
|
||||
if target_id_cella is not None and final_cell != target_id_cella:
|
||||
self._state.scanned_pallet = pallet
|
||||
self._state.destination_barcode = destination
|
||||
self._state.status_text = "Movimento non confermato: la UDC non risulta nella cella attesa."
|
||||
self._state.status_color = self.RED
|
||||
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||
|
||||
try:
|
||||
self._state = await self._build_post_move_state(
|
||||
barcode_pallet=pallet,
|
||||
destination_barcode=destination,
|
||||
destination_display=target_display,
|
||||
last_priority_state=self._current_priority_state,
|
||||
auto_advance_delay_ms=5000 if (is_direct_unload or is_direct_load) else 1200 if is_picking_unload else 0,
|
||||
)
|
||||
except Exception as exc:
|
||||
log_exception("Barcode WMS", exc, context=f"post move state pallet={pallet} destination={destination}")
|
||||
self._state = BarcodeViewState(
|
||||
mode="confirm",
|
||||
queue_label="Conferma movimento",
|
||||
status_text="Movimento eseguito. Dettagli non aggiornati.",
|
||||
status_color=self.GREEN_YELLOW,
|
||||
destination_barcode=destination,
|
||||
scanned_pallet=pallet,
|
||||
)
|
||||
return BarcodeActionResult(True, self._state, self._state.status_text)
|
||||
|
||||
async def _build_post_move_state(
|
||||
@@ -172,7 +229,9 @@ class BarcodeService:
|
||||
*,
|
||||
barcode_pallet: str,
|
||||
destination_barcode: str,
|
||||
destination_display: str,
|
||||
last_priority_state: int,
|
||||
auto_advance_delay_ms: int,
|
||||
) -> BarcodeViewState:
|
||||
"""Mirror the legacy confirmation flow after one stored-procedure move."""
|
||||
|
||||
@@ -193,6 +252,8 @@ class BarcodeService:
|
||||
customer=customer,
|
||||
expected_pallet=str(picking_row.get("Pallet") or ""),
|
||||
destination_barcode=destination_barcode,
|
||||
auto_advance_delay_ms=auto_advance_delay_ms,
|
||||
destination_readonly=True,
|
||||
)
|
||||
|
||||
trace_row = await self.repository.fetch_trace_by_pallet(barcode_pallet)
|
||||
@@ -205,27 +266,29 @@ class BarcodeService:
|
||||
mode="confirm",
|
||||
queue_label=queue_label,
|
||||
status_text=(
|
||||
"Ok Scarico" if destination_barcode == "9000000" else f"Ok Carico - {destination_barcode}"
|
||||
"Ok Scarico" if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) else f"Ok Carico - {destination_display}"
|
||||
),
|
||||
status_color=self.GREEN_YELLOW,
|
||||
source_location=str(destination_barcode or ""),
|
||||
source_location=str(destination_display or destination_barcode or ""),
|
||||
document=(
|
||||
self.CONVENTIONAL_LOCATION_BY_CELL[9999]
|
||||
if destination_barcode == "9000000" and last_priority_state in (0, 1)
|
||||
self.CONVENTIONAL_LOCATION_BY_CELL[9999 if destination_barcode == self.SHIPPED_BARCODE else 1000]
|
||||
if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) and last_priority_state in (0, 1)
|
||||
else lotto
|
||||
),
|
||||
customer=(
|
||||
lotto
|
||||
if destination_barcode == "9000000" and last_priority_state in (0, 1)
|
||||
if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) and last_priority_state in (0, 1)
|
||||
else prodotto
|
||||
),
|
||||
expected_pallet=(
|
||||
" - ".join(part for part in (prodotto, descrizione) if part)
|
||||
if destination_barcode == "9000000" and last_priority_state in (0, 1)
|
||||
if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) and last_priority_state in (0, 1)
|
||||
else descrizione
|
||||
),
|
||||
destination_barcode=destination_barcode,
|
||||
scanned_pallet=barcode_pallet,
|
||||
auto_advance_delay_ms=auto_advance_delay_ms,
|
||||
destination_readonly=destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE),
|
||||
)
|
||||
|
||||
return BarcodeViewState(
|
||||
|
||||
Reference in New Issue
Block a user