Stabilizza picking barcode e patch cumulativa online

This commit is contained in:
2026-07-04 17:03:55 +02:00
parent 5dd7139b19
commit 77da8d9bad
13 changed files with 1153 additions and 97 deletions

View File

@@ -204,28 +204,7 @@ last_move AS (
FROM dbo.MagazziniPallet mp
JOIN last_in_cell lic ON lic.LastID = mp.ID
),
latest_any AS (
SELECT
ranked.BarcodePallet,
ranked.IDCella
FROM (
SELECT
mp.Attributo AS BarcodePallet,
mp.IDCella,
ROW_NUMBER() OVER (
PARTITION BY mp.Attributo
ORDER BY mp.ID DESC
) AS rn
FROM dbo.MagazziniPallet mp
JOIN cell_pallets cp
ON cp.BarcodePallet COLLATE Latin1_General_CI_AS =
mp.Attributo COLLATE Latin1_General_CI_AS
WHERE mp.Tipo = 'V'
AND mp.PesoUnitario > 0
) ranked
WHERE ranked.rn = 1
),
shipped AS (
closed_plist AS (
SELECT DISTINCT
shipped.BarcodePallet
FROM dbo.XMag_GiacenzaPalletPlistChiuse shipped
@@ -237,26 +216,19 @@ SELECT
cp.BarcodePallet AS UDC,
lm.ID AS SourceID,
lm.DataMagazzino AS LastEventAt,
ISNULL(la.IDCella, :idcella) AS CurrentIDCella,
:idcella AS CurrentIDCella,
CASE
WHEN shipped.BarcodePallet IS NOT NULL THEN CAST(1 AS int)
ELSE CAST(0 AS int)
END AS IsShippedGhost,
CASE
WHEN la.IDCella IS NOT NULL
AND la.IDCella <> :idcella
WHEN :idcella <> 9999
AND closed_plist.BarcodePallet IS NOT NULL
THEN CAST(1 AS int)
ELSE CAST(0 AS int)
END AS IsMovedGhost
END AS IsMissingUnload
FROM cell_pallets cp
LEFT JOIN last_move lm
ON lm.BarcodePallet COLLATE Latin1_General_CI_AS =
cp.BarcodePallet COLLATE Latin1_General_CI_AS
LEFT JOIN latest_any la
ON la.BarcodePallet COLLATE Latin1_General_CI_AS =
cp.BarcodePallet COLLATE Latin1_General_CI_AS
LEFT JOIN shipped
ON shipped.BarcodePallet COLLATE Latin1_General_CI_AS =
LEFT JOIN closed_plist
ON closed_plist.BarcodePallet COLLATE Latin1_General_CI_AS =
cp.BarcodePallet COLLATE Latin1_General_CI_AS
ORDER BY
lm.ID DESC,
@@ -425,15 +397,18 @@ class ScaricoRow:
selected: tk.BooleanVar
def _build_diagnostic_note(is_shipped: int | bool, is_moved: int | bool) -> str:
def _build_diagnostic_note(is_missing_unload: int | bool = False) -> str:
"""Translate low-level anomaly flags into one operator-facing note."""
notes: list[str] = []
if bool(is_shipped):
notes.append("Mancato scarico: spedita")
if bool(is_moved):
notes.append("Mancato scarico: spostata")
return " | ".join(notes)
if bool(is_missing_unload):
return "Motivo: spedita ma non scaricata dalla cella"
return ""
def _is_missing_unload_row(row: ScaricoRow) -> bool:
"""Return True when the row must be corrected only with shipped unload."""
return "spedita ma non scaricata dalla cella" in str(row.diagnostic_note or "").lower()
class ScaricoDialog(ctk.CTkToplevel):
@@ -486,8 +461,9 @@ class ScaricoDialog(ctk.CTkToplevel):
self.wait_visibility()
except Exception:
pass
self.lift()
self.focus_force()
if self.winfo_exists():
self.lift()
self.focus_force()
def _build_ui(self):
"""Build the compact modal layout."""
@@ -633,7 +609,13 @@ 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, current_idcella, is_shipped, is_moved in rows:
for (
udc,
source_id,
last_event_at,
current_idcella,
is_missing_unload,
) in rows:
if isinstance(last_event_at, datetime):
last_event = last_event_at.strftime("%d/%m/%Y %H:%M:%S")
else:
@@ -644,7 +626,7 @@ class ScaricoDialog(ctk.CTkToplevel):
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),
diagnostic_note=_build_diagnostic_note(is_missing_unload),
selected=tk.BooleanVar(value=False),
)
)
@@ -728,21 +710,30 @@ class ScaricoDialog(ctk.CTkToplevel):
return
shipped_rows: list[ScaricoRow] = []
missing_unload_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]
missing_unload_rows = [row for row in selected if _is_missing_unload_row(row)]
blocked_udcs = {row.udc for row in shipped_rows + missing_unload_rows}
movable_rows = [row for row in selected if row.udc not in blocked_udcs]
if shipped_rows and not movable_rows:
if (shipped_rows or missing_unload_rows) and not movable_rows:
message_lines = ["Nessuna UDC movimentata."]
if shipped_rows:
message_lines.append(f"UDC gia' in {SHIPPED_LABEL}: " + ", ".join(row.udc for row in shipped_rows))
if missing_unload_rows:
message_lines.append(
"UDC spedite ma non scaricate: "
+ ", ".join(row.udc for row in missing_unload_rows)
)
message_lines.append("Usare 'Scarico come spedita'.")
messagebox.showwarning(
title,
"Nessuna UDC movimentata.\n"
f"UDC in {SHIPPED_LABEL}: " + ", ".join(row.udc for row in shipped_rows),
"\n".join(message_lines),
parent=self,
)
return
@@ -784,6 +775,12 @@ class ScaricoDialog(ctk.CTkToplevel):
if shipped_rows
else ""
)
missing_unload_note = (
"\nSpedite ma non scaricate, usare 'Scarico come spedita': "
+ ", ".join(row.udc for row in missing_unload_rows)
if missing_unload_rows
else ""
)
target_note = (
f"\nUDC in {target_label}: " + ", ".join(done)
if done
@@ -796,6 +793,7 @@ class ScaricoDialog(ctk.CTkToplevel):
+ "\nNon scaricate: "
+ ", ".join(skipped)
+ shipped_note
+ missing_unload_note
+ target_note,
parent=self,
)
@@ -804,6 +802,12 @@ class ScaricoDialog(ctk.CTkToplevel):
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)
if missing_unload_rows:
msg += (
"\n\nUDC spedite ma non scaricate non toccate:\n"
+ "\n".join(row.udc for row in missing_unload_rows)
+ "\nUsare 'Scarico come spedita'."
)
messagebox.showinfo(title, msg, parent=self)
log_user_action(
self.session,
@@ -817,6 +821,7 @@ class ScaricoDialog(ctk.CTkToplevel):
"target_idcella": target_idcella,
"target_barcode_cella": target_barcode_cella,
"gia_spedite": [row.udc for row in shipped_rows],
"spedite_non_scaricate": [row.udc for row in missing_unload_rows],
},
)
if self.on_completed: