Stabilizza barcode e UDC non scaffalate
This commit is contained in:
@@ -11,6 +11,7 @@ import customtkinter as ctk
|
||||
from busy_overlay import InlineBusyOverlay
|
||||
from gestione_aree import AsyncRunner
|
||||
from locale_text import load_locale_catalog, text as loc_text
|
||||
from runtime_support import log_exception
|
||||
from ui_tables import style_treeview, zebra_tag
|
||||
from ui_theme import theme_color, theme_font, theme_section, theme_value
|
||||
from version_info import module_version, versioned_title
|
||||
@@ -20,7 +21,7 @@ __version__ = module_version(__name__)
|
||||
|
||||
|
||||
SQL_NON_SCAFFALATE = """
|
||||
WITH trace AS (
|
||||
WITH trace_rows AS (
|
||||
SELECT
|
||||
Pallet,
|
||||
MIN(Lotto) AS Lotto,
|
||||
@@ -39,7 +40,7 @@ SELECT
|
||||
FROM dbo.XMag_GiacenzaPallet AS g
|
||||
LEFT JOIN dbo.Celle AS c
|
||||
ON c.ID = g.IDCella
|
||||
LEFT JOIN trace AS t
|
||||
LEFT JOIN trace_rows AS t
|
||||
ON t.Pallet COLLATE Latin1_General_CI_AS =
|
||||
g.BarcodePallet COLLATE Latin1_General_CI_AS
|
||||
WHERE g.IDCella = 1000
|
||||
@@ -72,6 +73,7 @@ class UDCNonScaffalateWindow(ctk.CTkToplevel):
|
||||
self._locale_catalog = load_locale_catalog()
|
||||
self._async = AsyncRunner(self)
|
||||
self._busy = InlineBusyOverlay(self, self._theme)
|
||||
self._load_in_progress = False
|
||||
|
||||
self.title(versioned_title(loc_text("non_shelved.title", catalog=self._locale_catalog, default="UDC non scaffalate"), __name__))
|
||||
self.geometry(str(theme_value(self._theme, "window_geometry", "1000x650")))
|
||||
@@ -85,6 +87,18 @@ class UDCNonScaffalateWindow(ctk.CTkToplevel):
|
||||
self._build_ui()
|
||||
self.after(250, self._load)
|
||||
|
||||
def _is_alive(self) -> bool:
|
||||
try:
|
||||
return bool(self.winfo_exists())
|
||||
except tk.TclError:
|
||||
return False
|
||||
|
||||
def _hide_busy_safe(self) -> None:
|
||||
try:
|
||||
self._busy.hide()
|
||||
except Exception as exc:
|
||||
log_exception(__name__, exc, context="hide busy UDC non scaffalate")
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
self.grid_rowconfigure(1, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
@@ -145,33 +159,62 @@ class UDCNonScaffalateWindow(ctk.CTkToplevel):
|
||||
sx.grid(row=1, column=0, sticky="ew")
|
||||
|
||||
def _load(self) -> None:
|
||||
if self._load_in_progress or not self._is_alive():
|
||||
return
|
||||
|
||||
async def job():
|
||||
return await self.db_client.query_json(SQL_NON_SCAFFALATE, as_dict_rows=True)
|
||||
|
||||
self._busy.show(loc_text("non_shelved.busy", catalog=self._locale_catalog, default="Carico UDC non scaffalate..."))
|
||||
self._async.run(job(), self._on_loaded, self._on_error)
|
||||
self._load_in_progress = True
|
||||
try:
|
||||
self._busy.show(loc_text("non_shelved.busy", catalog=self._locale_catalog, default="Carico UDC non scaffalate..."))
|
||||
self._async.run(job(), self._on_loaded, self._on_error)
|
||||
except Exception as exc:
|
||||
self._load_in_progress = False
|
||||
self._hide_busy_safe()
|
||||
log_exception(__name__, exc, context="avvio caricamento UDC non scaffalate")
|
||||
messagebox.showerror(
|
||||
loc_text("non_shelved.title", catalog=self._locale_catalog, default="UDC non scaffalate"),
|
||||
str(exc),
|
||||
parent=self if self._is_alive() else None,
|
||||
)
|
||||
|
||||
def _on_loaded(self, res: dict[str, Any] | None) -> None:
|
||||
self._busy.hide()
|
||||
rows = _rows_to_dicts(res)
|
||||
self.tree.delete(*self.tree.get_children(""))
|
||||
for index, row in enumerate(rows):
|
||||
self.tree.insert(
|
||||
"",
|
||||
"end",
|
||||
values=(
|
||||
row.get("UDC") or "",
|
||||
row.get("IDCella") or "",
|
||||
row.get("Ubicazione") or "",
|
||||
row.get("Lotto") or "",
|
||||
row.get("Prodotto") or "",
|
||||
row.get("Descrizione") or "",
|
||||
),
|
||||
tags=(zebra_tag(index),),
|
||||
self._load_in_progress = False
|
||||
self._hide_busy_safe()
|
||||
if not self._is_alive():
|
||||
return
|
||||
try:
|
||||
rows = _rows_to_dicts(res)
|
||||
self.tree.delete(*self.tree.get_children(""))
|
||||
for index, row in enumerate(rows):
|
||||
self.tree.insert(
|
||||
"",
|
||||
"end",
|
||||
values=(
|
||||
row.get("UDC") or "",
|
||||
row.get("IDCella") or "",
|
||||
row.get("Ubicazione") or "",
|
||||
row.get("Lotto") or "",
|
||||
row.get("Prodotto") or "",
|
||||
row.get("Descrizione") or "",
|
||||
),
|
||||
tags=(zebra_tag(index),),
|
||||
)
|
||||
except Exception as exc:
|
||||
log_exception(__name__, exc, context="render UDC non scaffalate")
|
||||
messagebox.showerror(
|
||||
loc_text("non_shelved.title", catalog=self._locale_catalog, default="UDC non scaffalate"),
|
||||
str(exc),
|
||||
parent=self,
|
||||
)
|
||||
|
||||
def _on_error(self, exc: BaseException) -> None:
|
||||
self._busy.hide()
|
||||
self._load_in_progress = False
|
||||
self._hide_busy_safe()
|
||||
log_exception(__name__, exc, context="query UDC non scaffalate")
|
||||
if not self._is_alive():
|
||||
return
|
||||
messagebox.showerror(
|
||||
loc_text("non_shelved.title", catalog=self._locale_catalog, default="UDC non scaffalate"),
|
||||
str(exc),
|
||||
@@ -183,5 +226,5 @@ def open_udc_non_scaffalate_window(parent: tk.Misc, db_client, session=None) ->
|
||||
"""Open the non-shelved UDC window."""
|
||||
|
||||
win = UDCNonScaffalateWindow(parent, db_client, session=session)
|
||||
place_window_fullsize_below_parent_later(win, parent)
|
||||
place_window_fullsize_below_parent_later(parent, win)
|
||||
return win
|
||||
|
||||
Reference in New Issue
Block a user