Aggiungi pausa picking list nel barcode

This commit is contained in:
2026-07-03 10:13:49 +02:00
parent 29687c8094
commit 7ecc906d59
4 changed files with 238 additions and 25 deletions

View File

@@ -67,6 +67,7 @@ class BarcodeClientApp:
self._pending: Future | None = None
self._auto_advance_id: str | None = None
self._pallet_auto_focus_id: str | None = None
self._paused_queue_id: int | None = None
self._status_colors = {
"red": "#f4cccc",
"green": "#d9ead3",
@@ -198,7 +199,7 @@ class BarcodeClientApp:
self.btn_f1 = ttk.Button(buttons, text="[F1] H Priority", command=lambda: self._start_queue(1))
self.btn_f1.grid(row=0, column=0, padx=(0, 4), pady=(0, button_pad_y), sticky="ew")
self.btn_submit = ttk.Button(buttons, text="[Ent] Carica", command=self._submit)
self.btn_submit = ttk.Button(buttons, text="[F3] Carica", command=self._on_f3)
self.btn_submit.grid(row=0, column=1, padx=(4, 0), pady=(0, button_pad_y), sticky="ew")
self.btn_f2 = ttk.Button(buttons, text="[F2] L Priority", command=lambda: self._start_queue(0))
self.btn_f2.grid(row=1, column=0, padx=(0, 4), sticky="ew")
@@ -324,7 +325,9 @@ class BarcodeClientApp:
def _bind_keys(self) -> None:
self.root.bind("<F1>", lambda _e: self._start_queue(1))
self.root.bind("<F2>", lambda _e: self._start_queue(0))
self.root.bind("<F3>", self._on_f3_key)
self.root.bind("<F4>", self._on_unload_key)
self.root.bind("<Escape>", self._on_escape_key)
self.pallet_entry.bind("<Return>", self._on_pallet_enter)
self.destination_entry.bind("<Return>", self._on_destination_enter)
@@ -352,6 +355,9 @@ class BarcodeClientApp:
self.busy_bar.stop()
self.busy_cover.place_forget()
def _is_priority_pause(self) -> bool:
return str(self.queue_var.get() or "") == "Pausa PL"
def _apply_state(self, state: BarcodeViewState) -> None:
if self._auto_advance_id is not None:
try:
@@ -368,12 +374,26 @@ class BarcodeClientApp:
self.queue_var.set(state.queue_label)
self.destination_var.set(state.destination_barcode)
self.scanned_var.set(state.scanned_pallet)
self.info1_var.set(state.status_text)
self.info1_var.set(self._status_text_with_wait_hint(state))
self.info2_var.set(state.document)
self.info3_var.set(state.customer)
self.info4_var.set(state.expected_pallet)
self.status_band.configure(bg=state.status_color or self._status_colors["red"])
try:
if str(state.queue_label or "") != "Pausa PL":
self._paused_queue_id = None
resumable_queue = self._resumable_queue_from_state(state)
if state.mode in ("priority_high", "priority_low") or resumable_queue is not None:
self.btn_submit.configure(text="[F3] Pausa PL")
else:
self.btn_submit.configure(text="[F3] Carica")
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)
except Exception:
pass
destination_readonly = bool(getattr(state, "destination_readonly", False))
try:
self.destination_entry.configure(state="normal")
@@ -382,16 +402,11 @@ class BarcodeClientApp:
except Exception:
pass
is_completed_move = (
str(state.status_text or "").startswith("Ok Scarico")
or str(state.status_text or "").startswith("Ok Carico")
)
if state.mode == "confirm" and is_completed_move:
next_queue = self._queue_id_from_label(state.queue_label)
delay_ms = int(getattr(state, "auto_advance_delay_ms", 0) or 0)
if next_queue is not None and delay_ms > 0:
if state.mode == "confirm":
next_queue = self._resumable_queue_from_state(state)
if next_queue is not None:
self._auto_advance_id = self.root.after(
delay_ms,
int(getattr(state, "auto_advance_delay_ms", 0) or 0),
lambda q=next_queue: self._start_queue(q),
)
@@ -404,6 +419,17 @@ class BarcodeClientApp:
except Exception:
pass
def _status_text_with_wait_hint(self, state: BarcodeViewState) -> str:
text = str(getattr(state, "status_text", "") or "")
delay_ms = int(getattr(state, "auto_advance_delay_ms", 0) or 0)
if delay_ms <= 0:
return text
seconds = max(1, round(delay_ms / 1000))
hint = f"Attendi {seconds} secondi..."
if hint.lower() in text.lower():
return text
return f"{text} - {hint}" if text else hint
def _focus_destination_input(self) -> None:
try:
self.destination_entry.configure(state="normal")
@@ -443,20 +469,50 @@ class BarcodeClientApp:
self._begin_manual_unload()
return "break"
def _on_escape_key(self, _event=None) -> str:
if self._is_priority_pause() and self._paused_queue_id is not None:
self._start_queue(self._paused_queue_id, allow_during_pause=True)
return "break"
def _on_f3_key(self, _event=None) -> str:
self._on_f3()
return "break"
def _on_f3(self) -> None:
mode = getattr(self.service.state, "mode", "")
if mode == "priority_high":
self._paused_queue_id = 1
self._apply_state(self.service.begin_priority_pause(1))
return
if mode == "priority_low":
self._paused_queue_id = 0
self._apply_state(self.service.begin_priority_pause(0))
return
resumable_queue = self._resumable_queue_from_state(self.service.state)
if resumable_queue is not None:
self._paused_queue_id = resumable_queue
self._apply_state(self.service.begin_priority_pause(resumable_queue))
return
self._submit()
def _begin_manual_unload(self) -> None:
pallet = str(self.scanned_var.get() or "").strip()
destination = str(self.destination_var.get() or "").strip()
if pallet and destination in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE):
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()
return
if pallet and not destination:
self.destination_var.set(self.NON_SCAFFALATA_BARCODE)
self._submit()
if pallet:
self._submit_unload_with_source_check()
return
if self._is_priority_pause():
return
self._apply_state(self.service.begin_manual_unload())
def _start_queue(self, id_stato: int) -> None:
def _start_queue(self, id_stato: int, *, allow_during_pause: bool = False) -> None:
if self._is_priority_pause() and not allow_during_pause:
return
self._run_async(
lambda: self.service.start_priority_queue(id_stato),
busy_message="In preparazione...",
@@ -471,6 +527,15 @@ class BarcodeClientApp:
busy_message="In esecuzione...",
)
def _submit_unload_with_source_check(self) -> None:
self._run_async(
lambda: self.service.submit_unload_with_source_check(
scanned_pallet=self.scanned_var.get(),
source_barcode=self.destination_var.get(),
),
busy_message="In esecuzione...",
)
def _run_async(self, coro_factory: Callable[[], object], busy_message: str) -> None:
if self._pending is not None and not self._pending.done():
return
@@ -492,6 +557,12 @@ class BarcodeClientApp:
return 0
return None
def _resumable_queue_from_state(self, state: BarcodeViewState) -> int | None:
delay_ms = int(getattr(state, "auto_advance_delay_ms", 0) or 0)
if delay_ms <= 0:
return None
return self._queue_id_from_label(str(getattr(state, "queue_label", "") or ""))
def _poll_future(self) -> None:
if self._pending is None:
self._set_busy(False)