From 5dd7139b191bf52f91e8afbd12033d3324f432a2 Mon Sep 17 00:00:00 2001 From: allebonvi Date: Sat, 4 Jul 2026 09:27:52 +0200 Subject: [PATCH] Differenzia scarico layout spedita e non scaffalata --- gestione_layout.py | 22 +------ gestione_scarico.py | 147 +++++++++++++++++++++++++++++++++++++------- locale.json | 4 ++ version_info.py | 4 +- 4 files changed, 131 insertions(+), 46 deletions(-) diff --git a/gestione_layout.py b/gestione_layout.py index 688fcb6..f5d3aa2 100644 --- a/gestione_layout.py +++ b/gestione_layout.py @@ -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}...", - ) + self._open_scarico_dialog(r, c) @_log_call() def _run_pallet_move( diff --git a/gestione_scarico.py b/gestione_scarico.py index e1e723e..247b89b 100644 --- a/gestione_scarico.py +++ b/gestione_scarico.py @@ -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() diff --git a/locale.json b/locale.json index fb7da2a..35a4d61 100644 --- a/locale.json +++ b/locale.json @@ -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.", diff --git a/version_info.py b/version_info.py index dce0412..f3f9a67 100644 --- a/version_info.py +++ b/version_info.py @@ -19,9 +19,9 @@ MODULE_VERSIONS: dict[str, str] = { "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",