Compare commits

...

2 Commits

Author SHA1 Message Date
5dd7139b19 Differenzia scarico layout spedita e non scaffalata 2026-07-04 09:27:52 +02:00
d4cfe0be54 Aggiungi salto UDC nel picking barcode 2026-07-04 09:13:25 +02:00
9 changed files with 322 additions and 53 deletions

View File

@@ -0,0 +1,43 @@
SET XACT_ABORT ON;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.py_BarcodePickingListSkip', N'U') IS NULL
BEGIN
CREATE TABLE dbo.py_BarcodePickingListSkip (
ID int IDENTITY(1,1) NOT NULL CONSTRAINT PK_py_BarcodePickingListSkip PRIMARY KEY,
Documento varchar(50) NOT NULL,
Pallet varchar(50) NOT NULL,
IDStato int NOT NULL,
IDOperatore int NOT NULL,
DataOra datetime2(0) NOT NULL CONSTRAINT DF_py_BarcodePickingListSkip_DataOra DEFAULT SYSDATETIME(),
Motivo nvarchar(200) NULL,
Risolto bit NOT NULL CONSTRAINT DF_py_BarcodePickingListSkip_Risolto DEFAULT 0,
RisoltoDa int NULL,
RisoltoDataOra datetime2(0) NULL
);
END;
IF NOT EXISTS (
SELECT 1
FROM sys.indexes
WHERE name = N'UX_py_BarcodePickingListSkip_Open'
AND object_id = OBJECT_ID(N'dbo.py_BarcodePickingListSkip', N'U')
)
BEGIN
CREATE UNIQUE INDEX UX_py_BarcodePickingListSkip_Open
ON dbo.py_BarcodePickingListSkip (Documento, Pallet, IDStato)
WHERE Risolto = 0;
END;
IF NOT EXISTS (
SELECT 1
FROM sys.indexes
WHERE name = N'IX_py_BarcodePickingListSkip_Queue'
AND object_id = OBJECT_ID(N'dbo.py_BarcodePickingListSkip', N'U')
)
BEGIN
CREATE INDEX IX_py_BarcodePickingListSkip_Queue
ON dbo.py_BarcodePickingListSkip (IDStato, Documento, Pallet, Risolto);
END;
COMMIT TRANSACTION;

View File

@@ -388,6 +388,10 @@ class BarcodeClientApp:
self.btn_submit.configure(text="[F3] Pausa PL")
else:
self.btn_submit.configure(text="[F3] Carica")
if state.mode in ("priority_high", "priority_low"):
self.btn_unload.configure(text="[F4] Salta UDC")
else:
self.btn_unload.configure(text="[F4] Scarica")
queue_buttons_state = "disabled" if str(state.queue_label or "") == "Pausa PL" else "normal"
self.btn_f1.configure(state=queue_buttons_state)
self.btn_f2.configure(state=queue_buttons_state)
@@ -502,9 +506,8 @@ class BarcodeClientApp:
pallet = str(self.scanned_var.get() or "").strip()
destination = str(self.destination_var.get() or "").strip()
mode = getattr(self.service.state, "mode", "")
if pallet and mode in ("priority_high", "priority_low") and destination == self.SHIPPED_BARCODE:
# Legacy barcode flow: F4/Scarica confirms the prepared unload destination.
self._submit()
if mode in ("priority_high", "priority_low"):
self._skip_current_picking_pallet()
return
if pallet:
self._submit_unload_with_source_check()
@@ -539,6 +542,12 @@ class BarcodeClientApp:
busy_message="In esecuzione...",
)
def _skip_current_picking_pallet(self) -> None:
self._run_async(
lambda: self.service.skip_current_picking_pallet(),
busy_message="Registro salto UDC...",
)
def _run_async(self, coro_factory: Callable[[], object], busy_message: str) -> None:
if self._pending is not None and not self._pending.done():
return

View File

@@ -26,9 +26,17 @@ SELECT TOP (1)
Ubicazione,
Ordinamento,
IDStato
FROM dbo.py_XMag_ViewPackingList
FROM dbo.py_XMag_ViewPackingList AS pl
WHERE Ordinamento > 0
AND IDStato = :id_stato
AND NOT EXISTS (
SELECT 1
FROM dbo.py_BarcodePickingListSkip AS s
WHERE s.Documento = CAST(pl.Documento AS varchar(50))
AND s.Pallet = CAST(pl.Pallet AS varchar(50))
AND s.IDStato = pl.IDStato
AND s.Risolto = 0
)
ORDER BY Ordinamento;
"""
@@ -136,6 +144,44 @@ SELECT
:numero_cella AS NumeroCella;
"""
SQL_SKIP_PICKING_PALLET = """
SET NOCOUNT ON;
IF NOT EXISTS (
SELECT 1
FROM dbo.py_BarcodePickingListSkip
WHERE Documento = :documento
AND Pallet = :pallet
AND IDStato = :id_stato
AND Risolto = 0
)
BEGIN
INSERT INTO dbo.py_BarcodePickingListSkip (
Documento,
Pallet,
IDStato,
IDOperatore,
DataOra,
Motivo,
Risolto
)
VALUES (
:documento,
:pallet,
:id_stato,
:id_operatore,
SYSDATETIME(),
:motivo,
0
);
END;
SELECT
:documento AS Documento,
:pallet AS Pallet,
:id_stato AS IDStato;
"""
def _rows_to_dicts(res: dict[str, Any] | None) -> list[dict[str, Any]]:
"""Convert ``query_json`` payloads to a list of row dictionaries."""
@@ -219,6 +265,45 @@ class BarcodeRepository:
res = await self.db_client.query_json(SQL_OPEN_PALLETS_BY_CELL, {"id_cella": int(id_cella)})
return _rows_to_dicts(res)
async def skip_picking_pallet(
self,
*,
documento: str,
pallet: str,
id_stato: int,
operator_id: int,
motivo: str = "UDC non trovata dal magazziniere",
) -> None:
"""Persist one skipped picking-list pallet so the queue can advance."""
params = {
"documento": str(documento or "").strip(),
"pallet": str(pallet or "").strip(),
"id_stato": int(id_stato),
"id_operatore": int(operator_id),
"motivo": str(motivo or "").strip(),
}
log_runtime_event(
"Barcode WMS",
(
"PICKING SKIP START "
f"documento={params['documento']} "
f"pallet={params['pallet']} "
f"id_stato={params['id_stato']} "
f"operator={params['id_operatore']}"
),
)
await self.db_client.query_json(SQL_SKIP_PICKING_PALLET, params, commit=True)
log_runtime_event(
"Barcode WMS",
(
"PICKING SKIP OK "
f"documento={params['documento']} "
f"pallet={params['pallet']} "
f"id_stato={params['id_stato']}"
),
)
async def resolve_physical_cell(self, destination: str) -> DestinationCell | None:
"""Accept either an internal cell ID or the scanned legacy cell barcode."""

View File

@@ -115,6 +115,44 @@ class BarcodeService:
)
return self._state
async def skip_current_picking_pallet(self) -> BarcodeActionResult:
"""Mark the currently proposed picking pallet as skipped and advance."""
mode = str(self._state.mode or "")
if mode not in ("priority_high", "priority_low"):
return BarcodeActionResult(False, self._state, "Nessuna picking list attiva.")
id_stato = 1 if mode == "priority_high" else 0
documento = str(self._state.document or "").strip()
pallet = str(self._state.expected_pallet or "").strip()
if not documento or not pallet:
self._state.status_text = "Nessuna UDC da saltare."
self._state.status_color = self.RED
return BarcodeActionResult(False, self._state, self._state.status_text)
await self.repository.skip_picking_pallet(
documento=documento,
pallet=pallet,
id_stato=id_stato,
operator_id=self.operator_id,
)
queue_label = "Alta priorita' (F1)" if id_stato == 1 else "Bassa priorita' (F2)"
self._current_priority_state = id_stato
self._state = BarcodeViewState(
mode="confirm",
queue_label=queue_label,
status_text="UDC saltata - chiusura manuale richiesta",
status_color=self.RED,
source_location=self._state.source_location,
document=documento,
customer="UDC non trovata",
expected_pallet=pallet,
destination_barcode=self.SHIPPED_BARCODE,
auto_advance_delay_ms=1500,
destination_readonly=True,
)
return BarcodeActionResult(True, self._state, self._state.status_text)
async def start_priority_queue(self, id_stato: int) -> BarcodeActionResult:
"""Load the next item of the selected legacy priority queue."""

View File

@@ -681,27 +681,7 @@ class LayoutWindow(ctk.CTkToplevel):
if stato <= 0:
self._toast("La cella selezionata non contiene alcuna UDC da scaricare.")
return
if stato >= 2:
self._open_scarico_dialog(r, c)
return
barcode = str(self.udc1[r][c] or "").strip()
if not barcode:
self._toast("UDC non disponibile per lo scarico.")
return
if not messagebox.askyesno(
"Scarico",
f"Scaricare l'UDC {barcode} da {self._cell_label(r, c)}?",
parent=self,
):
return
self._run_pallet_move(
barcode_pallet=barcode,
target_idcella=9999,
target_barcode_cella="9000000",
success_message=f"Scarico completato per {barcode}.",
busy_message=f"Scarico {barcode}...",
)
@_log_call()
def _run_pallet_move(

View File

@@ -76,6 +76,12 @@ _MODULE_LOG_LEVEL = "DEBUG" if SCARICO_LOG_MODE.upper() == "DEBUG" else "INFO"
_MODULE_LOGGER = logger.bind(warehouse_module=MODULE_LOG_NAME)
_MODULE_LOGGING_CONFIGURED = False
DEFAULT_SCARICO_USER = "warehouse_ui"
SHIPPED_IDCELLA = 9999
SHIPPED_BARCODE = "9000000"
SHIPPED_LABEL = "7G.1.1"
NON_SCAFF_IDCELLA = 1000
NON_SCAFF_BARCODE = "9001000"
NON_SCAFF_LABEL = "5E1.1"
def _session_login(session: UserSession | None, fallback: str | None = None) -> str:
@@ -231,6 +237,7 @@ SELECT
cp.BarcodePallet AS UDC,
lm.ID AS SourceID,
lm.DataMagazzino AS LastEventAt,
ISNULL(la.IDCella, :idcella) AS CurrentIDCella,
CASE
WHEN shipped.BarcodePallet IS NOT NULL THEN CAST(1 AS int)
ELSE CAST(0 AS int)
@@ -413,6 +420,7 @@ class ScaricoRow:
udc: str
source_id: int | None
last_event_at: str
current_idcella: int
diagnostic_note: str
selected: tk.BooleanVar
@@ -546,19 +554,27 @@ class ScaricoDialog(ctk.CTkToplevel):
actions.grid_columnconfigure(0, weight=1)
ctk.CTkButton(
actions,
text=loc_text("scarico.button.submit", catalog=self._locale_catalog, default="Scarica"),
command=self._on_scarica,
text=loc_text("scarico.button.shipped", catalog=self._locale_catalog, default="Scarico come spedita"),
command=self._on_scarica_spedita,
font=theme_font(self._theme, "button_font", ("Segoe UI", 10, "bold")),
).grid(
row=0, column=1, padx=(8, 0), pady=8
)
ctk.CTkButton(
actions,
text=loc_text("scarico.button.non_shelved", catalog=self._locale_catalog, default="Scarico come non scaff."),
command=self._on_scarica_non_scaff,
font=theme_font(self._theme, "button_font", ("Segoe UI", 10, "bold")),
).grid(
row=0, column=2, padx=(8, 0), pady=8
)
ctk.CTkButton(
actions,
text=loc_text("scarico.button.close", catalog=self._locale_catalog, default="Chiudi"),
command=self._close,
font=theme_font(self._theme, "button_font", ("Segoe UI", 10, "bold")),
).grid(
row=0, column=2, padx=(8, 8), pady=8
row=0, column=3, padx=(8, 8), pady=8
)
def _render_rows(self):
@@ -617,7 +633,7 @@ class ScaricoDialog(ctk.CTkToplevel):
rows = res.get("rows", []) if isinstance(res, dict) else []
_log_dataset("scarico_load_rows", rows)
self.rows = []
for udc, source_id, last_event_at, is_shipped, is_moved in rows:
for udc, source_id, last_event_at, current_idcella, is_shipped, is_moved in rows:
if isinstance(last_event_at, datetime):
last_event = last_event_at.strftime("%d/%m/%Y %H:%M:%S")
else:
@@ -627,6 +643,7 @@ class ScaricoDialog(ctk.CTkToplevel):
udc=str(udc or ""),
source_id=int(source_id) if source_id is not None else None,
last_event_at=last_event,
current_idcella=int(current_idcella or 0),
diagnostic_note=_build_diagnostic_note(is_shipped, is_moved),
selected=tk.BooleanVar(value=False),
)
@@ -653,8 +670,9 @@ class ScaricoDialog(ctk.CTkToplevel):
)
@_log_call()
def _on_scarica(self):
"""Unload the UDCs selected by the user from the current cell."""
def _selected_rows_or_warn(self) -> list[ScaricoRow] | None:
"""Return selected rows or show the standard selection warning."""
selected = [row for row in self.rows if row.selected.get()]
if not selected:
messagebox.showinfo(
@@ -662,23 +680,88 @@ class ScaricoDialog(ctk.CTkToplevel):
loc_text("scarico.msg.select_one", catalog=self._locale_catalog, default="Seleziona almeno una UDC da scaricare."),
parent=self,
)
return selected
@_log_call()
def _on_scarica_spedita(self):
"""Unload selected UDCs to the shipped conventional location."""
self._scarica_selected_to_target(
target_idcella=SHIPPED_IDCELLA,
target_barcode_cella=SHIPPED_BARCODE,
target_label=SHIPPED_LABEL,
title="Scarico come spedita",
confirm_text="Scaricare come spedite {count} UDC da {ubicazione}?",
busy_message="Scarico UDC come spedite...",
block_shipped_for_non_scaff=False,
)
@_log_call()
def _on_scarica_non_scaff(self):
"""Unload selected UDCs to the non-shelved conventional location."""
self._scarica_selected_to_target(
target_idcella=NON_SCAFF_IDCELLA,
target_barcode_cella=NON_SCAFF_BARCODE,
target_label=NON_SCAFF_LABEL,
title="Scarico come non scaff.",
confirm_text="Scaricare come non scaffalate {count} UDC da {ubicazione}?",
busy_message="Scarico UDC come non scaffalate...",
block_shipped_for_non_scaff=True,
)
def _scarica_selected_to_target(
self,
*,
target_idcella: int,
target_barcode_cella: str,
target_label: str,
title: str,
confirm_text: str,
busy_message: str,
block_shipped_for_non_scaff: bool,
):
"""Move selected UDCs to one conventional unload location."""
selected = self._selected_rows_or_warn()
if not selected:
return
shipped_rows: list[ScaricoRow] = []
movable_rows = list(selected)
if block_shipped_for_non_scaff:
shipped_rows = [
row for row in selected
if int(row.current_idcella or 0) == SHIPPED_IDCELLA
or "spedita" in str(row.diagnostic_note or "").lower()
]
shipped_udcs = {row.udc for row in shipped_rows}
movable_rows = [row for row in selected if row.udc not in shipped_udcs]
if shipped_rows and not movable_rows:
messagebox.showwarning(
title,
"Nessuna UDC movimentata.\n"
f"UDC in {SHIPPED_LABEL}: " + ", ".join(row.udc for row in shipped_rows),
parent=self,
)
return
if not messagebox.askyesno(
"Conferma scarico",
f"Scaricare {len(selected)} UDC da {self.ubicazione}?",
title,
confirm_text.format(count=len(movable_rows), ubicazione=self.ubicazione),
parent=self,
):
return
async def _job():
results: list[dict[str, Any]] = []
for row in selected:
for row in movable_rows:
result = await move_pallet_async(
self.db_client,
barcode_pallet=row.udc,
target_idcella=9999,
target_barcode_cella="9000000",
target_idcella=target_idcella,
target_barcode_cella=target_barcode_cella,
utente=_session_login(self.session),
)
results.append({"udc": row.udc, "affected": int(result.get("ok") or 0)})
@@ -690,33 +773,51 @@ class ScaricoDialog(ctk.CTkToplevel):
skipped = [item["udc"] for item in results if int(item.get("affected") or 0) <= 0]
if not done:
messagebox.showwarning(
"Scarica",
title,
"Nessuna UDC e' stata scaricata. Verifica che le unita' siano ancora presenti in cella.",
parent=self,
)
return
if skipped:
shipped_note = (
f"\nGia' in {SHIPPED_LABEL} non toccate: " + ", ".join(row.udc for row in shipped_rows)
if shipped_rows
else ""
)
target_note = (
f"\nUDC in {target_label}: " + ", ".join(done)
if done
else ""
)
messagebox.showwarning(
"Scarica",
title,
"Scarico parziale.\nCompletate: "
+ ", ".join(done)
+ "\nNon scaricate: "
+ ", ".join(skipped),
+ ", ".join(skipped)
+ shipped_note
+ target_note,
parent=self,
)
else:
messagebox.showinfo(
"Scarica",
"Scarico completato per:\n" + "\n".join(done),
parent=self,
)
msg = f"Scarico completato verso {target_label} per:\n" + "\n".join(done)
if shipped_rows:
msg += f"\n\nUDC gia' in {SHIPPED_LABEL} non toccate:\n" + "\n".join(row.udc for row in shipped_rows)
msg += f"\n\nUDC in {target_label}: " + ", ".join(done)
messagebox.showinfo(title, msg, parent=self)
log_user_action(
self.session,
module=MODULE_LOG_NAME,
action="layout.scarico",
action="layout.scarico.spedita" if int(target_idcella) == SHIPPED_IDCELLA else "layout.scarico.non_scaff",
outcome="ok",
target=self.ubicazione,
details={"scaricate": done, "saltate": skipped},
details={
"scaricate": done,
"saltate": skipped,
"target_idcella": target_idcella,
"target_barcode_cella": target_barcode_cella,
"gia_spedite": [row.udc for row in shipped_rows],
},
)
if self.on_completed:
self.on_completed()
@@ -727,7 +828,7 @@ class ScaricoDialog(ctk.CTkToplevel):
log_user_action(
self.session,
module=MODULE_LOG_NAME,
action="layout.scarico",
action="layout.scarico.spedita" if int(target_idcella) == SHIPPED_IDCELLA else "layout.scarico.non_scaff",
outcome="error",
target=self.ubicazione,
details={"error": str(ex)},
@@ -743,7 +844,7 @@ class ScaricoDialog(ctk.CTkToplevel):
_ok,
_err,
busy=self._busy,
message="Scarico UDC...",
message=busy_message,
)
@_log_call()

View File

@@ -107,6 +107,8 @@
"scarico.col.last_insert": "Ultimo inserimento",
"scarico.col.diagnostic": "Diagnostica",
"scarico.button.submit": "Scarica",
"scarico.button.shipped": "Scarico come spedita",
"scarico.button.non_shelved": "Scarico come non scaff.",
"scarico.button.close": "Chiudi",
"scarico.msg.title": "Scarica",
"scarico.msg.select_one": "Seleziona almeno una UDC da scaricare.",
@@ -220,6 +222,8 @@
"scarico.col.last_insert": "Last insert",
"scarico.col.diagnostic": "Diagnostics",
"scarico.button.submit": "Unload",
"scarico.button.shipped": "Unload as shipped",
"scarico.button.non_shelved": "Unload as non-shelved",
"scarico.button.close": "Close",
"scarico.msg.title": "Unload",
"scarico.msg.select_one": "Select at least one UDC to unload.",

View File

@@ -0,0 +1,9 @@
SET XACT_ABORT ON;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.py_BarcodePickingListSkip', N'U') IS NOT NULL
BEGIN
DROP TABLE dbo.py_BarcodePickingListSkip;
END;
COMMIT TRANSACTION;

View File

@@ -13,15 +13,15 @@ MODULE_VERSIONS: dict[str, str] = {
"async_msssql_query": "1.0.0",
"audit_log": "1.0.0",
"main": "1.0.1",
"barcode_client": "1.0.19",
"barcode_repository": "1.0.5",
"barcode_service": "1.0.15",
"barcode_client": "1.0.20",
"barcode_repository": "1.0.6",
"barcode_service": "1.0.16",
"busy_overlay": "1.0.0",
"db_config": "1.0.0",
"gestione_aree": "1.0.1",
"gestione_layout": "1.0.0",
"gestione_layout": "1.0.1",
"gestione_pickinglist": "1.0.2",
"gestione_scarico": "1.0.0",
"gestione_scarico": "1.0.1",
"locale_text": "1.0.0",
"login_window": "1.0.0",
"prenota_sprenota_sql": "1.0.0",