Compare commits
11 Commits
alpha11-sa
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5dc26b21b1 | |||
| 0ae052e55b | |||
| 7dc068b1b0 | |||
| 1ea37eb49d | |||
| 7f3ce9d3af | |||
| 8e9294f80b | |||
| fa9d0be09a | |||
| 44cd82352b | |||
| eb12af3b9a | |||
| 77da8d9bad | |||
| 5dd7139b19 |
@@ -5,8 +5,8 @@ IF OBJECT_ID(N'dbo.py_BarcodePickingListSkip', N'U') IS NULL
|
|||||||
BEGIN
|
BEGIN
|
||||||
CREATE TABLE dbo.py_BarcodePickingListSkip (
|
CREATE TABLE dbo.py_BarcodePickingListSkip (
|
||||||
ID int IDENTITY(1,1) NOT NULL CONSTRAINT PK_py_BarcodePickingListSkip PRIMARY KEY,
|
ID int IDENTITY(1,1) NOT NULL CONSTRAINT PK_py_BarcodePickingListSkip PRIMARY KEY,
|
||||||
Documento varchar(50) NOT NULL,
|
Documento varchar(50) COLLATE Latin1_General_CI_AS NOT NULL,
|
||||||
Pallet varchar(50) NOT NULL,
|
Pallet varchar(50) COLLATE Latin1_General_CI_AS NOT NULL,
|
||||||
IDStato int NOT NULL,
|
IDStato int NOT NULL,
|
||||||
IDOperatore int NOT NULL,
|
IDOperatore int NOT NULL,
|
||||||
DataOra datetime2(0) NOT NULL CONSTRAINT DF_py_BarcodePickingListSkip_DataOra DEFAULT SYSDATETIME(),
|
DataOra datetime2(0) NOT NULL CONSTRAINT DF_py_BarcodePickingListSkip_DataOra DEFAULT SYSDATETIME(),
|
||||||
|
|||||||
531
apply_online_python_wms_full_patch.sql
Normal file
531
apply_online_python_wms_full_patch.sql
Normal file
@@ -0,0 +1,531 @@
|
|||||||
|
/*
|
||||||
|
Patch cumulativa DB online - ramo Python WMS
|
||||||
|
|
||||||
|
Da eseguire una sola volta in SSMS sul database Mediseawall.
|
||||||
|
|
||||||
|
Questa patch NON modifica gli oggetti legacy usati dal programma C#.
|
||||||
|
|
||||||
|
Include:
|
||||||
|
- dbo.PyPickingListReservation
|
||||||
|
- dbo.py_XMag_ViewPackingList
|
||||||
|
- dbo.py_ViewPackingListRestante
|
||||||
|
- dbo.py_sp_xExePackingListPallet
|
||||||
|
- dbo.py_sp_xExePackingListPalletPrenota
|
||||||
|
- dbo.py_sp_ControllaPrenotazionePackingListPalletNew
|
||||||
|
- dbo.py_vPreparaPackingListSAMA1
|
||||||
|
- dbo.py_vPreparaPackingList
|
||||||
|
- dbo.py_XMag_ViewPackingListStorico
|
||||||
|
- dbo.py_BarcodePickingListSkip
|
||||||
|
|
||||||
|
Nota storico:
|
||||||
|
dbo.py_vPreparaPackingListSAMA1 usa ANNDOC >= YEAR(GETDATE())
|
||||||
|
per mantenere visibili solo le picking list dall'inizio dell'anno corrente.
|
||||||
|
*/
|
||||||
|
|
||||||
|
SET ANSI_NULLS ON;
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON;
|
||||||
|
GO
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
1. Stato prenotazione picking list ramo Python
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
IF OBJECT_ID(N'dbo.PyPickingListReservation', N'U') IS NULL
|
||||||
|
BEGIN
|
||||||
|
CREATE TABLE [dbo].[PyPickingListReservation](
|
||||||
|
[ID] [tinyint] NOT NULL,
|
||||||
|
[Documento] [varchar](8) NULL,
|
||||||
|
[IDOperatore] [int] NULL,
|
||||||
|
[ModUtente] [varchar](50) NULL,
|
||||||
|
[ModDataOra] [datetime] NULL,
|
||||||
|
CONSTRAINT [PK_PyPickingListReservation] PRIMARY KEY CLUSTERED ([ID] ASC),
|
||||||
|
CONSTRAINT [CK_PyPickingListReservation_Singleton] CHECK ([ID] = 1)
|
||||||
|
) ON [PRIMARY];
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM dbo.PyPickingListReservation WHERE ID = 1)
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO dbo.PyPickingListReservation (ID, Documento, IDOperatore, ModUtente, ModDataOra)
|
||||||
|
VALUES (1, NULL, NULL, NULL, GETDATE());
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
2. Viste operative picking list ramo Python
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
CREATE OR ALTER VIEW [dbo].[py_XMag_ViewPackingList]
|
||||||
|
AS
|
||||||
|
SELECT TOP 10000
|
||||||
|
legacy.Pallet,
|
||||||
|
legacy.Lotto,
|
||||||
|
legacy.Articolo,
|
||||||
|
legacy.Descrizione,
|
||||||
|
legacy.Qta,
|
||||||
|
legacy.Documento,
|
||||||
|
legacy.CodNazione,
|
||||||
|
legacy.NAZIONE,
|
||||||
|
legacy.Stato,
|
||||||
|
legacy.PalletCella,
|
||||||
|
legacy.Magazzino,
|
||||||
|
legacy.Area,
|
||||||
|
legacy.Cella,
|
||||||
|
legacy.Ordinamento,
|
||||||
|
legacy.Ubicazione,
|
||||||
|
legacy.DEST,
|
||||||
|
CASE
|
||||||
|
WHEN pr.Documento IS NOT NULL
|
||||||
|
AND pr.Documento = CAST(legacy.Documento AS varchar(8))
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END AS IDStato
|
||||||
|
FROM dbo.XMag_ViewPackingList legacy
|
||||||
|
LEFT JOIN dbo.PyPickingListReservation pr
|
||||||
|
ON pr.ID = 1
|
||||||
|
AND NULLIF(LTRIM(RTRIM(pr.Documento)), '') IS NOT NULL
|
||||||
|
ORDER BY
|
||||||
|
CASE
|
||||||
|
WHEN pr.Documento IS NOT NULL
|
||||||
|
AND pr.Documento = CAST(legacy.Documento AS varchar(8))
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END DESC,
|
||||||
|
legacy.Documento,
|
||||||
|
legacy.Ordinamento;
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER VIEW [dbo].[py_ViewPackingListRestante]
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
Pallet,
|
||||||
|
Lotto,
|
||||||
|
Articolo,
|
||||||
|
Descrizione,
|
||||||
|
Qta,
|
||||||
|
Documento,
|
||||||
|
CodNazione,
|
||||||
|
NAZIONE,
|
||||||
|
Stato,
|
||||||
|
PalletCella,
|
||||||
|
Magazzino,
|
||||||
|
Area,
|
||||||
|
Cella,
|
||||||
|
Ordinamento,
|
||||||
|
Ubicazione,
|
||||||
|
DEST,
|
||||||
|
IDStato
|
||||||
|
FROM dbo.py_XMag_ViewPackingList
|
||||||
|
WHERE Cella <> 9999;
|
||||||
|
GO
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
3. Stored procedure operative ramo Python
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[py_sp_xExePackingListPallet]
|
||||||
|
@IDOperatore int,
|
||||||
|
@Documento varchar(8),
|
||||||
|
@Azione char(1) = 'P',
|
||||||
|
@RC int OUTPUT
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
SET @RC = 0;
|
||||||
|
|
||||||
|
DECLARE @Nominativo varchar(50) = '';
|
||||||
|
DECLARE @DocumentoAttivo varchar(8) = NULL;
|
||||||
|
DECLARE @Description varchar(255) = '';
|
||||||
|
DECLARE @Message varchar(255) = '';
|
||||||
|
DECLARE @IDResult int = 0;
|
||||||
|
DECLARE @ID int = 0;
|
||||||
|
|
||||||
|
SELECT @Nominativo = [Login]
|
||||||
|
FROM dbo.Operatori
|
||||||
|
WHERE ID = @IDOperatore;
|
||||||
|
|
||||||
|
IF @Nominativo IS NULL
|
||||||
|
SET @Nominativo = 'SYSTEM';
|
||||||
|
|
||||||
|
IF @Azione NOT IN ('P', 'S')
|
||||||
|
BEGIN
|
||||||
|
SET @RC = -10;
|
||||||
|
RETURN;
|
||||||
|
END;
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM dbo.py_XMag_ViewPackingList
|
||||||
|
WHERE CAST(Documento AS varchar(8)) = @Documento
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
SET @RC = -20;
|
||||||
|
RETURN;
|
||||||
|
END;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM dbo.PyPickingListReservation WHERE ID = 1)
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO dbo.PyPickingListReservation (ID, Documento, IDOperatore, ModUtente, ModDataOra)
|
||||||
|
VALUES (1, NULL, NULL, NULL, GETDATE());
|
||||||
|
END;
|
||||||
|
|
||||||
|
SELECT @DocumentoAttivo = NULLIF(LTRIM(RTRIM(Documento)), '')
|
||||||
|
FROM dbo.PyPickingListReservation
|
||||||
|
WHERE ID = 1;
|
||||||
|
|
||||||
|
DECLARE @TargetCelle TABLE (
|
||||||
|
IDCella int PRIMARY KEY
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO @TargetCelle (IDCella)
|
||||||
|
SELECT DISTINCT Cella
|
||||||
|
FROM dbo.py_XMag_ViewPackingList
|
||||||
|
WHERE CAST(Documento AS varchar(8)) = @Documento
|
||||||
|
AND Cella IS NOT NULL;
|
||||||
|
|
||||||
|
IF @Azione = 'P'
|
||||||
|
BEGIN
|
||||||
|
IF @DocumentoAttivo = @Documento
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
UPDATE c
|
||||||
|
SET c.IDStato = 0,
|
||||||
|
c.ModUtente = @Nominativo,
|
||||||
|
c.ModDataOra = GETDATE()
|
||||||
|
FROM dbo.Celle c
|
||||||
|
WHERE ISNULL(c.IDStato, 0) <> 0;
|
||||||
|
|
||||||
|
UPDATE c
|
||||||
|
SET c.IDStato = 1,
|
||||||
|
c.ModUtente = @Nominativo,
|
||||||
|
c.ModDataOra = GETDATE()
|
||||||
|
FROM dbo.Celle c
|
||||||
|
INNER JOIN @TargetCelle t ON t.IDCella = c.ID;
|
||||||
|
|
||||||
|
UPDATE dbo.PyPickingListReservation
|
||||||
|
SET Documento = @Documento,
|
||||||
|
IDOperatore = @IDOperatore,
|
||||||
|
ModUtente = @Nominativo,
|
||||||
|
ModDataOra = GETDATE()
|
||||||
|
WHERE ID = 1;
|
||||||
|
|
||||||
|
SELECT TOP 1 @Description = NAZIONE
|
||||||
|
FROM dbo.py_XMag_ViewPackingList
|
||||||
|
WHERE CAST(Documento AS varchar(8)) = @Documento;
|
||||||
|
|
||||||
|
EXEC dbo.sp_LogPackingList
|
||||||
|
@ID = @ID,
|
||||||
|
@Code = @Documento,
|
||||||
|
@Description = @Description,
|
||||||
|
@Message = @Message OUTPUT,
|
||||||
|
@IDResult = @IDResult OUTPUT;
|
||||||
|
|
||||||
|
RETURN;
|
||||||
|
END;
|
||||||
|
|
||||||
|
IF @Azione = 'S'
|
||||||
|
BEGIN
|
||||||
|
IF ISNULL(@DocumentoAttivo, '') <> @Documento
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
UPDATE c
|
||||||
|
SET c.IDStato = 0,
|
||||||
|
c.ModUtente = @Nominativo,
|
||||||
|
c.ModDataOra = GETDATE()
|
||||||
|
FROM dbo.Celle c
|
||||||
|
INNER JOIN @TargetCelle t ON t.IDCella = c.ID;
|
||||||
|
|
||||||
|
UPDATE dbo.PyPickingListReservation
|
||||||
|
SET Documento = NULL,
|
||||||
|
IDOperatore = @IDOperatore,
|
||||||
|
ModUtente = @Nominativo,
|
||||||
|
ModDataOra = GETDATE()
|
||||||
|
WHERE ID = 1;
|
||||||
|
|
||||||
|
RETURN;
|
||||||
|
END;
|
||||||
|
END;
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[py_sp_xExePackingListPalletPrenota]
|
||||||
|
@IDOperatore int,
|
||||||
|
@Documento varchar(8),
|
||||||
|
@RC int OUTPUT
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
SET @RC = 0;
|
||||||
|
|
||||||
|
DECLARE @Nominativo varchar(50) = '';
|
||||||
|
|
||||||
|
SELECT @Nominativo = LOGIN
|
||||||
|
FROM dbo.Operatori
|
||||||
|
WHERE ID = @IDOperatore;
|
||||||
|
|
||||||
|
IF @Nominativo IS NULL
|
||||||
|
SET @Nominativo = 'SYSTEM';
|
||||||
|
|
||||||
|
UPDATE c
|
||||||
|
SET c.IDStato = 1,
|
||||||
|
c.ModUtente = @Nominativo,
|
||||||
|
c.ModDataOra = GETDATE()
|
||||||
|
FROM dbo.Celle c
|
||||||
|
WHERE c.ID IN (
|
||||||
|
SELECT DISTINCT Cella
|
||||||
|
FROM dbo.py_ViewPackingListRestante
|
||||||
|
WHERE CAST(Documento AS varchar(8)) = @Documento
|
||||||
|
AND Cella IS NOT NULL
|
||||||
|
);
|
||||||
|
END;
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[py_sp_ControllaPrenotazionePackingListPalletNew]
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
|
DECLARE @Documento varchar(8) = NULL;
|
||||||
|
DECLARE @IDOperatore int = 0;
|
||||||
|
DECLARE @Nominativo varchar(50) = 'SYSTEM';
|
||||||
|
DECLARE @RC int = 0;
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
@Documento = NULLIF(LTRIM(RTRIM(Documento)), ''),
|
||||||
|
@IDOperatore = ISNULL(IDOperatore, 0),
|
||||||
|
@Nominativo = ISNULL(NULLIF(LTRIM(RTRIM(ModUtente)), ''), 'SYSTEM')
|
||||||
|
FROM dbo.PyPickingListReservation
|
||||||
|
WHERE ID = 1;
|
||||||
|
|
||||||
|
IF ISNULL(@Documento, '') = ''
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM dbo.py_ViewPackingListRestante
|
||||||
|
WHERE CAST(Documento AS varchar(8)) = @Documento
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
UPDATE dbo.Celle
|
||||||
|
SET IDStato = 0,
|
||||||
|
ModUtente = @Nominativo,
|
||||||
|
ModDataOra = GETDATE()
|
||||||
|
WHERE ISNULL(IDStato, 0) <> 0;
|
||||||
|
|
||||||
|
UPDATE dbo.PyPickingListReservation
|
||||||
|
SET Documento = NULL,
|
||||||
|
IDOperatore = @IDOperatore,
|
||||||
|
ModUtente = @Nominativo,
|
||||||
|
ModDataOra = GETDATE()
|
||||||
|
WHERE ID = 1;
|
||||||
|
|
||||||
|
RETURN;
|
||||||
|
END;
|
||||||
|
|
||||||
|
UPDATE dbo.Celle
|
||||||
|
SET IDStato = 0,
|
||||||
|
ModUtente = @Nominativo,
|
||||||
|
ModDataOra = GETDATE()
|
||||||
|
WHERE ISNULL(IDStato, 0) <> 0;
|
||||||
|
|
||||||
|
IF @IDOperatore <= 0
|
||||||
|
BEGIN
|
||||||
|
SELECT TOP 1 @IDOperatore = ID
|
||||||
|
FROM dbo.Operatori
|
||||||
|
WHERE LOGIN = @Nominativo;
|
||||||
|
END;
|
||||||
|
|
||||||
|
EXEC dbo.py_sp_xExePackingListPalletPrenota
|
||||||
|
@IDOperatore = @IDOperatore,
|
||||||
|
@Documento = @Documento,
|
||||||
|
@RC = @RC OUTPUT;
|
||||||
|
END;
|
||||||
|
GO
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
4. Viste storico picking list ramo Python
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
CREATE OR ALTER VIEW [dbo].[py_vPreparaPackingListSAMA1]
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
SAMA1.dbo.LOTSER.NUMLOT,
|
||||||
|
SAMA1.dbo.ARTICO.CODICE,
|
||||||
|
SAMA1.dbo.FATRIG.DESCR,
|
||||||
|
LEFT(SAMA1.dbo.LOTSER.NUMSER, 6) AS UDC,
|
||||||
|
SUM(SAMA1.dbo.LOTSER.QTTGIAI) AS Qta,
|
||||||
|
SAMA1.dbo.BAMTES.NUMDOC,
|
||||||
|
SAMA1.dbo.BAMTES.DATDOC,
|
||||||
|
SAMA1.dbo.BAMTES.ID,
|
||||||
|
SAMA1.dbo.BAMTES.DESCRDEST,
|
||||||
|
SAMA1.dbo.BAMTES.STATO AS StatoDocumento,
|
||||||
|
SAMA1.dbo.NAZIONI.CODICE AS Expr1,
|
||||||
|
SAMA1.dbo.MTRASP.CODICE + ' ' + SAMA1.dbo.NAZIONI.DESCR AS NAZIONE,
|
||||||
|
SAMA1.dbo.BAMTES.IDMTRASP
|
||||||
|
FROM SAMA1.dbo.NAZIONI
|
||||||
|
INNER JOIN SAMA1.dbo.BAMTES
|
||||||
|
ON SAMA1.dbo.NAZIONI.ID = SAMA1.dbo.BAMTES.IDNAZDEST
|
||||||
|
RIGHT OUTER JOIN SAMA1.dbo.LOTTIBF
|
||||||
|
LEFT OUTER JOIN SAMA1.dbo.LOTSER
|
||||||
|
ON SAMA1.dbo.LOTTIBF.IDLOTSER = SAMA1.dbo.LOTSER.ID
|
||||||
|
LEFT OUTER JOIN SAMA1.dbo.ARTICO
|
||||||
|
ON SAMA1.dbo.LOTSER.IDARTICO = SAMA1.dbo.ARTICO.ID
|
||||||
|
LEFT OUTER JOIN SAMA1.dbo.FATRIG
|
||||||
|
ON SAMA1.dbo.LOTTIBF.IDFATRIG = SAMA1.dbo.FATRIG.ID
|
||||||
|
ON SAMA1.dbo.BAMTES.ID = SAMA1.dbo.FATRIG.IDBAM
|
||||||
|
LEFT OUTER JOIN SAMA1.sam.EXTUC
|
||||||
|
ON LEFT(SAMA1.dbo.LOTSER.NUMSER, 6) = SAMA1.sam.EXTUC.CODICE
|
||||||
|
LEFT OUTER JOIN SAMA1.dbo.MTRASP
|
||||||
|
ON SAMA1.dbo.BAMTES.IDMTRASP = SAMA1.dbo.MTRASP.ID
|
||||||
|
WHERE
|
||||||
|
SAMA1.dbo.BAMTES.ANNDOC >= YEAR(GETDATE())
|
||||||
|
AND SAMA1.dbo.BAMTES.STATO IN ('P', 'D')
|
||||||
|
AND SAMA1.dbo.LOTSER.NUMLOT <> '00000000000'
|
||||||
|
GROUP BY
|
||||||
|
SAMA1.dbo.LOTSER.NUMLOT,
|
||||||
|
SAMA1.dbo.ARTICO.CODICE,
|
||||||
|
SAMA1.dbo.FATRIG.DESCR,
|
||||||
|
LEFT(SAMA1.dbo.LOTSER.NUMSER, 6),
|
||||||
|
SAMA1.dbo.BAMTES.NUMDOC,
|
||||||
|
SAMA1.dbo.BAMTES.DATDOC,
|
||||||
|
SAMA1.dbo.BAMTES.ID,
|
||||||
|
SAMA1.dbo.BAMTES.DESCRDEST,
|
||||||
|
SAMA1.dbo.BAMTES.STATO,
|
||||||
|
SAMA1.dbo.NAZIONI.CODICE,
|
||||||
|
SAMA1.dbo.NAZIONI.DESCR,
|
||||||
|
SAMA1.dbo.BAMTES.IDMTRASP,
|
||||||
|
SAMA1.dbo.MTRASP.CODICE;
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER VIEW [dbo].[py_vPreparaPackingList]
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
NUMLOT,
|
||||||
|
CODICE,
|
||||||
|
DESCR,
|
||||||
|
UDC,
|
||||||
|
Qta,
|
||||||
|
NUMDOC,
|
||||||
|
DATDOC,
|
||||||
|
ID,
|
||||||
|
DESCRDEST,
|
||||||
|
StatoDocumento,
|
||||||
|
Expr1,
|
||||||
|
NAZIONE
|
||||||
|
FROM dbo.py_vPreparaPackingListSAMA1
|
||||||
|
WHERE NUMLOT <> '';
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER VIEW [dbo].[py_XMag_ViewPackingListStorico]
|
||||||
|
AS
|
||||||
|
SELECT TOP (100000)
|
||||||
|
prep.UDC AS Pallet,
|
||||||
|
prep.NUMLOT AS Lotto,
|
||||||
|
prep.CODICE AS Articolo,
|
||||||
|
prep.DESCR AS Descrizione,
|
||||||
|
prep.Qta,
|
||||||
|
prep.NUMDOC AS Documento,
|
||||||
|
prep.DATDOC AS DataDocumento,
|
||||||
|
prep.StatoDocumento,
|
||||||
|
prep.Expr1 AS CodNazione,
|
||||||
|
prep.NAZIONE,
|
||||||
|
CASE
|
||||||
|
WHEN prep.Expr1 = 'DE' THEN 10
|
||||||
|
WHEN prep.Expr1 = 'TH' THEN
|
||||||
|
CASE WHEN SUBSTRING(prep.DESCRDEST, 1, 2) = 'NA' THEN 11 ELSE 13 END
|
||||||
|
WHEN prep.Expr1 = 'MEX' THEN 12
|
||||||
|
ELSE 4
|
||||||
|
END AS Stato,
|
||||||
|
ISNULL(g.NumeroPallet, 0) AS PalletCella,
|
||||||
|
ISNULL(g.IDMagazzino, 1) AS Magazzino,
|
||||||
|
ISNULL(g.IDArea, 5) AS Area,
|
||||||
|
ISNULL(g.IDCella, 1000) AS Cella,
|
||||||
|
ISNULL(c.Ordinamento, 99999) AS Ordinamento,
|
||||||
|
ISNULL(c.Corsia + ' - ' + c.Colonna + ' - ' + c.Fila, 'Non scaff.') AS Ubicazione,
|
||||||
|
SUBSTRING(prep.DESCRDEST, 1, 2) AS DEST,
|
||||||
|
CASE
|
||||||
|
WHEN MAX(CASE
|
||||||
|
WHEN pr.Documento IS NOT NULL
|
||||||
|
AND pr.Documento = CAST(prep.NUMDOC AS varchar(8))
|
||||||
|
THEN 1 ELSE 0 END) = 1
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END AS IDStato
|
||||||
|
FROM dbo.Celle c
|
||||||
|
INNER JOIN dbo.XMag_GiacenzaPallet g
|
||||||
|
ON c.ID = g.IDCella
|
||||||
|
RIGHT OUTER JOIN dbo.py_vPreparaPackingList prep
|
||||||
|
ON g.BarcodePallet COLLATE SQL_Latin1_General_CP1_CI_AS = prep.UDC
|
||||||
|
LEFT JOIN dbo.PyPickingListReservation pr
|
||||||
|
ON pr.ID = 1
|
||||||
|
AND NULLIF(LTRIM(RTRIM(pr.Documento)), '') IS NOT NULL
|
||||||
|
GROUP BY
|
||||||
|
prep.Expr1,
|
||||||
|
prep.NAZIONE,
|
||||||
|
prep.UDC,
|
||||||
|
prep.NUMDOC,
|
||||||
|
prep.DATDOC,
|
||||||
|
prep.StatoDocumento,
|
||||||
|
prep.NUMLOT,
|
||||||
|
prep.CODICE,
|
||||||
|
prep.DESCR,
|
||||||
|
prep.Qta,
|
||||||
|
g.NumeroPallet,
|
||||||
|
g.IDMagazzino,
|
||||||
|
g.IDArea,
|
||||||
|
g.IDCella,
|
||||||
|
c.Ordinamento,
|
||||||
|
c.Corsia,
|
||||||
|
c.Colonna,
|
||||||
|
c.Fila,
|
||||||
|
prep.DESCRDEST;
|
||||||
|
GO
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
5. Tabella salta UDC barcode picking list
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
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) COLLATE Latin1_General_CI_AS NOT NULL,
|
||||||
|
Pallet varchar(50) COLLATE Latin1_General_CI_AS 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;
|
||||||
|
GO
|
||||||
|
|
||||||
|
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;
|
||||||
|
GO
|
||||||
|
|
||||||
|
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;
|
||||||
|
GO
|
||||||
|
|
||||||
|
PRINT 'Patch cumulativa Python WMS completata.';
|
||||||
|
GO
|
||||||
@@ -10,9 +10,13 @@ cross-loop errors.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import inspect
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
@@ -22,6 +26,59 @@ from version_info import module_version
|
|||||||
|
|
||||||
__version__ = module_version(__name__)
|
__version__ = module_version(__name__)
|
||||||
|
|
||||||
|
QUERY_PROFILER_LOG = Path(__file__).with_name("warehouse_query_profiler.log")
|
||||||
|
QUERY_PROFILER_CONFIG_PATH = Path(__file__).with_name("db_connection.json")
|
||||||
|
|
||||||
|
|
||||||
|
def _load_query_profiler_config() -> dict[str, Any]:
|
||||||
|
"""Read profiler settings from db_connection.json, with env overrides."""
|
||||||
|
|
||||||
|
config: dict[str, Any] = {
|
||||||
|
"enabled": False,
|
||||||
|
"slow_ms": 0,
|
||||||
|
"sql_limit": 4000,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
data = json.loads(QUERY_PROFILER_CONFIG_PATH.read_text(encoding="utf-8"))
|
||||||
|
section = data.get("query_profiler") if isinstance(data, dict) else None
|
||||||
|
if isinstance(section, dict):
|
||||||
|
config.update(section)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if "WAREHOUSE_QUERY_PROFILER" in os.environ:
|
||||||
|
config["enabled"] = os.environ.get("WAREHOUSE_QUERY_PROFILER", "1").strip().lower() not in {
|
||||||
|
"0",
|
||||||
|
"false",
|
||||||
|
"no",
|
||||||
|
"off",
|
||||||
|
}
|
||||||
|
if "WAREHOUSE_QUERY_PROFILER_SLOW_MS" in os.environ:
|
||||||
|
config["slow_ms"] = os.environ.get("WAREHOUSE_QUERY_PROFILER_SLOW_MS", "0")
|
||||||
|
if "WAREHOUSE_QUERY_PROFILER_SQL_LIMIT" in os.environ:
|
||||||
|
config["sql_limit"] = os.environ.get("WAREHOUSE_QUERY_PROFILER_SQL_LIMIT", "4000")
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def _query_profiler_enabled() -> bool:
|
||||||
|
value = _load_query_profiler_config().get("enabled", False)
|
||||||
|
if isinstance(value, str):
|
||||||
|
return value.strip().lower() not in {"0", "false", "no", "off"}
|
||||||
|
return bool(value)
|
||||||
|
|
||||||
|
|
||||||
|
def _query_profiler_slow_ms() -> float:
|
||||||
|
try:
|
||||||
|
return float(_load_query_profiler_config().get("slow_ms", 0) or 0)
|
||||||
|
except Exception:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
|
def _query_profiler_sql_limit() -> int:
|
||||||
|
try:
|
||||||
|
return int(_load_query_profiler_config().get("sql_limit", 4000) or 4000)
|
||||||
|
except Exception:
|
||||||
|
return 4000
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pyodbc
|
import pyodbc
|
||||||
|
|
||||||
@@ -76,6 +133,83 @@ def make_mssql_dsn(
|
|||||||
return f"mssql+aioodbc:///?odbc_connect={urllib.parse.quote_plus(odbc)}"
|
return f"mssql+aioodbc:///?odbc_connect={urllib.parse.quote_plus(odbc)}"
|
||||||
|
|
||||||
|
|
||||||
|
def _compact_sql(sql: str, *, limit: int | None = None) -> str:
|
||||||
|
"""Collapse SQL whitespace so profiler entries stay readable."""
|
||||||
|
|
||||||
|
if limit is None:
|
||||||
|
limit = _query_profiler_sql_limit()
|
||||||
|
text_value = " ".join(str(sql or "").split())
|
||||||
|
if limit > 0 and len(text_value) > limit:
|
||||||
|
return text_value[:limit] + "...<truncated>"
|
||||||
|
return text_value
|
||||||
|
|
||||||
|
|
||||||
|
def _profile_params(params: Optional[Dict[str, Any]]) -> str:
|
||||||
|
"""Serialize SQL parameters for diagnostics."""
|
||||||
|
|
||||||
|
if not params:
|
||||||
|
return "{}"
|
||||||
|
try:
|
||||||
|
return _dumps(params)
|
||||||
|
except Exception:
|
||||||
|
return repr(params)
|
||||||
|
|
||||||
|
|
||||||
|
def _query_caller() -> str:
|
||||||
|
"""Return the first external Python frame that triggered the DB call."""
|
||||||
|
|
||||||
|
current_file = Path(__file__).resolve()
|
||||||
|
for frame in inspect.stack(context=0)[2:]:
|
||||||
|
try:
|
||||||
|
frame_file = Path(frame.filename).resolve()
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
if frame_file == current_file:
|
||||||
|
continue
|
||||||
|
return f"{frame_file.name}:{frame.lineno}:{frame.function}"
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def _append_query_profile(
|
||||||
|
*,
|
||||||
|
method: str,
|
||||||
|
elapsed_ms: float,
|
||||||
|
rows: int | None,
|
||||||
|
rowcount: int | None,
|
||||||
|
commit: bool,
|
||||||
|
ok: bool,
|
||||||
|
sql: str,
|
||||||
|
params: Optional[Dict[str, Any]],
|
||||||
|
caller: str,
|
||||||
|
error: str = "",
|
||||||
|
) -> None:
|
||||||
|
"""Append one query timing line to the local profiler log."""
|
||||||
|
|
||||||
|
if not _query_profiler_enabled():
|
||||||
|
return
|
||||||
|
slow_ms = _query_profiler_slow_ms()
|
||||||
|
if ok and slow_ms > 0 and elapsed_ms < slow_ms:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
row_info = f"rows={rows}" if rows is not None else f"rowcount={rowcount}"
|
||||||
|
lines = [
|
||||||
|
(
|
||||||
|
f"{timestamp} | {elapsed_ms:.3f} ms | {method} | "
|
||||||
|
f"{row_info} | commit={int(commit)} | ok={int(ok)} | caller={caller}"
|
||||||
|
),
|
||||||
|
f"PARAMS: {_profile_params(params)}",
|
||||||
|
f"SQL: {_compact_sql(sql)}",
|
||||||
|
]
|
||||||
|
if error:
|
||||||
|
lines.append(f"ERROR: {error}")
|
||||||
|
with QUERY_PROFILER_LOG.open("a", encoding="utf-8") as handle:
|
||||||
|
handle.write("\n".join(lines) + "\n---\n")
|
||||||
|
except Exception:
|
||||||
|
# Profiling must never interfere with warehouse operations.
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AsyncMSSQLClient:
|
class AsyncMSSQLClient:
|
||||||
"""Thin async query client for SQL Server.
|
"""Thin async query client for SQL Server.
|
||||||
|
|
||||||
@@ -152,23 +286,83 @@ class AsyncMSSQLClient:
|
|||||||
"""
|
"""
|
||||||
await self._ensure_engine()
|
await self._ensure_engine()
|
||||||
t0 = time.perf_counter()
|
t0 = time.perf_counter()
|
||||||
|
caller = _query_caller()
|
||||||
|
try:
|
||||||
async with (self._engine.begin() if commit else self._engine.connect()) as conn:
|
async with (self._engine.begin() if commit else self._engine.connect()) as conn:
|
||||||
res = await conn.execute(text(sql), params or {})
|
res = await conn.execute(text(sql), params or {})
|
||||||
rows = res.fetchall()
|
rows = res.fetchall()
|
||||||
cols = list(res.keys())
|
cols = list(res.keys())
|
||||||
|
except Exception as exc:
|
||||||
|
elapsed_ms = round((time.perf_counter() - t0) * 1000, 3)
|
||||||
|
_append_query_profile(
|
||||||
|
method="query_json",
|
||||||
|
elapsed_ms=elapsed_ms,
|
||||||
|
rows=None,
|
||||||
|
rowcount=None,
|
||||||
|
commit=commit,
|
||||||
|
ok=False,
|
||||||
|
sql=sql,
|
||||||
|
params=params,
|
||||||
|
caller=caller,
|
||||||
|
error=repr(exc),
|
||||||
|
)
|
||||||
|
raise
|
||||||
if as_dict_rows:
|
if as_dict_rows:
|
||||||
rows_out = [dict(zip(cols, row)) for row in rows]
|
rows_out = [dict(zip(cols, row)) for row in rows]
|
||||||
else:
|
else:
|
||||||
rows_out = [list(row) for row in rows]
|
rows_out = [list(row) for row in rows]
|
||||||
|
elapsed_ms = round((time.perf_counter() - t0) * 1000, 3)
|
||||||
|
_append_query_profile(
|
||||||
|
method="query_json",
|
||||||
|
elapsed_ms=elapsed_ms,
|
||||||
|
rows=len(rows_out),
|
||||||
|
rowcount=None,
|
||||||
|
commit=commit,
|
||||||
|
ok=True,
|
||||||
|
sql=sql,
|
||||||
|
params=params,
|
||||||
|
caller=caller,
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
"columns": cols,
|
"columns": cols,
|
||||||
"rows": rows_out,
|
"rows": rows_out,
|
||||||
"elapsed_ms": round((time.perf_counter() - t0) * 1000, 3),
|
"elapsed_ms": elapsed_ms,
|
||||||
}
|
}
|
||||||
|
|
||||||
async def exec(self, sql: str, params: Optional[Dict[str, Any]] = None, *, commit: bool = False) -> int:
|
async def exec(self, sql: str, params: Optional[Dict[str, Any]] = None, *, commit: bool = False) -> int:
|
||||||
"""Execute a DML statement and return its row count."""
|
"""Execute a DML statement and return its row count."""
|
||||||
await self._ensure_engine()
|
await self._ensure_engine()
|
||||||
|
t0 = time.perf_counter()
|
||||||
|
caller = _query_caller()
|
||||||
|
try:
|
||||||
async with (self._engine.begin() if commit else self._engine.connect()) as conn:
|
async with (self._engine.begin() if commit else self._engine.connect()) as conn:
|
||||||
res = await conn.execute(text(sql), params or {})
|
res = await conn.execute(text(sql), params or {})
|
||||||
return res.rowcount or 0
|
rowcount = res.rowcount or 0
|
||||||
|
except Exception as exc:
|
||||||
|
elapsed_ms = round((time.perf_counter() - t0) * 1000, 3)
|
||||||
|
_append_query_profile(
|
||||||
|
method="exec",
|
||||||
|
elapsed_ms=elapsed_ms,
|
||||||
|
rows=None,
|
||||||
|
rowcount=None,
|
||||||
|
commit=commit,
|
||||||
|
ok=False,
|
||||||
|
sql=sql,
|
||||||
|
params=params,
|
||||||
|
caller=caller,
|
||||||
|
error=repr(exc),
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
elapsed_ms = round((time.perf_counter() - t0) * 1000, 3)
|
||||||
|
_append_query_profile(
|
||||||
|
method="exec",
|
||||||
|
elapsed_ms=elapsed_ms,
|
||||||
|
rows=None,
|
||||||
|
rowcount=rowcount,
|
||||||
|
commit=commit,
|
||||||
|
ok=True,
|
||||||
|
sql=sql,
|
||||||
|
params=params,
|
||||||
|
caller=caller,
|
||||||
|
)
|
||||||
|
return rowcount
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ class BarcodeClientApp:
|
|||||||
self._auto_advance_id: str | None = None
|
self._auto_advance_id: str | None = None
|
||||||
self._pallet_auto_focus_id: str | None = None
|
self._pallet_auto_focus_id: str | None = None
|
||||||
self._paused_queue_id: int | None = None
|
self._paused_queue_id: int | None = None
|
||||||
|
self._paused_priority_state: BarcodeViewState | None = None
|
||||||
|
self._pallet_user_input_serial = 0
|
||||||
|
self._priority_loaded_input_serial = 0
|
||||||
|
self._priority_expected_pallet = ""
|
||||||
self._status_colors = {
|
self._status_colors = {
|
||||||
"red": "#f4cccc",
|
"red": "#f4cccc",
|
||||||
"green": "#d9ead3",
|
"green": "#d9ead3",
|
||||||
@@ -237,16 +241,20 @@ class BarcodeClientApp:
|
|||||||
parent.columnconfigure(1, weight=1)
|
parent.columnconfigure(1, weight=1)
|
||||||
if scanned:
|
if scanned:
|
||||||
self.pallet_entry = entry
|
self.pallet_entry = entry
|
||||||
|
self.pallet_entry.bind("<KeyPress>", self._on_pallet_keypress, add="+")
|
||||||
self.scanned_var.trace_add("write", lambda *_: self._on_scanned_var_changed())
|
self.scanned_var.trace_add("write", lambda *_: self._on_scanned_var_changed())
|
||||||
else:
|
else:
|
||||||
self.destination_entry = entry
|
self.destination_entry = entry
|
||||||
self.destination_var.trace_add("write", lambda *_: self._limit_var(self.destination_var, 8))
|
self.destination_var.trace_add("write", lambda *_: self._on_destination_var_changed())
|
||||||
|
|
||||||
def _limit_var(self, variable: tk.StringVar, max_len: int) -> None:
|
def _limit_var(self, variable: tk.StringVar, max_len: int) -> None:
|
||||||
value = str(variable.get() or "")
|
value = str(variable.get() or "")
|
||||||
if len(value) > max_len:
|
if len(value) > max_len:
|
||||||
variable.set(value[:max_len])
|
variable.set(value[:max_len])
|
||||||
|
|
||||||
|
def _on_pallet_keypress(self, _event=None) -> None:
|
||||||
|
self._pallet_user_input_serial += 1
|
||||||
|
|
||||||
def _on_scanned_var_changed(self) -> None:
|
def _on_scanned_var_changed(self) -> None:
|
||||||
self._limit_var(self.scanned_var, 8)
|
self._limit_var(self.scanned_var, 8)
|
||||||
if self._pallet_auto_focus_id is not None:
|
if self._pallet_auto_focus_id is not None:
|
||||||
@@ -260,6 +268,10 @@ class BarcodeClientApp:
|
|||||||
return
|
return
|
||||||
self._pallet_auto_focus_id = self.root.after(80, self._auto_focus_destination_after_scan)
|
self._pallet_auto_focus_id = self.root.after(80, self._auto_focus_destination_after_scan)
|
||||||
|
|
||||||
|
def _on_destination_var_changed(self) -> None:
|
||||||
|
self._limit_var(self.destination_var, 8)
|
||||||
|
self._refresh_action_labels()
|
||||||
|
|
||||||
def _auto_focus_destination_after_scan(self) -> None:
|
def _auto_focus_destination_after_scan(self) -> None:
|
||||||
self._pallet_auto_focus_id = None
|
self._pallet_auto_focus_id = None
|
||||||
pallet = str(self.scanned_var.get() or "").strip()
|
pallet = str(self.scanned_var.get() or "").strip()
|
||||||
@@ -269,6 +281,11 @@ class BarcodeClientApp:
|
|||||||
return
|
return
|
||||||
if getattr(self.service.state, "mode", "") == "confirm":
|
if getattr(self.service.state, "mode", "") == "confirm":
|
||||||
return
|
return
|
||||||
|
if getattr(self.service.state, "mode", "") in ("priority_high", "priority_low"):
|
||||||
|
expected = str(getattr(self.service.state, "expected_pallet", "") or "").strip()
|
||||||
|
if expected and pallet == expected and self._is_fresh_priority_scan(expected):
|
||||||
|
self._submit()
|
||||||
|
return
|
||||||
if bool(getattr(self.service.state, "destination_readonly", False)):
|
if bool(getattr(self.service.state, "destination_readonly", False)):
|
||||||
return
|
return
|
||||||
self._focus_destination_input()
|
self._focus_destination_input()
|
||||||
@@ -371,7 +388,9 @@ class BarcodeClientApp:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self._pallet_auto_focus_id = None
|
self._pallet_auto_focus_id = None
|
||||||
self.queue_var.set(state.queue_label)
|
pause_context = self._paused_queue_id is not None and state.mode not in ("priority_high", "priority_low")
|
||||||
|
effective_queue_label = "Pausa PL" if pause_context else state.queue_label
|
||||||
|
self.queue_var.set(effective_queue_label)
|
||||||
self.destination_var.set(state.destination_barcode)
|
self.destination_var.set(state.destination_barcode)
|
||||||
self.scanned_var.set(state.scanned_pallet)
|
self.scanned_var.set(state.scanned_pallet)
|
||||||
self.info1_var.set(self._status_text_with_wait_hint(state))
|
self.info1_var.set(self._status_text_with_wait_hint(state))
|
||||||
@@ -380,25 +399,28 @@ class BarcodeClientApp:
|
|||||||
self.info4_var.set(state.expected_pallet)
|
self.info4_var.set(state.expected_pallet)
|
||||||
self.status_band.configure(bg=state.status_color or self._status_colors["red"])
|
self.status_band.configure(bg=state.status_color or self._status_colors["red"])
|
||||||
|
|
||||||
|
if state.mode in ("priority_high", "priority_low"):
|
||||||
|
self._priority_loaded_input_serial = self._pallet_user_input_serial
|
||||||
|
self._priority_expected_pallet = str(state.expected_pallet or "").strip()
|
||||||
|
else:
|
||||||
|
self._priority_expected_pallet = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if str(state.queue_label or "") != "Pausa PL":
|
if str(effective_queue_label or "") != "Pausa PL":
|
||||||
self._paused_queue_id = None
|
self._paused_queue_id = None
|
||||||
resumable_queue = self._resumable_queue_from_state(state)
|
resumable_queue = self._resumable_queue_from_state(state)
|
||||||
if state.mode in ("priority_high", "priority_low") or resumable_queue is not None:
|
if state.mode in ("priority_high", "priority_low") or resumable_queue is not None:
|
||||||
self.btn_submit.configure(text="[F3] Pausa PL")
|
self.btn_submit.configure(text="[F3] Pausa PL")
|
||||||
else:
|
else:
|
||||||
self.btn_submit.configure(text="[F3] Carica")
|
self.btn_submit.configure(text="[F3] Carica")
|
||||||
if state.mode in ("priority_high", "priority_low"):
|
self._refresh_action_labels(state)
|
||||||
self.btn_unload.configure(text="[F4] Salta UDC")
|
queue_buttons_state = "disabled" if str(effective_queue_label or "") == "Pausa PL" else "normal"
|
||||||
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_f1.configure(state=queue_buttons_state)
|
||||||
self.btn_f2.configure(state=queue_buttons_state)
|
self.btn_f2.configure(state=queue_buttons_state)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
destination_readonly = bool(getattr(state, "destination_readonly", False))
|
destination_readonly = False if pause_context else bool(getattr(state, "destination_readonly", False))
|
||||||
try:
|
try:
|
||||||
self.destination_entry.configure(state="normal")
|
self.destination_entry.configure(state="normal")
|
||||||
if destination_readonly:
|
if destination_readonly:
|
||||||
@@ -419,6 +441,22 @@ class BarcodeClientApp:
|
|||||||
else:
|
else:
|
||||||
self.root.after(20, self._focus_primary_input)
|
self.root.after(20, self._focus_primary_input)
|
||||||
|
|
||||||
|
def _refresh_action_labels(self, state: BarcodeViewState | None = None) -> None:
|
||||||
|
current_state = state or self.service.state
|
||||||
|
try:
|
||||||
|
if current_state.mode in ("priority_high", "priority_low"):
|
||||||
|
self.btn_unload.configure(text="[F4] Salta UDC")
|
||||||
|
return
|
||||||
|
destination = str(self.destination_var.get() or "").strip()
|
||||||
|
if destination == self.NON_SCAFFALATA_BARCODE:
|
||||||
|
self.btn_unload.configure(text="[F4] Non scaff.")
|
||||||
|
elif destination:
|
||||||
|
self.btn_unload.configure(text="[F4] Dissocia")
|
||||||
|
else:
|
||||||
|
self.btn_unload.configure(text="[F4] Scarica")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def _focus_primary_input(self) -> None:
|
def _focus_primary_input(self) -> None:
|
||||||
try:
|
try:
|
||||||
self.pallet_entry.focus_force()
|
self.pallet_entry.focus_force()
|
||||||
@@ -448,6 +486,14 @@ class BarcodeClientApp:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _is_fresh_priority_scan(self, expected: str) -> bool:
|
||||||
|
mode = str(getattr(self.service.state, "mode", "") or "")
|
||||||
|
if mode not in ("priority_high", "priority_low"):
|
||||||
|
return False
|
||||||
|
if str(expected or "").strip() != self._priority_expected_pallet:
|
||||||
|
return False
|
||||||
|
return self._pallet_user_input_serial > self._priority_loaded_input_serial
|
||||||
|
|
||||||
def _on_pallet_enter(self, _event=None) -> str:
|
def _on_pallet_enter(self, _event=None) -> str:
|
||||||
pallet = str(self.scanned_var.get() or "").strip()
|
pallet = str(self.scanned_var.get() or "").strip()
|
||||||
destination = str(self.destination_var.get() or "").strip()
|
destination = str(self.destination_var.get() or "").strip()
|
||||||
@@ -455,6 +501,14 @@ class BarcodeClientApp:
|
|||||||
return "break"
|
return "break"
|
||||||
if destination in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE):
|
if destination in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE):
|
||||||
if bool(getattr(self.service.state, "destination_readonly", False)):
|
if bool(getattr(self.service.state, "destination_readonly", False)):
|
||||||
|
mode = str(getattr(self.service.state, "mode", "") or "")
|
||||||
|
if mode in ("priority_high", "priority_low"):
|
||||||
|
expected = str(getattr(self.service.state, "expected_pallet", "") or "").strip()
|
||||||
|
if expected and pallet == expected and self._is_fresh_priority_scan(expected):
|
||||||
|
self._submit()
|
||||||
|
else:
|
||||||
|
self._focus_primary_input()
|
||||||
|
else:
|
||||||
self._submit()
|
self._submit()
|
||||||
else:
|
else:
|
||||||
self._focus_destination_input()
|
self._focus_destination_input()
|
||||||
@@ -465,11 +519,12 @@ class BarcodeClientApp:
|
|||||||
|
|
||||||
def _on_destination_enter(self, _event=None) -> str:
|
def _on_destination_enter(self, _event=None) -> str:
|
||||||
pallet = str(self.scanned_var.get() or "").strip()
|
pallet = str(self.scanned_var.get() or "").strip()
|
||||||
destination = str(self.destination_var.get() or "").strip()
|
if not pallet:
|
||||||
if pallet and destination:
|
|
||||||
self._submit()
|
|
||||||
else:
|
|
||||||
self._focus_primary_input()
|
self._focus_primary_input()
|
||||||
|
else:
|
||||||
|
self.info1_var.set("F3 per associare, F4 per disassociare")
|
||||||
|
self.status_band.configure(bg=self._status_colors["yellow"])
|
||||||
|
self._focus_destination_input()
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
def _on_unload_key(self, _event=None) -> str:
|
def _on_unload_key(self, _event=None) -> str:
|
||||||
@@ -478,6 +533,12 @@ class BarcodeClientApp:
|
|||||||
|
|
||||||
def _on_escape_key(self, _event=None) -> str:
|
def _on_escape_key(self, _event=None) -> str:
|
||||||
if self._is_priority_pause() and self._paused_queue_id is not None:
|
if self._is_priority_pause() and self._paused_queue_id is not None:
|
||||||
|
if self._paused_priority_state is not None:
|
||||||
|
state = self.service.resume_priority_state(self._paused_priority_state)
|
||||||
|
self._paused_priority_state = None
|
||||||
|
self._paused_queue_id = None
|
||||||
|
self._apply_state(state)
|
||||||
|
return "break"
|
||||||
self._start_queue(self._paused_queue_id, allow_during_pause=True)
|
self._start_queue(self._paused_queue_id, allow_during_pause=True)
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
@@ -489,15 +550,18 @@ class BarcodeClientApp:
|
|||||||
mode = getattr(self.service.state, "mode", "")
|
mode = getattr(self.service.state, "mode", "")
|
||||||
if mode == "priority_high":
|
if mode == "priority_high":
|
||||||
self._paused_queue_id = 1
|
self._paused_queue_id = 1
|
||||||
|
self._paused_priority_state = self.service.state
|
||||||
self._apply_state(self.service.begin_priority_pause(1))
|
self._apply_state(self.service.begin_priority_pause(1))
|
||||||
return
|
return
|
||||||
if mode == "priority_low":
|
if mode == "priority_low":
|
||||||
self._paused_queue_id = 0
|
self._paused_queue_id = 0
|
||||||
|
self._paused_priority_state = self.service.state
|
||||||
self._apply_state(self.service.begin_priority_pause(0))
|
self._apply_state(self.service.begin_priority_pause(0))
|
||||||
return
|
return
|
||||||
resumable_queue = self._resumable_queue_from_state(self.service.state)
|
resumable_queue = self._resumable_queue_from_state(self.service.state)
|
||||||
if resumable_queue is not None:
|
if resumable_queue is not None:
|
||||||
self._paused_queue_id = resumable_queue
|
self._paused_queue_id = resumable_queue
|
||||||
|
self._paused_priority_state = None
|
||||||
self._apply_state(self.service.begin_priority_pause(resumable_queue))
|
self._apply_state(self.service.begin_priority_pause(resumable_queue))
|
||||||
return
|
return
|
||||||
self._submit()
|
self._submit()
|
||||||
@@ -510,6 +574,9 @@ class BarcodeClientApp:
|
|||||||
self._skip_current_picking_pallet()
|
self._skip_current_picking_pallet()
|
||||||
return
|
return
|
||||||
if pallet:
|
if pallet:
|
||||||
|
if destination == self.NON_SCAFFALATA_BARCODE:
|
||||||
|
self._submit()
|
||||||
|
else:
|
||||||
self._submit_unload_with_source_check()
|
self._submit_unload_with_source_check()
|
||||||
return
|
return
|
||||||
if self._is_priority_pause():
|
if self._is_priority_pause():
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ WHERE Ordinamento > 0
|
|||||||
AND NOT EXISTS (
|
AND NOT EXISTS (
|
||||||
SELECT 1
|
SELECT 1
|
||||||
FROM dbo.py_BarcodePickingListSkip AS s
|
FROM dbo.py_BarcodePickingListSkip AS s
|
||||||
WHERE s.Documento = CAST(pl.Documento AS varchar(50))
|
WHERE s.Documento COLLATE Latin1_General_CI_AS =
|
||||||
AND s.Pallet = CAST(pl.Pallet AS varchar(50))
|
CAST(pl.Documento AS varchar(50)) COLLATE Latin1_General_CI_AS
|
||||||
|
AND s.Pallet COLLATE Latin1_General_CI_AS =
|
||||||
|
CAST(pl.Pallet AS varchar(50)) COLLATE Latin1_General_CI_AS
|
||||||
AND s.IDStato = pl.IDStato
|
AND s.IDStato = pl.IDStato
|
||||||
AND s.Risolto = 0
|
AND s.Risolto = 0
|
||||||
)
|
)
|
||||||
@@ -52,7 +54,7 @@ SELECT TOP (1)
|
|||||||
Ordinamento,
|
Ordinamento,
|
||||||
IDStato
|
IDStato
|
||||||
FROM dbo.py_XMag_ViewPackingList
|
FROM dbo.py_XMag_ViewPackingList
|
||||||
WHERE Pallet = :pallet
|
WHERE Pallet COLLATE Latin1_General_CI_AS = :pallet COLLATE Latin1_General_CI_AS
|
||||||
ORDER BY Ordinamento;
|
ORDER BY Ordinamento;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ SELECT TOP (1)
|
|||||||
Prodotto,
|
Prodotto,
|
||||||
Descrizione
|
Descrizione
|
||||||
FROM dbo.vXTracciaProdotti
|
FROM dbo.vXTracciaProdotti
|
||||||
WHERE Pallet = :pallet
|
WHERE Pallet COLLATE Latin1_General_CI_AS = :pallet COLLATE Latin1_General_CI_AS
|
||||||
ORDER BY Lotto;
|
ORDER BY Lotto;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -77,7 +79,7 @@ SELECT TOP (1)
|
|||||||
FROM dbo.XMag_GiacenzaPallet AS g
|
FROM dbo.XMag_GiacenzaPallet AS g
|
||||||
LEFT JOIN dbo.Celle AS c
|
LEFT JOIN dbo.Celle AS c
|
||||||
ON c.ID = g.IDCella
|
ON c.ID = g.IDCella
|
||||||
WHERE g.BarcodePallet = :pallet;
|
WHERE g.BarcodePallet COLLATE Latin1_General_CI_AS = :pallet COLLATE Latin1_General_CI_AS;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SQL_OPEN_LOCATIONS_BY_PALLET = """
|
SQL_OPEN_LOCATIONS_BY_PALLET = """
|
||||||
@@ -90,7 +92,7 @@ SELECT
|
|||||||
FROM dbo.XMag_GiacenzaPallet AS g
|
FROM dbo.XMag_GiacenzaPallet AS g
|
||||||
LEFT JOIN dbo.Celle AS c
|
LEFT JOIN dbo.Celle AS c
|
||||||
ON c.ID = g.IDCella
|
ON c.ID = g.IDCella
|
||||||
WHERE g.BarcodePallet = :pallet
|
WHERE g.BarcodePallet COLLATE Latin1_General_CI_AS = :pallet COLLATE Latin1_General_CI_AS
|
||||||
ORDER BY g.IDCella;
|
ORDER BY g.IDCella;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -103,6 +105,34 @@ WHERE g.IDCella = :id_cella
|
|||||||
ORDER BY g.BarcodePallet;
|
ORDER BY g.BarcodePallet;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
SQL_CLOSED_PICKING_BY_PALLET = """
|
||||||
|
SELECT TOP (1)
|
||||||
|
g.BarcodePallet,
|
||||||
|
g.NumeroPallet,
|
||||||
|
g.IDMagazzino,
|
||||||
|
g.IDArea,
|
||||||
|
g.IDCella,
|
||||||
|
g.IDStato
|
||||||
|
FROM dbo.XMag_GiacenzaPallet AS g
|
||||||
|
WHERE g.IDCella <> 9999
|
||||||
|
AND g.BarcodePallet COLLATE Latin1_General_CI_AS = :pallet COLLATE Latin1_General_CI_AS
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM SAMA1.dbo.LOTSER AS ls
|
||||||
|
INNER JOIN SAMA1.dbo.LOTTIBF AS lb
|
||||||
|
ON lb.IDLOTSER = ls.ID
|
||||||
|
INNER JOIN SAMA1.dbo.FATRIG AS fr
|
||||||
|
ON lb.IDFATRIG = fr.ID
|
||||||
|
INNER JOIN SAMA1.dbo.BAMTES AS bt
|
||||||
|
ON bt.ID = fr.IDBAM
|
||||||
|
WHERE bt.ANNDOC >= 2011
|
||||||
|
AND bt.STATO = 'D'
|
||||||
|
AND LEFT(ls.NUMSER, 6) COLLATE Latin1_General_CI_AS =
|
||||||
|
:pallet COLLATE Latin1_General_CI_AS
|
||||||
|
)
|
||||||
|
ORDER BY g.IDCella DESC;
|
||||||
|
"""
|
||||||
|
|
||||||
SQL_RESOLVE_PHYSICAL_CELL = """
|
SQL_RESOLVE_PHYSICAL_CELL = """
|
||||||
DECLARE @raw int = TRY_CONVERT(int, :destination);
|
DECLARE @raw int = TRY_CONVERT(int, :destination);
|
||||||
DECLARE @cell_id int =
|
DECLARE @cell_id int =
|
||||||
@@ -127,6 +157,7 @@ SQL_LEGACY_MOVE = """
|
|||||||
SET NOCOUNT ON;
|
SET NOCOUNT ON;
|
||||||
SET XACT_ABORT ON;
|
SET XACT_ABORT ON;
|
||||||
DECLARE @RC int = 0;
|
DECLARE @RC int = 0;
|
||||||
|
DECLARE @RefreshPickingReservation bit = :refresh_picking_reservation;
|
||||||
|
|
||||||
EXEC dbo.sp_xMagGestioneMagazziniPallet
|
EXEC dbo.sp_xMagGestioneMagazziniPallet
|
||||||
@IDOperatore = :id_operatore,
|
@IDOperatore = :id_operatore,
|
||||||
@@ -135,7 +166,10 @@ EXEC dbo.sp_xMagGestioneMagazziniPallet
|
|||||||
@NumeroCella = :numero_cella,
|
@NumeroCella = :numero_cella,
|
||||||
@RC = @RC OUTPUT;
|
@RC = @RC OUTPUT;
|
||||||
|
|
||||||
|
IF @RefreshPickingReservation = 1
|
||||||
|
BEGIN
|
||||||
EXEC dbo.py_sp_ControllaPrenotazionePackingListPalletNew;
|
EXEC dbo.py_sp_ControllaPrenotazionePackingListPalletNew;
|
||||||
|
END;
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
@RC AS RC,
|
@RC AS RC,
|
||||||
@@ -151,7 +185,7 @@ IF NOT EXISTS (
|
|||||||
SELECT 1
|
SELECT 1
|
||||||
FROM dbo.py_BarcodePickingListSkip
|
FROM dbo.py_BarcodePickingListSkip
|
||||||
WHERE Documento = :documento
|
WHERE Documento = :documento
|
||||||
AND Pallet = :pallet
|
AND Pallet COLLATE Latin1_General_CI_AS = :pallet COLLATE Latin1_General_CI_AS
|
||||||
AND IDStato = :id_stato
|
AND IDStato = :id_stato
|
||||||
AND Risolto = 0
|
AND Risolto = 0
|
||||||
)
|
)
|
||||||
@@ -182,6 +216,37 @@ SELECT
|
|||||||
:id_stato AS IDStato;
|
:id_stato AS IDStato;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
SQL_ACTIVE_SKIPPED_DOCUMENT = """
|
||||||
|
SELECT TOP (1)
|
||||||
|
s.Documento,
|
||||||
|
COUNT(*) AS SkippedCount
|
||||||
|
FROM dbo.py_BarcodePickingListSkip AS s
|
||||||
|
WHERE s.IDStato = :id_stato
|
||||||
|
AND s.Risolto = 0
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM dbo.py_ViewPackingListRestante AS pl
|
||||||
|
WHERE CAST(pl.Documento AS varchar(50)) COLLATE Latin1_General_CI_AS =
|
||||||
|
s.Documento COLLATE Latin1_General_CI_AS
|
||||||
|
AND pl.IDStato = :id_stato
|
||||||
|
)
|
||||||
|
GROUP BY s.Documento
|
||||||
|
ORDER BY MIN(s.DataOra);
|
||||||
|
"""
|
||||||
|
|
||||||
|
SQL_RELEASE_PICKING_DOCUMENT = """
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
DECLARE @RC int = 0;
|
||||||
|
|
||||||
|
EXEC dbo.py_sp_xExePackingListPallet
|
||||||
|
@IDOperatore = :id_operatore,
|
||||||
|
@Documento = :documento,
|
||||||
|
@Azione = 'S',
|
||||||
|
@RC = @RC OUTPUT;
|
||||||
|
|
||||||
|
SELECT CAST(@RC AS int) AS RC;
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def _rows_to_dicts(res: dict[str, Any] | None) -> list[dict[str, Any]]:
|
def _rows_to_dicts(res: dict[str, Any] | None) -> list[dict[str, Any]]:
|
||||||
"""Convert ``query_json`` payloads to a list of row dictionaries."""
|
"""Convert ``query_json`` payloads to a list of row dictionaries."""
|
||||||
@@ -265,6 +330,13 @@ class BarcodeRepository:
|
|||||||
res = await self.db_client.query_json(SQL_OPEN_PALLETS_BY_CELL, {"id_cella": int(id_cella)})
|
res = await self.db_client.query_json(SQL_OPEN_PALLETS_BY_CELL, {"id_cella": int(id_cella)})
|
||||||
return _rows_to_dicts(res)
|
return _rows_to_dicts(res)
|
||||||
|
|
||||||
|
async def fetch_closed_picking_by_pallet(self, pallet: str) -> dict[str, Any] | None:
|
||||||
|
"""Return a closed picking-list row for a pallet already considered shipped."""
|
||||||
|
|
||||||
|
res = await self.db_client.query_json(SQL_CLOSED_PICKING_BY_PALLET, {"pallet": str(pallet or "").strip()})
|
||||||
|
rows = _rows_to_dicts(res)
|
||||||
|
return rows[0] if rows else None
|
||||||
|
|
||||||
async def skip_picking_pallet(
|
async def skip_picking_pallet(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@@ -304,6 +376,35 @@ class BarcodeRepository:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def fetch_active_skipped_document(self, id_stato: int) -> dict[str, Any] | None:
|
||||||
|
"""Return a reserved document whose remaining pallets were all skipped."""
|
||||||
|
|
||||||
|
res = await self.db_client.query_json(SQL_ACTIVE_SKIPPED_DOCUMENT, {"id_stato": int(id_stato)})
|
||||||
|
rows = _rows_to_dicts(res)
|
||||||
|
return rows[0] if rows else None
|
||||||
|
|
||||||
|
async def release_picking_document(self, *, documento: str, operator_id: int) -> int:
|
||||||
|
"""Release a reserved picking-list document without closing its residual rows."""
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"documento": str(documento or "").strip(),
|
||||||
|
"id_operatore": int(operator_id),
|
||||||
|
}
|
||||||
|
log_runtime_event(
|
||||||
|
"Barcode WMS",
|
||||||
|
f"PICKING AUTO RELEASE START documento={params['documento']} operator={params['id_operatore']}",
|
||||||
|
)
|
||||||
|
res = await self.db_client.query_json(SQL_RELEASE_PICKING_DOCUMENT, params, as_dict_rows=True, commit=True)
|
||||||
|
rows = _rows_to_dicts(res)
|
||||||
|
rc = 0
|
||||||
|
if rows:
|
||||||
|
try:
|
||||||
|
rc = int(rows[0].get("RC") or 0)
|
||||||
|
except Exception:
|
||||||
|
rc = 0
|
||||||
|
log_runtime_event("Barcode WMS", f"PICKING AUTO RELEASE END documento={params['documento']} rc={rc}")
|
||||||
|
return rc
|
||||||
|
|
||||||
async def resolve_physical_cell(self, destination: str) -> DestinationCell | None:
|
async def resolve_physical_cell(self, destination: str) -> DestinationCell | None:
|
||||||
"""Accept either an internal cell ID or the scanned legacy cell barcode."""
|
"""Accept either an internal cell ID or the scanned legacy cell barcode."""
|
||||||
|
|
||||||
@@ -326,6 +427,7 @@ class BarcodeRepository:
|
|||||||
barcode_cella: str,
|
barcode_cella: str,
|
||||||
barcode_pallet: str,
|
barcode_pallet: str,
|
||||||
numero_cella: int,
|
numero_cella: int,
|
||||||
|
refresh_picking_reservation: bool = True,
|
||||||
) -> LegacyMoveResult:
|
) -> LegacyMoveResult:
|
||||||
"""Execute the same stored procedure used by the C# barcode form."""
|
"""Execute the same stored procedure used by the C# barcode form."""
|
||||||
|
|
||||||
@@ -334,6 +436,7 @@ class BarcodeRepository:
|
|||||||
"barcode_cella": str(barcode_cella or "").strip(),
|
"barcode_cella": str(barcode_cella or "").strip(),
|
||||||
"barcode_pallet": str(barcode_pallet or "").strip(),
|
"barcode_pallet": str(barcode_pallet or "").strip(),
|
||||||
"numero_cella": int(numero_cella),
|
"numero_cella": int(numero_cella),
|
||||||
|
"refresh_picking_reservation": 1 if refresh_picking_reservation else 0,
|
||||||
}
|
}
|
||||||
log_runtime_event(
|
log_runtime_event(
|
||||||
"Barcode WMS",
|
"Barcode WMS",
|
||||||
@@ -342,6 +445,7 @@ class BarcodeRepository:
|
|||||||
f"operator={params['id_operatore']} "
|
f"operator={params['id_operatore']} "
|
||||||
f"cell={params['barcode_cella']} "
|
f"cell={params['barcode_cella']} "
|
||||||
f"pallet={params['barcode_pallet']} "
|
f"pallet={params['barcode_pallet']} "
|
||||||
|
f"refresh_pl={params['refresh_picking_reservation']}"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, replace
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
from barcode_repository import BarcodeRepository, LegacyMoveResult
|
from barcode_repository import BarcodeRepository, LegacyMoveResult
|
||||||
@@ -52,8 +52,8 @@ class BarcodeService:
|
|||||||
LIGHT_GREEN = "#d9ead3"
|
LIGHT_GREEN = "#d9ead3"
|
||||||
GREEN_YELLOW = "#e2f0cb"
|
GREEN_YELLOW = "#e2f0cb"
|
||||||
CONVENTIONAL_LOCATION_BY_CELL = {
|
CONVENTIONAL_LOCATION_BY_CELL = {
|
||||||
1000: "5E1.1",
|
1000: "5E.1.1 - Non scaffalata",
|
||||||
9999: "7G.1.1",
|
9999: "7G.1.1 - Spedita",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, repository: BarcodeRepository, operator_id: int):
|
def __init__(self, repository: BarcodeRepository, operator_id: int):
|
||||||
@@ -115,6 +115,15 @@ class BarcodeService:
|
|||||||
)
|
)
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
def resume_priority_state(self, state: BarcodeViewState) -> BarcodeViewState:
|
||||||
|
"""Restore the exact picking pallet that was visible before a local pause."""
|
||||||
|
|
||||||
|
if state.mode not in ("priority_high", "priority_low"):
|
||||||
|
return self._state
|
||||||
|
self._current_priority_state = 1 if state.mode == "priority_high" else 0
|
||||||
|
self._state = replace(state, scanned_pallet="", auto_advance_delay_ms=0)
|
||||||
|
return self._state
|
||||||
|
|
||||||
async def skip_current_picking_pallet(self) -> BarcodeActionResult:
|
async def skip_current_picking_pallet(self) -> BarcodeActionResult:
|
||||||
"""Mark the currently proposed picking pallet as skipped and advance."""
|
"""Mark the currently proposed picking pallet as skipped and advance."""
|
||||||
|
|
||||||
@@ -160,6 +169,24 @@ class BarcodeService:
|
|||||||
self._current_priority_state = int(id_stato)
|
self._current_priority_state = int(id_stato)
|
||||||
queue_label = "Alta priorita' (F1)" if int(id_stato) == 1 else "Bassa priorita' (F2)"
|
queue_label = "Alta priorita' (F1)" if int(id_stato) == 1 else "Bassa priorita' (F2)"
|
||||||
if not row:
|
if not row:
|
||||||
|
skipped_doc = await self.repository.fetch_active_skipped_document(int(id_stato))
|
||||||
|
if skipped_doc:
|
||||||
|
documento = str(skipped_doc.get("Documento") or "").strip()
|
||||||
|
skipped_count = int(skipped_doc.get("SkippedCount") or 0)
|
||||||
|
await self.repository.release_picking_document(
|
||||||
|
documento=documento,
|
||||||
|
operator_id=self.operator_id,
|
||||||
|
)
|
||||||
|
self._current_priority_state = -1
|
||||||
|
self._state = BarcodeViewState(
|
||||||
|
mode="manual_unload",
|
||||||
|
queue_label=queue_label,
|
||||||
|
status_text=f"PL {documento} sospesa: {skipped_count} UDC saltate. Riprenota per completare.",
|
||||||
|
status_color=self.RED,
|
||||||
|
destination_barcode=self.NON_SCAFFALATA_BARCODE,
|
||||||
|
destination_readonly=False,
|
||||||
|
)
|
||||||
|
return BarcodeActionResult(True, self._state)
|
||||||
self._current_priority_state = -1
|
self._current_priority_state = -1
|
||||||
self._state = BarcodeViewState(
|
self._state = BarcodeViewState(
|
||||||
mode="manual_unload",
|
mode="manual_unload",
|
||||||
@@ -215,6 +242,11 @@ class BarcodeService:
|
|||||||
self._state.status_color = self.RED
|
self._state.status_color = self.RED
|
||||||
return BarcodeActionResult(False, self._state, self._state.status_text)
|
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||||
|
|
||||||
|
if not is_picking_unload:
|
||||||
|
blocked = await self._block_closed_picking_free_move(pallet, destination)
|
||||||
|
if blocked is not None:
|
||||||
|
return blocked
|
||||||
|
|
||||||
target_barcode = destination
|
target_barcode = destination
|
||||||
target_numero_cella = int(destination)
|
target_numero_cella = int(destination)
|
||||||
target_id_cella = 9999 if destination == self.SHIPPED_BARCODE else (1000 if destination == self.NON_SCAFFALATA_BARCODE else None)
|
target_id_cella = 9999 if destination == self.SHIPPED_BARCODE else (1000 if destination == self.NON_SCAFFALATA_BARCODE else None)
|
||||||
@@ -254,7 +286,11 @@ class BarcodeService:
|
|||||||
target_display = resolved_cell.ubicazione or destination
|
target_display = resolved_cell.ubicazione or destination
|
||||||
|
|
||||||
current_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
current_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
||||||
picking_before_move = await self.repository.fetch_picking_by_pallet(pallet)
|
picking_before_move = (
|
||||||
|
None
|
||||||
|
if current_location
|
||||||
|
else await self.repository.fetch_picking_by_pallet(pallet)
|
||||||
|
)
|
||||||
if not current_location and not picking_before_move:
|
if not current_location and not picking_before_move:
|
||||||
if is_direct_load:
|
if is_direct_load:
|
||||||
trace_row = await self.repository.fetch_trace_by_pallet(pallet)
|
trace_row = await self.repository.fetch_trace_by_pallet(pallet)
|
||||||
@@ -274,6 +310,7 @@ class BarcodeService:
|
|||||||
barcode_cella=self.NON_SCAFFALATA_BARCODE,
|
barcode_cella=self.NON_SCAFFALATA_BARCODE,
|
||||||
barcode_pallet=pallet,
|
barcode_pallet=pallet,
|
||||||
numero_cella=int(self.NON_SCAFFALATA_BARCODE),
|
numero_cella=int(self.NON_SCAFFALATA_BARCODE),
|
||||||
|
refresh_picking_reservation=False,
|
||||||
)
|
)
|
||||||
current_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
current_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
||||||
try:
|
try:
|
||||||
@@ -331,6 +368,7 @@ class BarcodeService:
|
|||||||
barcode_cella=target_barcode,
|
barcode_cella=target_barcode,
|
||||||
barcode_pallet=pallet,
|
barcode_pallet=pallet,
|
||||||
numero_cella=target_numero_cella,
|
numero_cella=target_numero_cella,
|
||||||
|
refresh_picking_reservation=is_picking_unload,
|
||||||
)
|
)
|
||||||
|
|
||||||
final_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
final_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
||||||
@@ -351,7 +389,7 @@ class BarcodeService:
|
|||||||
destination_barcode=destination,
|
destination_barcode=destination,
|
||||||
destination_display=target_display,
|
destination_display=target_display,
|
||||||
last_priority_state=self._current_priority_state,
|
last_priority_state=self._current_priority_state,
|
||||||
auto_advance_delay_ms=5000 if (is_direct_unload or is_direct_load) else 3000 if is_picking_unload else 0,
|
auto_advance_delay_ms=3000 if is_picking_unload else 0,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log_exception("Barcode WMS", exc, context=f"post move state pallet={pallet} destination={destination}")
|
log_exception("Barcode WMS", exc, context=f"post move state pallet={pallet} destination={destination}")
|
||||||
@@ -377,6 +415,10 @@ class BarcodeService:
|
|||||||
if not source.isdigit():
|
if not source.isdigit():
|
||||||
return BarcodeActionResult(False, self._state, "La cella da scaricare deve essere numerica.")
|
return BarcodeActionResult(False, self._state, "La cella da scaricare deve essere numerica.")
|
||||||
|
|
||||||
|
blocked = await self._block_closed_picking_free_move(pallet, source)
|
||||||
|
if blocked is not None:
|
||||||
|
return blocked
|
||||||
|
|
||||||
current_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
current_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
||||||
if not current_location:
|
if not current_location:
|
||||||
self._state.scanned_pallet = pallet
|
self._state.scanned_pallet = pallet
|
||||||
@@ -449,7 +491,69 @@ class BarcodeService:
|
|||||||
self._state.status_color = self.RED
|
self._state.status_color = self.RED
|
||||||
return BarcodeActionResult(False, self._state, self._state.status_text)
|
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||||
|
|
||||||
return await self.submit(scanned_pallet=pallet, destination_barcode=self.NON_SCAFFALATA_BARCODE)
|
await self.repository.execute_legacy_move(
|
||||||
|
operator_id=self.operator_id,
|
||||||
|
barcode_cella=self.NON_SCAFFALATA_BARCODE,
|
||||||
|
barcode_pallet=pallet,
|
||||||
|
numero_cella=int(self.NON_SCAFFALATA_BARCODE),
|
||||||
|
refresh_picking_reservation=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
final_location = await self.repository.fetch_current_location_by_pallet(pallet)
|
||||||
|
try:
|
||||||
|
final_cell = int((final_location or {}).get("IDCella") or 0)
|
||||||
|
except Exception:
|
||||||
|
final_cell = 0
|
||||||
|
if final_cell != 1000:
|
||||||
|
self._state.scanned_pallet = pallet
|
||||||
|
self._state.destination_barcode = source
|
||||||
|
self._state.status_text = "Movimento non confermato: la UDC non risulta non scaffalata."
|
||||||
|
self._state.status_color = self.RED
|
||||||
|
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._state = await self._build_post_move_state(
|
||||||
|
barcode_pallet=pallet,
|
||||||
|
destination_barcode=self.NON_SCAFFALATA_BARCODE,
|
||||||
|
destination_display=self.CONVENTIONAL_LOCATION_BY_CELL[1000],
|
||||||
|
last_priority_state=self._current_priority_state,
|
||||||
|
auto_advance_delay_ms=0,
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
log_exception("Barcode WMS", exc, context=f"post source-check unload pallet={pallet} source={source}")
|
||||||
|
self._state = BarcodeViewState(
|
||||||
|
mode="confirm",
|
||||||
|
queue_label="Conferma movimento",
|
||||||
|
status_text="Movimento eseguito. Dettagli non aggiornati.",
|
||||||
|
status_color=self.GREEN_YELLOW,
|
||||||
|
destination_barcode=self.NON_SCAFFALATA_BARCODE,
|
||||||
|
scanned_pallet=pallet,
|
||||||
|
)
|
||||||
|
return BarcodeActionResult(True, self._state, self._state.status_text)
|
||||||
|
|
||||||
|
async def _block_closed_picking_free_move(
|
||||||
|
self,
|
||||||
|
pallet: str,
|
||||||
|
destination_barcode: str,
|
||||||
|
) -> BarcodeActionResult | None:
|
||||||
|
closed_row = await self.repository.fetch_closed_picking_by_pallet(pallet)
|
||||||
|
if not closed_row:
|
||||||
|
return None
|
||||||
|
log_runtime_event(
|
||||||
|
"Barcode WMS",
|
||||||
|
(
|
||||||
|
"MOVE BLOCKED CLOSED_PICKING "
|
||||||
|
f"pallet={pallet} "
|
||||||
|
f"destination={destination_barcode} "
|
||||||
|
f"id_cella={closed_row.get('IDCella')} "
|
||||||
|
f"id_stato={closed_row.get('IDStato')}"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self._state.scanned_pallet = pallet
|
||||||
|
self._state.destination_barcode = destination_barcode
|
||||||
|
self._state.status_text = "Errore: UDC gia' spedita, problema nella locazione o nella UDC."
|
||||||
|
self._state.status_color = self.RED
|
||||||
|
return BarcodeActionResult(False, self._state, self._state.status_text)
|
||||||
|
|
||||||
async def reconcile_after_submit_exception(
|
async def reconcile_after_submit_exception(
|
||||||
self,
|
self,
|
||||||
@@ -505,7 +609,7 @@ class BarcodeService:
|
|||||||
|
|
||||||
last_priority_state = self._current_priority_state
|
last_priority_state = self._current_priority_state
|
||||||
is_recovered_picking = bool(destination == self.SHIPPED_BARCODE and last_priority_state in (0, 1))
|
is_recovered_picking = bool(destination == self.SHIPPED_BARCODE and last_priority_state in (0, 1))
|
||||||
auto_advance_delay_ms = 3000 if is_recovered_picking else 5000
|
auto_advance_delay_ms = 3000 if is_recovered_picking else 0
|
||||||
state = await self._build_post_move_state(
|
state = await self._build_post_move_state(
|
||||||
barcode_pallet=pallet,
|
barcode_pallet=pallet,
|
||||||
destination_barcode=destination,
|
destination_barcode=destination,
|
||||||
@@ -542,7 +646,15 @@ class BarcodeService:
|
|||||||
) -> BarcodeViewState:
|
) -> BarcodeViewState:
|
||||||
"""Mirror the legacy confirmation flow after one stored-procedure move."""
|
"""Mirror the legacy confirmation flow after one stored-procedure move."""
|
||||||
|
|
||||||
picking_row = await self.repository.fetch_picking_by_pallet(barcode_pallet)
|
is_priority_shipping_confirmation = (
|
||||||
|
destination_barcode == self.SHIPPED_BARCODE
|
||||||
|
and last_priority_state in (0, 1)
|
||||||
|
)
|
||||||
|
picking_row = (
|
||||||
|
await self.repository.fetch_picking_by_pallet(barcode_pallet)
|
||||||
|
if is_priority_shipping_confirmation
|
||||||
|
else None
|
||||||
|
)
|
||||||
if picking_row:
|
if picking_row:
|
||||||
customer = f"{picking_row.get('CodNazione') or ''} - {picking_row.get('NAZIONE') or ''}".strip(" -")
|
customer = f"{picking_row.get('CodNazione') or ''} - {picking_row.get('NAZIONE') or ''}".strip(" -")
|
||||||
source_location = self._display_location(
|
source_location = self._display_location(
|
||||||
@@ -569,14 +681,20 @@ class BarcodeService:
|
|||||||
prodotto = str(trace_row.get("Prodotto") or "")
|
prodotto = str(trace_row.get("Prodotto") or "")
|
||||||
descrizione = str(trace_row.get("Descrizione") or "")
|
descrizione = str(trace_row.get("Descrizione") or "")
|
||||||
queue_label = "Alta priorita' (F1)" if last_priority_state == 1 else ("Bassa priorita' (F2)" if last_priority_state == 0 else "Conferma movimento")
|
queue_label = "Alta priorita' (F1)" if last_priority_state == 1 else ("Bassa priorita' (F2)" if last_priority_state == 0 else "Conferma movimento")
|
||||||
|
destination_label = self._display_destination_location(
|
||||||
|
destination_barcode=destination_barcode,
|
||||||
|
destination_display=destination_display,
|
||||||
|
)
|
||||||
return BarcodeViewState(
|
return BarcodeViewState(
|
||||||
mode="confirm",
|
mode="confirm",
|
||||||
queue_label=queue_label,
|
queue_label=queue_label,
|
||||||
status_text=(
|
status_text=(
|
||||||
"Ok Scarico" if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) else f"Ok Carico - {destination_display}"
|
f"Ok Scarico - {destination_label}"
|
||||||
|
if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE)
|
||||||
|
else f"Ok Carico - {destination_label}"
|
||||||
),
|
),
|
||||||
status_color=self.GREEN_YELLOW,
|
status_color=self.GREEN_YELLOW,
|
||||||
source_location=str(destination_display or destination_barcode or ""),
|
source_location=destination_label,
|
||||||
document=(
|
document=(
|
||||||
self.CONVENTIONAL_LOCATION_BY_CELL[9999 if destination_barcode == self.SHIPPED_BARCODE else 1000]
|
self.CONVENTIONAL_LOCATION_BY_CELL[9999 if destination_barcode == self.SHIPPED_BARCODE else 1000]
|
||||||
if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) and last_priority_state in (0, 1)
|
if destination_barcode in (self.NON_SCAFFALATA_BARCODE, self.SHIPPED_BARCODE) and last_priority_state in (0, 1)
|
||||||
@@ -607,6 +725,15 @@ class BarcodeService:
|
|||||||
scanned_pallet=barcode_pallet,
|
scanned_pallet=barcode_pallet,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _display_destination_location(self, *, destination_barcode: str, destination_display: str) -> str:
|
||||||
|
"""Return the confirmation label for a movement destination."""
|
||||||
|
|
||||||
|
if destination_barcode == self.NON_SCAFFALATA_BARCODE:
|
||||||
|
return self.CONVENTIONAL_LOCATION_BY_CELL[1000]
|
||||||
|
if destination_barcode == self.SHIPPED_BARCODE:
|
||||||
|
return self.CONVENTIONAL_LOCATION_BY_CELL[9999]
|
||||||
|
return str(destination_display or destination_barcode or "")
|
||||||
|
|
||||||
def _display_location(self, *, cella: object, ubicazione: object) -> str:
|
def _display_location(self, *, cella: object, ubicazione: object) -> str:
|
||||||
"""Return the operator-facing location, honoring legacy conventional cells."""
|
"""Return the operator-facing location, honoring legacy conventional cells."""
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ DEFAULT_DB_CONFIG: dict[str, Any] = {
|
|||||||
"driver": "ODBC Driver 17 for SQL Server",
|
"driver": "ODBC Driver 17 for SQL Server",
|
||||||
"trust_server_certificate": True,
|
"trust_server_certificate": True,
|
||||||
"encrypt": "",
|
"encrypt": "",
|
||||||
|
"query_profiler": {
|
||||||
|
"enabled": False,
|
||||||
|
"slow_ms": 0,
|
||||||
|
"sql_limit": 4000,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
543
diagnostica.py
Normal file
543
diagnostica.py
Normal file
@@ -0,0 +1,543 @@
|
|||||||
|
"""Operational diagnostic checks for warehouse data quadrature."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import tkinter as tk
|
||||||
|
from datetime import datetime
|
||||||
|
from tkinter import filedialog, messagebox, ttk
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
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
|
||||||
|
from window_placement import place_window_fullsize_below_parent_later
|
||||||
|
|
||||||
|
__version__ = module_version(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
SQL_SHIPPED_NOT_DISASSOCIATED = """
|
||||||
|
SELECT DISTINCT
|
||||||
|
LTRIM(RTRIM(g.BarcodePallet)) AS UDC,
|
||||||
|
CAST('Spedita ma non disassociata' AS varchar(64)) AS Diagnostica,
|
||||||
|
CONCAT(
|
||||||
|
RTRIM(c.Corsia),
|
||||||
|
' - ',
|
||||||
|
RTRIM(CAST(c.Colonna AS varchar(32))),
|
||||||
|
' - ',
|
||||||
|
RTRIM(CAST(c.Fila AS varchar(32)))
|
||||||
|
) AS NomeSimbolicoCella
|
||||||
|
FROM dbo.XMag_GiacenzaPallet AS g
|
||||||
|
INNER JOIN dbo.Celle AS c
|
||||||
|
ON c.ID = g.IDCella
|
||||||
|
INNER JOIN dbo.py_XMag_ViewPackingListStorico AS chiuse
|
||||||
|
ON LTRIM(RTRIM(chiuse.Pallet)) COLLATE Latin1_General_CI_AS =
|
||||||
|
LTRIM(RTRIM(g.BarcodePallet)) COLLATE Latin1_General_CI_AS
|
||||||
|
WHERE chiuse.StatoDocumento = 'D'
|
||||||
|
AND g.IDCella <> 9999
|
||||||
|
ORDER BY NomeSimbolicoCella, UDC;
|
||||||
|
"""
|
||||||
|
|
||||||
|
SQL_MULTIPLE_UDC_BY_CELL = """
|
||||||
|
WITH celle_multiple AS (
|
||||||
|
SELECT
|
||||||
|
g.IDCella
|
||||||
|
FROM dbo.XMag_GiacenzaPallet AS g
|
||||||
|
WHERE g.IDCella NOT IN (1000, 9999)
|
||||||
|
GROUP BY g.IDCella
|
||||||
|
HAVING COUNT(DISTINCT LTRIM(RTRIM(g.BarcodePallet))) > 1
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
CONCAT(
|
||||||
|
RTRIM(c.Corsia),
|
||||||
|
' - ',
|
||||||
|
RTRIM(CAST(c.Colonna AS varchar(32))),
|
||||||
|
' - ',
|
||||||
|
RTRIM(CAST(c.Fila AS varchar(32)))
|
||||||
|
) AS CELLA,
|
||||||
|
LTRIM(RTRIM(g.BarcodePallet)) AS UDC
|
||||||
|
FROM dbo.XMag_GiacenzaPallet AS g
|
||||||
|
INNER JOIN celle_multiple AS cm
|
||||||
|
ON cm.IDCella = g.IDCella
|
||||||
|
INNER JOIN dbo.Celle AS c
|
||||||
|
ON c.ID = g.IDCella
|
||||||
|
ORDER BY CELLA, UDC;
|
||||||
|
"""
|
||||||
|
|
||||||
|
SQL_SAM_UDC_NOT_IN_WMS = """
|
||||||
|
WITH recent_lotser AS (
|
||||||
|
SELECT TOP (5000)
|
||||||
|
ls.ID,
|
||||||
|
LEFT(ls.NUMSER, 6) AS UDC,
|
||||||
|
ls.NUMLOT AS Lotto,
|
||||||
|
ls.IDARTICO
|
||||||
|
FROM SAMA1.dbo.LOTSER AS ls
|
||||||
|
WHERE NULLIF(LTRIM(RTRIM(LEFT(ls.NUMSER, 6))), '') IS NOT NULL
|
||||||
|
AND TRY_CONVERT(int, LTRIM(RTRIM(LEFT(ls.NUMSER, 6)))) > 0
|
||||||
|
AND LEN(LTRIM(RTRIM(LEFT(ls.NUMSER, 6)))) = 6
|
||||||
|
AND ls.NUMLOT LIKE CONCAT('P', RIGHT(CONVERT(varchar(4), YEAR(GETDATE())), 2), '%')
|
||||||
|
ORDER BY ls.ID DESC
|
||||||
|
), sam_udc AS (
|
||||||
|
SELECT
|
||||||
|
LTRIM(RTRIM(r.UDC)) AS UDC,
|
||||||
|
MIN(r.Lotto) AS Lotto,
|
||||||
|
MIN(a.CODICE) AS Prodotto,
|
||||||
|
MIN(a.DESCR) AS Descrizione,
|
||||||
|
MAX(r.ID) AS UltimoIDLotSer
|
||||||
|
FROM recent_lotser AS r
|
||||||
|
INNER JOIN SAMA1.dbo.ARTICO AS a
|
||||||
|
ON a.ID = r.IDARTICO
|
||||||
|
GROUP BY LTRIM(RTRIM(r.UDC))
|
||||||
|
)
|
||||||
|
SELECT TOP (100)
|
||||||
|
s.UDC,
|
||||||
|
s.Lotto,
|
||||||
|
s.Prodotto,
|
||||||
|
s.Descrizione
|
||||||
|
FROM sam_udc AS s
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM dbo.MagazziniPallet AS mp
|
||||||
|
WHERE LTRIM(RTRIM(mp.Attributo)) COLLATE Latin1_General_CI_AS =
|
||||||
|
s.UDC COLLATE Latin1_General_CI_AS
|
||||||
|
)
|
||||||
|
ORDER BY s.UltimoIDLotSer DESC;
|
||||||
|
"""
|
||||||
|
|
||||||
|
SHIPPED_NOT_DISASSOCIATED_COLUMNS = (
|
||||||
|
("UDC", "diagnostics.col.udc", "UDC", 130, "w"),
|
||||||
|
(
|
||||||
|
"Diagnostica",
|
||||||
|
"diagnostics.col.shipped_not_disassociated",
|
||||||
|
"Spedita ma non disassociata",
|
||||||
|
280,
|
||||||
|
"w",
|
||||||
|
),
|
||||||
|
("NomeSimbolicoCella", "diagnostics.col.symbolic_cell", "Nome simbolico cella", 240, "w"),
|
||||||
|
)
|
||||||
|
|
||||||
|
MULTIPLE_UDC_COLUMNS = (
|
||||||
|
("CELLA", "diagnostics.col.cell", "CELLA", 220, "w"),
|
||||||
|
("UDC", "diagnostics.col.udc", "UDC", 160, "w"),
|
||||||
|
)
|
||||||
|
|
||||||
|
SAM_UDC_NOT_IN_WMS_COLUMNS = (
|
||||||
|
("UDC", "diagnostics.col.udc", "UDC", 130, "w"),
|
||||||
|
("Lotto", "diagnostics.col.lot", "Lotto", 160, "w"),
|
||||||
|
("Prodotto", "diagnostics.col.product", "Prodotto", 150, "w"),
|
||||||
|
("Descrizione", "diagnostics.col.description", "Descrizione", 360, "w"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _rows_to_dicts(res: dict[str, Any] | None) -> list[dict[str, Any]]:
|
||||||
|
if not isinstance(res, dict):
|
||||||
|
return []
|
||||||
|
rows = res.get("rows") or []
|
||||||
|
cols = res.get("columns") or []
|
||||||
|
if rows and isinstance(rows[0], dict):
|
||||||
|
return [row for row in rows if isinstance(row, dict)]
|
||||||
|
|
||||||
|
out: list[dict[str, Any]] = []
|
||||||
|
for row in rows:
|
||||||
|
if isinstance(row, (list, tuple)) and cols:
|
||||||
|
out.append({str(cols[i]): row[i] for i in range(min(len(cols), len(row)))})
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
class DiagnosticaWindow(ctk.CTkToplevel):
|
||||||
|
"""Window collecting read-only diagnostic queries."""
|
||||||
|
|
||||||
|
def __init__(self, parent: tk.Widget, db_client, session=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.db_client = db_client
|
||||||
|
self.session = session
|
||||||
|
self._theme = theme_section("diagnostics_window", theme_section("search_window", {}))
|
||||||
|
self._locale_catalog = load_locale_catalog()
|
||||||
|
self._async = AsyncRunner(self)
|
||||||
|
self._busy = InlineBusyOverlay(self, self._theme)
|
||||||
|
self._load_in_progress = False
|
||||||
|
self._current_check = ""
|
||||||
|
self.var_status = tk.StringVar(value="")
|
||||||
|
self._last_export_slug = "diagnostica"
|
||||||
|
self._current_columns = SHIPPED_NOT_DISASSOCIATED_COLUMNS
|
||||||
|
self._column_titles: dict[str, str] = {}
|
||||||
|
self._sort_column = ""
|
||||||
|
self._sort_descending = False
|
||||||
|
|
||||||
|
self.title(
|
||||||
|
versioned_title(
|
||||||
|
loc_text("diagnostics.title", catalog=self._locale_catalog, default="Diagnostica"),
|
||||||
|
__name__,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.geometry(str(theme_value(self._theme, "window_geometry", "1100x680")))
|
||||||
|
minsize = theme_value(self._theme, "window_minsize", [900, 560])
|
||||||
|
self.minsize(int(minsize[0]), int(minsize[1]))
|
||||||
|
try:
|
||||||
|
self.configure(fg_color=theme_color(self._theme, "window_fg_color", ("#efefef", "#2f2f2f")))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
self._build_ui()
|
||||||
|
|
||||||
|
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 diagnostica")
|
||||||
|
|
||||||
|
def _build_ui(self) -> None:
|
||||||
|
self.grid_rowconfigure(2, weight=1)
|
||||||
|
self.grid_columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
top = ctk.CTkFrame(
|
||||||
|
self,
|
||||||
|
fg_color=theme_color(self._theme, "toolbar_frame_fg_color", ("#d7d7d7", "#3b3b3b")),
|
||||||
|
)
|
||||||
|
top.grid(row=0, column=0, sticky="ew", padx=8, pady=8)
|
||||||
|
top.grid_columnconfigure(3, weight=1)
|
||||||
|
|
||||||
|
button_font = theme_font(self._theme, "toolbar_button_font", ("Segoe UI", 10, "bold"))
|
||||||
|
ctk.CTkButton(
|
||||||
|
top,
|
||||||
|
text=loc_text(
|
||||||
|
"diagnostics.button.shipped_not_disassociated",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="UDC spedite non disassociate",
|
||||||
|
),
|
||||||
|
command=self._load_shipped_not_disassociated,
|
||||||
|
font=button_font,
|
||||||
|
).grid(row=0, column=0, sticky="w", padx=(0, 8))
|
||||||
|
|
||||||
|
ctk.CTkButton(
|
||||||
|
top,
|
||||||
|
text=loc_text(
|
||||||
|
"diagnostics.button.multiple_udc_by_cell",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Celle con multiple UDC",
|
||||||
|
),
|
||||||
|
command=self._load_multiple_udc_by_cell,
|
||||||
|
font=button_font,
|
||||||
|
).grid(row=0, column=1, sticky="w", padx=(0, 8))
|
||||||
|
|
||||||
|
ctk.CTkButton(
|
||||||
|
top,
|
||||||
|
text=loc_text(
|
||||||
|
"diagnostics.button.sam_udc_not_in_wms",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Ultime UDC SAM non in WMS",
|
||||||
|
),
|
||||||
|
command=self._load_sam_udc_not_in_wms,
|
||||||
|
font=button_font,
|
||||||
|
).grid(row=0, column=2, sticky="w", padx=(0, 8))
|
||||||
|
|
||||||
|
self.btn_export = ctk.CTkButton(
|
||||||
|
top,
|
||||||
|
text=loc_text("diagnostics.button.export", catalog=self._locale_catalog, default="Esporta XLSX"),
|
||||||
|
command=self._export_xlsx,
|
||||||
|
font=button_font,
|
||||||
|
state="disabled",
|
||||||
|
)
|
||||||
|
self.btn_export.grid(row=0, column=4, sticky="e")
|
||||||
|
|
||||||
|
ctk.CTkLabel(
|
||||||
|
self,
|
||||||
|
textvariable=self.var_status,
|
||||||
|
anchor="w",
|
||||||
|
font=theme_font(self._theme, "status_font", ("Segoe UI", 10, "bold")),
|
||||||
|
).grid(row=1, column=0, sticky="ew", padx=10, pady=(0, 6))
|
||||||
|
|
||||||
|
wrap = ctk.CTkFrame(self)
|
||||||
|
wrap.grid(row=2, column=0, sticky="nsew", padx=8, pady=(0, 8))
|
||||||
|
wrap.grid_rowconfigure(0, weight=1)
|
||||||
|
wrap.grid_columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
self.tree = ttk.Treeview(wrap, show="headings")
|
||||||
|
self._configure_tree_columns(self._current_columns)
|
||||||
|
style_treeview(
|
||||||
|
self.tree,
|
||||||
|
style_name="Diagnostics.Treeview",
|
||||||
|
rowheight=22,
|
||||||
|
font=("", 9),
|
||||||
|
heading_font=("", 9, "bold"),
|
||||||
|
)
|
||||||
|
|
||||||
|
sy = ttk.Scrollbar(wrap, orient="vertical", command=self.tree.yview)
|
||||||
|
sx = ttk.Scrollbar(wrap, orient="horizontal", command=self.tree.xview)
|
||||||
|
self.tree.configure(yscrollcommand=sy.set, xscrollcommand=sx.set)
|
||||||
|
self.tree.grid(row=0, column=0, sticky="nsew")
|
||||||
|
sy.grid(row=0, column=1, sticky="ns")
|
||||||
|
sx.grid(row=1, column=0, sticky="ew")
|
||||||
|
|
||||||
|
def _set_status(self, text: str) -> None:
|
||||||
|
self.var_status.set(text)
|
||||||
|
|
||||||
|
def _configure_tree_columns(self, columns) -> None:
|
||||||
|
self.tree.delete(*self.tree.get_children(""))
|
||||||
|
keys = tuple(str(col[0]) for col in columns)
|
||||||
|
self.tree.configure(columns=keys, show="headings")
|
||||||
|
self._sort_column = ""
|
||||||
|
self._sort_descending = False
|
||||||
|
self._column_titles = {}
|
||||||
|
for key, locale_key, default, width, anchor in columns:
|
||||||
|
title = loc_text(str(locale_key), catalog=self._locale_catalog, default=str(default))
|
||||||
|
self._column_titles[str(key)] = title
|
||||||
|
self.tree.heading(
|
||||||
|
key,
|
||||||
|
text=title,
|
||||||
|
command=lambda col=str(key): self._sort_by_column(col),
|
||||||
|
)
|
||||||
|
self.tree.column(key, width=int(width), anchor=str(anchor), stretch=True)
|
||||||
|
|
||||||
|
def _refresh_sort_headings(self) -> None:
|
||||||
|
for key, title in self._column_titles.items():
|
||||||
|
suffix = ""
|
||||||
|
if key == self._sort_column:
|
||||||
|
suffix = " v" if self._sort_descending else " ^"
|
||||||
|
self.tree.heading(key, text=f"{title}{suffix}", command=lambda col=key: self._sort_by_column(col))
|
||||||
|
|
||||||
|
def _sort_key(self, value: Any) -> tuple[int, Any]:
|
||||||
|
text = str(value or "").strip()
|
||||||
|
if not text:
|
||||||
|
return (2, "")
|
||||||
|
normalized = text.replace(".", "").replace(",", ".")
|
||||||
|
try:
|
||||||
|
return (0, float(normalized))
|
||||||
|
except ValueError:
|
||||||
|
return (1, text.casefold())
|
||||||
|
|
||||||
|
def _sort_by_column(self, column: str) -> None:
|
||||||
|
columns = list(self.tree["columns"])
|
||||||
|
if column not in columns:
|
||||||
|
return
|
||||||
|
descending = not self._sort_descending if self._sort_column == column else False
|
||||||
|
col_index = columns.index(column)
|
||||||
|
rows = []
|
||||||
|
for iid in self.tree.get_children(""):
|
||||||
|
values = self.tree.item(iid, "values")
|
||||||
|
value = values[col_index] if col_index < len(values) else ""
|
||||||
|
rows.append((self._sort_key(value), iid))
|
||||||
|
rows.sort(key=lambda item: item[0], reverse=descending)
|
||||||
|
for index, (_key, iid) in enumerate(rows):
|
||||||
|
self.tree.move(iid, "", index)
|
||||||
|
self.tree.item(iid, tags=(zebra_tag(index),))
|
||||||
|
self._sort_column = column
|
||||||
|
self._sort_descending = descending
|
||||||
|
self._refresh_sort_headings()
|
||||||
|
|
||||||
|
def _load_shipped_not_disassociated(self) -> None:
|
||||||
|
self._run_check(
|
||||||
|
key="shipped_not_disassociated",
|
||||||
|
sql=SQL_SHIPPED_NOT_DISASSOCIATED,
|
||||||
|
columns=SHIPPED_NOT_DISASSOCIATED_COLUMNS,
|
||||||
|
busy_text=loc_text(
|
||||||
|
"diagnostics.busy.shipped_not_disassociated",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Cerco UDC spedite ma ancora in cella...",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _load_multiple_udc_by_cell(self) -> None:
|
||||||
|
self._run_check(
|
||||||
|
key="multiple_udc_by_cell",
|
||||||
|
sql=SQL_MULTIPLE_UDC_BY_CELL,
|
||||||
|
columns=MULTIPLE_UDC_COLUMNS,
|
||||||
|
busy_text=loc_text(
|
||||||
|
"diagnostics.busy.multiple_udc_by_cell",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Cerco celle con multiple UDC...",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _load_sam_udc_not_in_wms(self) -> None:
|
||||||
|
self._run_check(
|
||||||
|
key="sam_udc_not_in_wms",
|
||||||
|
sql=SQL_SAM_UDC_NOT_IN_WMS,
|
||||||
|
columns=SAM_UDC_NOT_IN_WMS_COLUMNS,
|
||||||
|
busy_text=loc_text(
|
||||||
|
"diagnostics.busy.sam_udc_not_in_wms",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Cerco le ultime UDC presenti in SAM ma non ancora in WMS...",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _run_check(self, *, key: str, sql: str, columns, busy_text: str) -> None:
|
||||||
|
if self._load_in_progress or not self._is_alive():
|
||||||
|
return
|
||||||
|
|
||||||
|
async def job():
|
||||||
|
return await self.db_client.query_json(sql, as_dict_rows=True)
|
||||||
|
|
||||||
|
self._load_in_progress = True
|
||||||
|
self._current_check = key
|
||||||
|
self._last_export_slug = key
|
||||||
|
self._current_columns = columns
|
||||||
|
self._configure_tree_columns(columns)
|
||||||
|
try:
|
||||||
|
self.btn_export.configure(state="disabled")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
self._busy.show(busy_text)
|
||||||
|
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=f"avvio diagnostica {key}")
|
||||||
|
messagebox.showerror(
|
||||||
|
loc_text("diagnostics.title", catalog=self._locale_catalog, default="Diagnostica"),
|
||||||
|
str(exc),
|
||||||
|
parent=self if self._is_alive() else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _on_loaded(self, res: dict[str, Any] | None) -> None:
|
||||||
|
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(""))
|
||||||
|
keys = [str(col[0]) for col in self._current_columns]
|
||||||
|
for index, row in enumerate(rows):
|
||||||
|
self.tree.insert(
|
||||||
|
"",
|
||||||
|
"end",
|
||||||
|
values=tuple(row.get(key) or "" for key in keys),
|
||||||
|
tags=(zebra_tag(index),),
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
self.btn_export.configure(state="normal" if rows else "disabled")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
self._set_status(
|
||||||
|
loc_text(
|
||||||
|
"diagnostics.status.rows",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Righe trovate: {count}",
|
||||||
|
).format(count=len(rows))
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
log_exception(__name__, exc, context="render diagnostica")
|
||||||
|
messagebox.showerror(
|
||||||
|
loc_text("diagnostics.title", catalog=self._locale_catalog, default="Diagnostica"),
|
||||||
|
str(exc),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _on_error(self, exc: BaseException) -> None:
|
||||||
|
self._load_in_progress = False
|
||||||
|
self._hide_busy_safe()
|
||||||
|
log_exception(__name__, exc, context=f"query diagnostica {self._current_check}")
|
||||||
|
if not self._is_alive():
|
||||||
|
return
|
||||||
|
messagebox.showerror(
|
||||||
|
loc_text("diagnostics.title", catalog=self._locale_catalog, default="Diagnostica"),
|
||||||
|
str(exc),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _export_xlsx(self) -> None:
|
||||||
|
"""Export the currently visible diagnostic grid to an Excel file."""
|
||||||
|
|
||||||
|
rows = [self.tree.item(iid, "values") for iid in self.tree.get_children("")]
|
||||||
|
if not rows:
|
||||||
|
messagebox.showinfo(
|
||||||
|
loc_text("diagnostics.export.title", catalog=self._locale_catalog, default="Esporta"),
|
||||||
|
loc_text(
|
||||||
|
"diagnostics.export.empty",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Non ci sono righe da esportare.",
|
||||||
|
),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
from openpyxl import Workbook
|
||||||
|
from openpyxl.styles import Alignment, Font
|
||||||
|
from openpyxl.utils import get_column_letter
|
||||||
|
except Exception as exc:
|
||||||
|
messagebox.showerror(
|
||||||
|
loc_text("diagnostics.export.title", catalog=self._locale_catalog, default="Esporta"),
|
||||||
|
loc_text(
|
||||||
|
"diagnostics.export.dep",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Per l'esportazione serve 'openpyxl' (pip install openpyxl).",
|
||||||
|
).format(error=exc),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
ts = datetime.now().strftime("%Y%m%d_%H%M")
|
||||||
|
default_name = f"{self._last_export_slug}_{ts}.xlsx"
|
||||||
|
path = filedialog.asksaveasfilename(
|
||||||
|
parent=self,
|
||||||
|
title=loc_text("diagnostics.export.title", catalog=self._locale_catalog, default="Esporta"),
|
||||||
|
defaultextension=".xlsx",
|
||||||
|
filetypes=[("Excel Workbook", "*.xlsx")],
|
||||||
|
initialfile=default_name,
|
||||||
|
)
|
||||||
|
if not path:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
wb = Workbook()
|
||||||
|
ws = wb.active
|
||||||
|
ws.title = "Diagnostica"
|
||||||
|
columns = list(self.tree["columns"])
|
||||||
|
headers = [str(self.tree.heading(col, "text") or col) for col in columns]
|
||||||
|
|
||||||
|
for col_index, header in enumerate(headers, start=1):
|
||||||
|
cell = ws.cell(row=1, column=col_index, value=header)
|
||||||
|
cell.font = Font(bold=True)
|
||||||
|
cell.alignment = Alignment(horizontal="center", vertical="center")
|
||||||
|
|
||||||
|
for row_index, row in enumerate(rows, start=2):
|
||||||
|
for col_index, value in enumerate(row, start=1):
|
||||||
|
ws.cell(row=row_index, column=col_index, value=value)
|
||||||
|
|
||||||
|
widths: dict[int, int] = {}
|
||||||
|
for row in ws.iter_rows(values_only=True):
|
||||||
|
for col_index, value in enumerate(row, start=1):
|
||||||
|
widths[col_index] = max(widths.get(col_index, 0), len("" if value is None else str(value)))
|
||||||
|
for col_index, width in widths.items():
|
||||||
|
ws.column_dimensions[get_column_letter(col_index)].width = min(max(width + 2, 12), 70)
|
||||||
|
|
||||||
|
wb.save(path)
|
||||||
|
messagebox.showinfo(
|
||||||
|
loc_text("diagnostics.export.title", catalog=self._locale_catalog, default="Esporta"),
|
||||||
|
loc_text("diagnostics.export.ok", catalog=self._locale_catalog, default="File creato:\n{path}").format(path=path),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
log_exception(__name__, exc, context="export diagnostica xlsx")
|
||||||
|
messagebox.showerror(
|
||||||
|
loc_text("diagnostics.export.title", catalog=self._locale_catalog, default="Esporta"),
|
||||||
|
loc_text(
|
||||||
|
"diagnostics.export.error",
|
||||||
|
catalog=self._locale_catalog,
|
||||||
|
default="Errore durante l'esportazione:\n{error}",
|
||||||
|
).format(error=exc),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def open_diagnostica_window(parent: tk.Misc, db_client, session=None) -> tk.Misc:
|
||||||
|
"""Open the diagnostics window."""
|
||||||
|
|
||||||
|
win = DiagnosticaWindow(parent, db_client, session=session)
|
||||||
|
place_window_fullsize_below_parent_later(parent, win)
|
||||||
|
win.bind("<Escape>", lambda _e: win.destroy())
|
||||||
|
return win
|
||||||
235
diagnostica_scarico_celle_multiple.md
Normal file
235
diagnostica_scarico_celle_multiple.md
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
# Diagnostica Scarico Celle Multiple
|
||||||
|
|
||||||
|
## Contesto
|
||||||
|
|
||||||
|
La finestra `Scarico` aperta da `Gestione layout` serve a gestire celle fisiche che contengono piu' UDC.
|
||||||
|
Nel database legacy non esisteva un vincolo rigido `una cella = una UDC`, quindi una cella rossa puo' contenere:
|
||||||
|
|
||||||
|
- UDC realmente compresenti nella stessa cella;
|
||||||
|
- UDC rimaste in cella anche se appartenenti a picking list gia' chiuse/spedite.
|
||||||
|
|
||||||
|
L'obiettivo della diagnostica non e' ricostruire tutta la storia della UDC, ma aiutare l'operatore a capire quali righe scaricare come spedite.
|
||||||
|
|
||||||
|
## Fonti Dati
|
||||||
|
|
||||||
|
La griglia della dialog parte dalla giacenza corrente:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
dbo.XMag_GiacenzaPallet
|
||||||
|
```
|
||||||
|
|
||||||
|
Questa vista indica quali UDC risultano presenti nella cella aperta dal layout.
|
||||||
|
|
||||||
|
La diagnostica controlla anche:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
dbo.XMag_GiacenzaPalletPlistChiuse
|
||||||
|
```
|
||||||
|
|
||||||
|
Questa vista non e' uno storico documentale puro. E' una vista ibrida che incrocia la giacenza corrente con i documenti SAM chiusi.
|
||||||
|
In pratica serve a individuare UDC ancora presenti in una cella fisica, ma appartenenti a una picking list/documento gia' chiuso.
|
||||||
|
|
||||||
|
## Conclusione Operativa
|
||||||
|
|
||||||
|
Per una cella fisica aperta da `Gestione layout`, i casi realmente utili sono solo due.
|
||||||
|
|
||||||
|
### 1. Nessuna Diagnostica
|
||||||
|
|
||||||
|
La UDC e' presente nella cella multipla e non compare in `XMag_GiacenzaPalletPlistChiuse`.
|
||||||
|
|
||||||
|
Significato:
|
||||||
|
|
||||||
|
```text
|
||||||
|
UDC normalmente presente in cella.
|
||||||
|
```
|
||||||
|
|
||||||
|
Non viene mostrato nessun messaggio nella colonna diagnostica.
|
||||||
|
|
||||||
|
### 2. Spedita Ma Non Scaricata Dalla Cella
|
||||||
|
|
||||||
|
La UDC e' presente nella cella fisica aperta, ma compare anche in `XMag_GiacenzaPalletPlistChiuse`.
|
||||||
|
|
||||||
|
Diagnostica mostrata:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Motivo: spedita ma non scaricata dalla cella
|
||||||
|
```
|
||||||
|
|
||||||
|
Significato:
|
||||||
|
|
||||||
|
```text
|
||||||
|
La UDC appartiene a una picking list chiusa, ma non e' stata scaricata dalla cella fisica.
|
||||||
|
```
|
||||||
|
|
||||||
|
Operativamente questa UDC va selezionata e scaricata come spedita, quindi verso la cella virtuale:
|
||||||
|
|
||||||
|
```text
|
||||||
|
7G.1.1 / IDCella 9999 / barcode cella 9000000
|
||||||
|
```
|
||||||
|
|
||||||
|
## Casi Teorici Scartati Dalla Dialog
|
||||||
|
|
||||||
|
Durante l'analisi erano stati ipotizzati altri casi, ma sono stati esclusi dalla diagnostica della dialog per non confondere l'operatore.
|
||||||
|
|
||||||
|
### UDC Gia' In 7G.1.1
|
||||||
|
|
||||||
|
Se una UDC risulta davvero in `IDCella = 9999`, normalmente non dovrebbe comparire nella cella fisica aperta dal layout.
|
||||||
|
Se accadesse, sarebbe un'incoerenza tra viste o dati non sincronizzati.
|
||||||
|
|
||||||
|
Per questo la dialog di scarico da layout fisico non mostra piu' il messaggio:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Motivo: spedita
|
||||||
|
```
|
||||||
|
|
||||||
|
### UDC In Picking List Chiusa Ma Non Spedita
|
||||||
|
|
||||||
|
Questo caso e' teoricamente possibile ma raro e ambiguo nel modello dati attuale.
|
||||||
|
Le viste disponibili non forniscono una distinzione documentale/storica abbastanza pulita da renderlo utile in questa dialog operativa.
|
||||||
|
|
||||||
|
Per questo la dialog non mostra piu':
|
||||||
|
|
||||||
|
```text
|
||||||
|
Motivo: in plist chiusa, non spedita e non scaricata dalla cella
|
||||||
|
```
|
||||||
|
|
||||||
|
Eventuali analisi piu' profonde vanno fatte nelle finestre di storico, non nella dialog rapida di scarico.
|
||||||
|
|
||||||
|
## Regola Finale Implementata
|
||||||
|
|
||||||
|
La diagnostica della dialog `Scarico` e' volutamente semplice:
|
||||||
|
|
||||||
|
```text
|
||||||
|
se UDC in XMag_GiacenzaPalletPlistChiuse:
|
||||||
|
"Motivo: spedita ma non scaricata dalla cella"
|
||||||
|
altrimenti:
|
||||||
|
diagnostica vuota
|
||||||
|
```
|
||||||
|
|
||||||
|
Questa scelta riduce il rischio di falsi positivi e mantiene chiaro il comportamento per l'operatore.
|
||||||
|
|
||||||
|
## Aggiornamento 04/07/2026 - Barcode Picking List
|
||||||
|
|
||||||
|
Durante i test sul barcode sono state introdotte alcune modifiche operative collegate alla gestione delle picking list, agli skip UDC e alla ripresa del lavoro dopo movimenti liberi.
|
||||||
|
|
||||||
|
### Anti Autosubmit Su Cambio Lista
|
||||||
|
|
||||||
|
Problema osservato:
|
||||||
|
|
||||||
|
```text
|
||||||
|
passando rapidamente da una picking list prenotata a una non prenotata,
|
||||||
|
il barcode poteva considerare come lettura valida un valore gia' presente nel campo Pallet
|
||||||
|
e scaricare automaticamente una UDC della nuova lista.
|
||||||
|
```
|
||||||
|
|
||||||
|
Correzione implementata:
|
||||||
|
|
||||||
|
```text
|
||||||
|
lo scarico automatico in picking list parte solo se il campo Pallet e' stato modificato
|
||||||
|
dall'operatore dopo il caricamento della UDC proposta.
|
||||||
|
```
|
||||||
|
|
||||||
|
In pratica, quando il programma carica una nuova UDC attesa, il valore visualizzato non puo' piu' generare da solo lo scarico. Serve una nuova lettura o digitazione effettiva.
|
||||||
|
|
||||||
|
### Skip UDC In Picking List
|
||||||
|
|
||||||
|
Durante l'evasione di una picking list, il tasto F4 assume il significato:
|
||||||
|
|
||||||
|
```text
|
||||||
|
[F4] Salta UDC
|
||||||
|
```
|
||||||
|
|
||||||
|
La UDC saltata viene registrata nella tabella:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
dbo.py_BarcodePickingListSkip
|
||||||
|
```
|
||||||
|
|
||||||
|
Le righe aperte hanno:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Risolto = 0
|
||||||
|
```
|
||||||
|
|
||||||
|
La query del barcode esclude le UDC saltate aperte, quindi la lista puo' proseguire sulle UDC successive senza chiudere definitivamente quelle non trovate.
|
||||||
|
|
||||||
|
### Fine Lista Con UDC Saltate
|
||||||
|
|
||||||
|
Quando una picking list non ha piu' UDC immediatamente lavorabili, ma contiene una o piu' UDC saltate, il barcode:
|
||||||
|
|
||||||
|
```text
|
||||||
|
non chiude la picking list;
|
||||||
|
rilascia la prenotazione;
|
||||||
|
lascia la lista riprenotabile;
|
||||||
|
mostra un messaggio di sospensione con numero UDC saltate.
|
||||||
|
```
|
||||||
|
|
||||||
|
La lista resta quindi aperta e potra' essere ripresa in un secondo momento.
|
||||||
|
|
||||||
|
### Riprenotazione E Ripresa UDC Saltate
|
||||||
|
|
||||||
|
Quando la picking list viene riprenotata, gli skip aperti del documento vengono marcati come risolti:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
UPDATE dbo.py_BarcodePickingListSkip
|
||||||
|
SET Risolto = 1,
|
||||||
|
RisoltoDa = <operatore>,
|
||||||
|
RisoltoDataOra = SYSDATETIME()
|
||||||
|
WHERE Documento = <documento>
|
||||||
|
AND Risolto = 0;
|
||||||
|
```
|
||||||
|
|
||||||
|
Questo permette al barcode di riproporre le UDC saltate rimaste da evadere.
|
||||||
|
|
||||||
|
### Posizione UDC Dopo Movimenti Liberi
|
||||||
|
|
||||||
|
Una UDC saltata puo' essere movimentata in pausa tramite operazioni libere, ad esempio:
|
||||||
|
|
||||||
|
```text
|
||||||
|
versamento in una nuova cella fisica;
|
||||||
|
dissociazione verso 9001000 / Non scaffalata.
|
||||||
|
```
|
||||||
|
|
||||||
|
Alla ripresa della picking list, la posizione mostrata dal barcode riflette la giacenza corrente, perche' la vista operativa deriva `Cella` e `Ubicazione` da:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
dbo.XMag_GiacenzaPallet
|
||||||
|
```
|
||||||
|
|
||||||
|
Quindi una UDC prima saltata e poi spostata verra' proposta con la nuova cella, oppure come:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Non scaffalata
|
||||||
|
```
|
||||||
|
|
||||||
|
se e' stata dissociata verso la locazione virtuale `9001000`.
|
||||||
|
|
||||||
|
### Regola Conservata
|
||||||
|
|
||||||
|
Resta confermata la regola operativa:
|
||||||
|
|
||||||
|
```text
|
||||||
|
una UDC diventa Spedita / 7G.1.1 / 9000000 solo nel flusso picking list.
|
||||||
|
```
|
||||||
|
|
||||||
|
Le operazioni libere non spediscono una UDC. Possono solo versarla in una cella fisica oppure metterla in `9001000 / Non scaffalata`.
|
||||||
|
|
||||||
|
### File Coinvolti
|
||||||
|
|
||||||
|
Le modifiche principali sono nei moduli:
|
||||||
|
|
||||||
|
```text
|
||||||
|
barcode_client.py
|
||||||
|
barcode_repository.py
|
||||||
|
barcode_service.py
|
||||||
|
prenota_sprenota_sql.py
|
||||||
|
version_info.py
|
||||||
|
```
|
||||||
|
|
||||||
|
La patch DB cumulativa da usare sul database online e':
|
||||||
|
|
||||||
|
```text
|
||||||
|
apply_online_python_wms_full_patch.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
La patch contiene gli oggetti SQL necessari al ramo Python e puo' essere eseguita una sola volta da SSMS.
|
||||||
@@ -607,6 +607,7 @@ class LayoutWindow(ctk.CTkToplevel):
|
|||||||
)
|
)
|
||||||
m.add_separator()
|
m.add_separator()
|
||||||
m.add_command(label="Copia ubicazione", command=lambda: self._copy(label))
|
m.add_command(label="Copia ubicazione", command=lambda: self._copy(label))
|
||||||
|
m.add_command(label="Codice cella", command=lambda: self._show_cell_code(r, c))
|
||||||
x = self.winfo_pointerx() if event is None else event.x_root
|
x = self.winfo_pointerx() if event is None else event.x_root
|
||||||
y = self.winfo_pointery() if event is None else event.y_root
|
y = self.winfo_pointery() if event is None else event.y_root
|
||||||
m.tk_popup(x, y)
|
m.tk_popup(x, y)
|
||||||
@@ -648,6 +649,25 @@ class LayoutWindow(ctk.CTkToplevel):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def _show_cell_code(self, r: int, c: int) -> None:
|
||||||
|
"""Show the internal cell code for the selected layout cell."""
|
||||||
|
|
||||||
|
idcella = self._cell_id(r, c)
|
||||||
|
ubicazione = self._cell_label(r, c)
|
||||||
|
barcode_cella = self._cell_barcode(r, c)
|
||||||
|
if idcella <= 0:
|
||||||
|
messagebox.showwarning(
|
||||||
|
"Codice cella",
|
||||||
|
f"Codice cella non disponibile per {ubicazione}.",
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
messagebox.showinfo(
|
||||||
|
"Codice cella",
|
||||||
|
f"Ubicazione: {ubicazione}\nCodice cella: {idcella}\nBarcode cella: {barcode_cella or idcella}",
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
|
||||||
@_log_call()
|
@_log_call()
|
||||||
def _prompt_carico(self, r: int, c: int):
|
def _prompt_carico(self, r: int, c: int):
|
||||||
"""Prompt the operator for a pallet barcode and move it to the selected cell."""
|
"""Prompt the operator for a pallet barcode and move it to the selected cell."""
|
||||||
@@ -681,27 +701,7 @@ class LayoutWindow(ctk.CTkToplevel):
|
|||||||
if stato <= 0:
|
if stato <= 0:
|
||||||
self._toast("La cella selezionata non contiene alcuna UDC da scaricare.")
|
self._toast("La cella selezionata non contiene alcuna UDC da scaricare.")
|
||||||
return
|
return
|
||||||
if stato >= 2:
|
|
||||||
self._open_scarico_dialog(r, c)
|
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()
|
@_log_call()
|
||||||
def _run_pallet_move(
|
def _run_pallet_move(
|
||||||
|
|||||||
@@ -328,6 +328,8 @@ DET_COLS: List[ColSpec] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
ROW_H = 28
|
ROW_H = 28
|
||||||
|
RESERVED_IDSTATO_BG = "#dc2626"
|
||||||
|
RESERVED_IDSTATO_FG = "#ffffff"
|
||||||
|
|
||||||
|
|
||||||
# -------------------- Micro spinner (toolbar) --------------------
|
# -------------------- Micro spinner (toolbar) --------------------
|
||||||
@@ -559,6 +561,8 @@ class ScrollTable(ctk.CTkFrame):
|
|||||||
row_index: int,
|
row_index: int,
|
||||||
anchors: Optional[List[str]] = None,
|
anchors: Optional[List[str]] = None,
|
||||||
checkbox_builder: Optional[Callable[[tk.Widget], ctk.CTkCheckBox]] = None,
|
checkbox_builder: Optional[Callable[[tk.Widget], ctk.CTkCheckBox]] = None,
|
||||||
|
cell_bg: Optional[Dict[str, str]] = None,
|
||||||
|
cell_fg: Optional[Dict[str, str]] = None,
|
||||||
):
|
):
|
||||||
"""Append one row to the table body."""
|
"""Append one row to the table body."""
|
||||||
row_bg = TABLE_ROW_EVEN if row_index % 2 == 0 else TABLE_ROW_ODD
|
row_bg = TABLE_ROW_EVEN if row_index % 2 == 0 else TABLE_ROW_ODD
|
||||||
@@ -568,8 +572,9 @@ class ScrollTable(ctk.CTkFrame):
|
|||||||
row.pack_propagate(False)
|
row.pack_propagate(False)
|
||||||
|
|
||||||
for i, col in enumerate(self.columns):
|
for i, col in enumerate(self.columns):
|
||||||
|
holder_bg = (cell_bg or {}).get(col.key, row_bg)
|
||||||
holder = ctk.CTkFrame(
|
holder = ctk.CTkFrame(
|
||||||
row, fg_color=row_bg,
|
row, fg_color=holder_bg,
|
||||||
width=col.width, height=ROW_H,
|
width=col.width, height=ROW_H,
|
||||||
border_width=1, border_color=self.GRID_COLOR
|
border_width=1, border_color=self.GRID_COLOR
|
||||||
)
|
)
|
||||||
@@ -581,10 +586,17 @@ class ScrollTable(ctk.CTkFrame):
|
|||||||
cb = checkbox_builder(holder)
|
cb = checkbox_builder(holder)
|
||||||
cb.pack(padx=(self.PADX_L, self.PADX_R), pady=self.PADY, anchor="w")
|
cb.pack(padx=(self.PADX_L, self.PADX_R), pady=self.PADY, anchor="w")
|
||||||
else:
|
else:
|
||||||
ctk.CTkLabel(holder, text="", fg_color=row_bg).pack(fill="both")
|
ctk.CTkLabel(holder, text="", fg_color=holder_bg).pack(fill="both")
|
||||||
else:
|
else:
|
||||||
anchor = (anchors[i] if anchors else col.anchor)
|
anchor = (anchors[i] if anchors else col.anchor)
|
||||||
ctk.CTkLabel(holder, text=values[i], anchor=anchor, fg_color=row_bg, text_color="#111827").pack(
|
ctk.CTkLabel(
|
||||||
|
holder,
|
||||||
|
text=values[i],
|
||||||
|
anchor=anchor,
|
||||||
|
fg_color=holder_bg,
|
||||||
|
text_color=(cell_fg or {}).get(col.key, "#111827"),
|
||||||
|
font=("Segoe UI", 10, "bold") if col.key == "IDStato" and col.key in (cell_bg or {}) else None,
|
||||||
|
).pack(
|
||||||
fill="both", padx=(self.PADX_L, self.PADX_R), pady=self.PADY
|
fill="both", padx=(self.PADX_L, self.PADX_R), pady=self.PADY
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -876,10 +888,22 @@ class GestionePickingListFrame(ctk.CTkFrame):
|
|||||||
try:
|
try:
|
||||||
for idx, d in enumerate(rows):
|
for idx, d in enumerate(rows):
|
||||||
row_widget = self.pl_table.b_inner.winfo_children()[idx]
|
row_widget = self.pl_table.b_inner.winfo_children()[idx]
|
||||||
if int(d.get("IDStato") or 0) == 1:
|
row_bg = TABLE_ROW_EVEN if idx % 2 == 0 else TABLE_ROW_ODD
|
||||||
row_widget.configure(fg_color="#ffe6f2") # rosa tenue
|
row_widget.configure(fg_color=row_bg)
|
||||||
else:
|
row_children = row_widget.winfo_children()
|
||||||
row_widget.configure(fg_color="transparent")
|
if len(row_children) >= 5:
|
||||||
|
holder = row_children[4]
|
||||||
|
is_reserved = int(d.get("IDStato") or 0) == 1
|
||||||
|
holder_bg = RESERVED_IDSTATO_BG if is_reserved else row_bg
|
||||||
|
holder.configure(fg_color=holder_bg)
|
||||||
|
if holder.winfo_children():
|
||||||
|
lbl = holder.winfo_children()[0]
|
||||||
|
if hasattr(lbl, "configure"):
|
||||||
|
lbl.configure(
|
||||||
|
fg_color=holder_bg,
|
||||||
|
text_color=RESERVED_IDSTATO_FG if is_reserved else "#111827",
|
||||||
|
font=("Segoe UI", 10, "bold") if is_reserved else ("Segoe UI", 10),
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -906,7 +930,9 @@ class GestionePickingListFrame(ctk.CTkFrame):
|
|||||||
values=values,
|
values=values,
|
||||||
row_index=r,
|
row_index=r,
|
||||||
anchors=[c.anchor for c in PL_COLS],
|
anchors=[c.anchor for c in PL_COLS],
|
||||||
checkbox_builder=model.build_checkbox
|
checkbox_builder=model.build_checkbox,
|
||||||
|
cell_bg={"IDStato": RESERVED_IDSTATO_BG} if int(d.get("IDStato") or 0) == 1 else None,
|
||||||
|
cell_fg={"IDStato": RESERVED_IDSTATO_FG} if int(d.get("IDStato") or 0) == 1 else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 🎯 Colora dopo che la UI è resa → no balzi visivi
|
# 🎯 Colora dopo che la UI è resa → no balzi visivi
|
||||||
@@ -932,10 +958,20 @@ class GestionePickingListFrame(ctk.CTkFrame):
|
|||||||
row_children = row_widget.winfo_children()
|
row_children = row_widget.winfo_children()
|
||||||
if len(row_children) >= 5:
|
if len(row_children) >= 5:
|
||||||
holder = row_children[4]
|
holder = row_children[4]
|
||||||
|
holder.configure(fg_color=RESERVED_IDSTATO_BG if idstato == 1 else (
|
||||||
|
TABLE_ROW_EVEN if idx % 2 == 0 else TABLE_ROW_ODD
|
||||||
|
))
|
||||||
if holder.winfo_children():
|
if holder.winfo_children():
|
||||||
lbl = holder.winfo_children()[0]
|
lbl = holder.winfo_children()[0]
|
||||||
if hasattr(lbl, "configure"):
|
if hasattr(lbl, "configure"):
|
||||||
lbl.configure(text=str(idstato))
|
lbl.configure(
|
||||||
|
text=str(idstato),
|
||||||
|
fg_color=RESERVED_IDSTATO_BG if idstato == 1 else (
|
||||||
|
TABLE_ROW_EVEN if idx % 2 == 0 else TABLE_ROW_ODD
|
||||||
|
),
|
||||||
|
text_color=RESERVED_IDSTATO_FG if idstato == 1 else "#111827",
|
||||||
|
font=("Segoe UI", 10, "bold") if idstato == 1 else ("Segoe UI", 10),
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# differisci la colorazione (smooth)
|
# differisci la colorazione (smooth)
|
||||||
|
|||||||
@@ -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_LOGGER = logger.bind(warehouse_module=MODULE_LOG_NAME)
|
||||||
_MODULE_LOGGING_CONFIGURED = False
|
_MODULE_LOGGING_CONFIGURED = False
|
||||||
DEFAULT_SCARICO_USER = "warehouse_ui"
|
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:
|
def _session_login(session: UserSession | None, fallback: str | None = None) -> str:
|
||||||
@@ -198,28 +204,7 @@ last_move AS (
|
|||||||
FROM dbo.MagazziniPallet mp
|
FROM dbo.MagazziniPallet mp
|
||||||
JOIN last_in_cell lic ON lic.LastID = mp.ID
|
JOIN last_in_cell lic ON lic.LastID = mp.ID
|
||||||
),
|
),
|
||||||
latest_any AS (
|
closed_plist 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 (
|
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
shipped.BarcodePallet
|
shipped.BarcodePallet
|
||||||
FROM dbo.XMag_GiacenzaPalletPlistChiuse shipped
|
FROM dbo.XMag_GiacenzaPalletPlistChiuse shipped
|
||||||
@@ -231,25 +216,19 @@ SELECT
|
|||||||
cp.BarcodePallet AS UDC,
|
cp.BarcodePallet AS UDC,
|
||||||
lm.ID AS SourceID,
|
lm.ID AS SourceID,
|
||||||
lm.DataMagazzino AS LastEventAt,
|
lm.DataMagazzino AS LastEventAt,
|
||||||
|
:idcella AS CurrentIDCella,
|
||||||
CASE
|
CASE
|
||||||
WHEN shipped.BarcodePallet IS NOT NULL THEN CAST(1 AS int)
|
WHEN :idcella <> 9999
|
||||||
ELSE CAST(0 AS int)
|
AND closed_plist.BarcodePallet IS NOT NULL
|
||||||
END AS IsShippedGhost,
|
|
||||||
CASE
|
|
||||||
WHEN la.IDCella IS NOT NULL
|
|
||||||
AND la.IDCella <> :idcella
|
|
||||||
THEN CAST(1 AS int)
|
THEN CAST(1 AS int)
|
||||||
ELSE CAST(0 AS int)
|
ELSE CAST(0 AS int)
|
||||||
END AS IsMovedGhost
|
END AS IsMissingUnload
|
||||||
FROM cell_pallets cp
|
FROM cell_pallets cp
|
||||||
LEFT JOIN last_move lm
|
LEFT JOIN last_move lm
|
||||||
ON lm.BarcodePallet COLLATE Latin1_General_CI_AS =
|
ON lm.BarcodePallet COLLATE Latin1_General_CI_AS =
|
||||||
cp.BarcodePallet COLLATE Latin1_General_CI_AS
|
cp.BarcodePallet COLLATE Latin1_General_CI_AS
|
||||||
LEFT JOIN latest_any la
|
LEFT JOIN closed_plist
|
||||||
ON la.BarcodePallet COLLATE Latin1_General_CI_AS =
|
ON closed_plist.BarcodePallet COLLATE Latin1_General_CI_AS =
|
||||||
cp.BarcodePallet COLLATE Latin1_General_CI_AS
|
|
||||||
LEFT JOIN shipped
|
|
||||||
ON shipped.BarcodePallet COLLATE Latin1_General_CI_AS =
|
|
||||||
cp.BarcodePallet COLLATE Latin1_General_CI_AS
|
cp.BarcodePallet COLLATE Latin1_General_CI_AS
|
||||||
ORDER BY
|
ORDER BY
|
||||||
lm.ID DESC,
|
lm.ID DESC,
|
||||||
@@ -413,19 +392,23 @@ class ScaricoRow:
|
|||||||
udc: str
|
udc: str
|
||||||
source_id: int | None
|
source_id: int | None
|
||||||
last_event_at: str
|
last_event_at: str
|
||||||
|
current_idcella: int
|
||||||
diagnostic_note: str
|
diagnostic_note: str
|
||||||
selected: tk.BooleanVar
|
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."""
|
"""Translate low-level anomaly flags into one operator-facing note."""
|
||||||
|
|
||||||
notes: list[str] = []
|
if bool(is_missing_unload):
|
||||||
if bool(is_shipped):
|
return "Motivo: spedita ma non scaricata dalla cella"
|
||||||
notes.append("Mancato scarico: spedita")
|
return ""
|
||||||
if bool(is_moved):
|
|
||||||
notes.append("Mancato scarico: spostata")
|
|
||||||
return " | ".join(notes)
|
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):
|
class ScaricoDialog(ctk.CTkToplevel):
|
||||||
@@ -478,6 +461,7 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
self.wait_visibility()
|
self.wait_visibility()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
if self.winfo_exists():
|
||||||
self.lift()
|
self.lift()
|
||||||
self.focus_force()
|
self.focus_force()
|
||||||
|
|
||||||
@@ -546,19 +530,27 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
actions.grid_columnconfigure(0, weight=1)
|
actions.grid_columnconfigure(0, weight=1)
|
||||||
ctk.CTkButton(
|
ctk.CTkButton(
|
||||||
actions,
|
actions,
|
||||||
text=loc_text("scarico.button.submit", catalog=self._locale_catalog, default="Scarica"),
|
text=loc_text("scarico.button.shipped", catalog=self._locale_catalog, default="Scarico come spedita"),
|
||||||
command=self._on_scarica,
|
command=self._on_scarica_spedita,
|
||||||
font=theme_font(self._theme, "button_font", ("Segoe UI", 10, "bold")),
|
font=theme_font(self._theme, "button_font", ("Segoe UI", 10, "bold")),
|
||||||
).grid(
|
).grid(
|
||||||
row=0, column=1, padx=(8, 0), pady=8
|
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(
|
ctk.CTkButton(
|
||||||
actions,
|
actions,
|
||||||
text=loc_text("scarico.button.close", catalog=self._locale_catalog, default="Chiudi"),
|
text=loc_text("scarico.button.close", catalog=self._locale_catalog, default="Chiudi"),
|
||||||
command=self._close,
|
command=self._close,
|
||||||
font=theme_font(self._theme, "button_font", ("Segoe UI", 10, "bold")),
|
font=theme_font(self._theme, "button_font", ("Segoe UI", 10, "bold")),
|
||||||
).grid(
|
).grid(
|
||||||
row=0, column=2, padx=(8, 8), pady=8
|
row=0, column=3, padx=(8, 8), pady=8
|
||||||
)
|
)
|
||||||
|
|
||||||
def _render_rows(self):
|
def _render_rows(self):
|
||||||
@@ -617,7 +609,13 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
rows = res.get("rows", []) if isinstance(res, dict) else []
|
rows = res.get("rows", []) if isinstance(res, dict) else []
|
||||||
_log_dataset("scarico_load_rows", rows)
|
_log_dataset("scarico_load_rows", rows)
|
||||||
self.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_missing_unload,
|
||||||
|
) in rows:
|
||||||
if isinstance(last_event_at, datetime):
|
if isinstance(last_event_at, datetime):
|
||||||
last_event = last_event_at.strftime("%d/%m/%Y %H:%M:%S")
|
last_event = last_event_at.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
else:
|
else:
|
||||||
@@ -627,7 +625,8 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
udc=str(udc or ""),
|
udc=str(udc or ""),
|
||||||
source_id=int(source_id) if source_id is not None else None,
|
source_id=int(source_id) if source_id is not None else None,
|
||||||
last_event_at=last_event,
|
last_event_at=last_event,
|
||||||
diagnostic_note=_build_diagnostic_note(is_shipped, is_moved),
|
current_idcella=int(current_idcella or 0),
|
||||||
|
diagnostic_note=_build_diagnostic_note(is_missing_unload),
|
||||||
selected=tk.BooleanVar(value=False),
|
selected=tk.BooleanVar(value=False),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -653,8 +652,9 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@_log_call()
|
@_log_call()
|
||||||
def _on_scarica(self):
|
def _selected_rows_or_warn(self) -> list[ScaricoRow] | None:
|
||||||
"""Unload the UDCs selected by the user from the current cell."""
|
"""Return selected rows or show the standard selection warning."""
|
||||||
|
|
||||||
selected = [row for row in self.rows if row.selected.get()]
|
selected = [row for row in self.rows if row.selected.get()]
|
||||||
if not selected:
|
if not selected:
|
||||||
messagebox.showinfo(
|
messagebox.showinfo(
|
||||||
@@ -662,23 +662,97 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
loc_text("scarico.msg.select_one", catalog=self._locale_catalog, default="Seleziona almeno una UDC da scaricare."),
|
loc_text("scarico.msg.select_one", catalog=self._locale_catalog, default="Seleziona almeno una UDC da scaricare."),
|
||||||
parent=self,
|
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] = []
|
||||||
|
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
|
||||||
|
]
|
||||||
|
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 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,
|
||||||
|
"\n".join(message_lines),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not messagebox.askyesno(
|
if not messagebox.askyesno(
|
||||||
"Conferma scarico",
|
title,
|
||||||
f"Scaricare {len(selected)} UDC da {self.ubicazione}?",
|
confirm_text.format(count=len(movable_rows), ubicazione=self.ubicazione),
|
||||||
parent=self,
|
parent=self,
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
async def _job():
|
async def _job():
|
||||||
results: list[dict[str, Any]] = []
|
results: list[dict[str, Any]] = []
|
||||||
for row in selected:
|
for row in movable_rows:
|
||||||
result = await move_pallet_async(
|
result = await move_pallet_async(
|
||||||
self.db_client,
|
self.db_client,
|
||||||
barcode_pallet=row.udc,
|
barcode_pallet=row.udc,
|
||||||
target_idcella=9999,
|
target_idcella=target_idcella,
|
||||||
target_barcode_cella="9000000",
|
target_barcode_cella=target_barcode_cella,
|
||||||
utente=_session_login(self.session),
|
utente=_session_login(self.session),
|
||||||
)
|
)
|
||||||
results.append({"udc": row.udc, "affected": int(result.get("ok") or 0)})
|
results.append({"udc": row.udc, "affected": int(result.get("ok") or 0)})
|
||||||
@@ -690,33 +764,65 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
skipped = [item["udc"] for item in results if int(item.get("affected") or 0) <= 0]
|
skipped = [item["udc"] for item in results if int(item.get("affected") or 0) <= 0]
|
||||||
if not done:
|
if not done:
|
||||||
messagebox.showwarning(
|
messagebox.showwarning(
|
||||||
"Scarica",
|
title,
|
||||||
"Nessuna UDC e' stata scaricata. Verifica che le unita' siano ancora presenti in cella.",
|
"Nessuna UDC e' stata scaricata. Verifica che le unita' siano ancora presenti in cella.",
|
||||||
parent=self,
|
parent=self,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if skipped:
|
if skipped:
|
||||||
|
shipped_note = (
|
||||||
|
f"\nGia' in {SHIPPED_LABEL} non toccate: " + ", ".join(row.udc for row in shipped_rows)
|
||||||
|
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
|
||||||
|
else ""
|
||||||
|
)
|
||||||
messagebox.showwarning(
|
messagebox.showwarning(
|
||||||
"Scarica",
|
title,
|
||||||
"Scarico parziale.\nCompletate: "
|
"Scarico parziale.\nCompletate: "
|
||||||
+ ", ".join(done)
|
+ ", ".join(done)
|
||||||
+ "\nNon scaricate: "
|
+ "\nNon scaricate: "
|
||||||
+ ", ".join(skipped),
|
+ ", ".join(skipped)
|
||||||
|
+ shipped_note
|
||||||
|
+ missing_unload_note
|
||||||
|
+ target_note,
|
||||||
parent=self,
|
parent=self,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
messagebox.showinfo(
|
msg = f"Scarico completato verso {target_label} per:\n" + "\n".join(done)
|
||||||
"Scarica",
|
if shipped_rows:
|
||||||
"Scarico completato per:\n" + "\n".join(done),
|
msg += f"\n\nUDC gia' in {SHIPPED_LABEL} non toccate:\n" + "\n".join(row.udc for row in shipped_rows)
|
||||||
parent=self,
|
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(
|
log_user_action(
|
||||||
self.session,
|
self.session,
|
||||||
module=MODULE_LOG_NAME,
|
module=MODULE_LOG_NAME,
|
||||||
action="layout.scarico",
|
action="layout.scarico.spedita" if int(target_idcella) == SHIPPED_IDCELLA else "layout.scarico.non_scaff",
|
||||||
outcome="ok",
|
outcome="ok",
|
||||||
target=self.ubicazione,
|
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],
|
||||||
|
"spedite_non_scaricate": [row.udc for row in missing_unload_rows],
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if self.on_completed:
|
if self.on_completed:
|
||||||
self.on_completed()
|
self.on_completed()
|
||||||
@@ -727,7 +833,7 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
log_user_action(
|
log_user_action(
|
||||||
self.session,
|
self.session,
|
||||||
module=MODULE_LOG_NAME,
|
module=MODULE_LOG_NAME,
|
||||||
action="layout.scarico",
|
action="layout.scarico.spedita" if int(target_idcella) == SHIPPED_IDCELLA else "layout.scarico.non_scaff",
|
||||||
outcome="error",
|
outcome="error",
|
||||||
target=self.ubicazione,
|
target=self.ubicazione,
|
||||||
details={"error": str(ex)},
|
details={"error": str(ex)},
|
||||||
@@ -743,7 +849,7 @@ class ScaricoDialog(ctk.CTkToplevel):
|
|||||||
_ok,
|
_ok,
|
||||||
_err,
|
_err,
|
||||||
busy=self._busy,
|
busy=self._busy,
|
||||||
message="Scarico UDC...",
|
message=busy_message,
|
||||||
)
|
)
|
||||||
|
|
||||||
@_log_call()
|
@_log_call()
|
||||||
|
|||||||
48
locale.json
48
locale.json
@@ -10,6 +10,7 @@
|
|||||||
"launcher.history_udc": "Storico movimenti UDC",
|
"launcher.history_udc": "Storico movimenti UDC",
|
||||||
"launcher.pickinglist": "Gestione Picking List",
|
"launcher.pickinglist": "Gestione Picking List",
|
||||||
"launcher.history_pickinglist": "Storico Picking List",
|
"launcher.history_pickinglist": "Storico Picking List",
|
||||||
|
"launcher.diagnostics": "Diagnostica",
|
||||||
"launcher.arrange": "Ridisponi finestre",
|
"launcher.arrange": "Ridisponi finestre",
|
||||||
"launcher.exit": "Esci",
|
"launcher.exit": "Esci",
|
||||||
"launcher.already_running_title": "Warehouse",
|
"launcher.already_running_title": "Warehouse",
|
||||||
@@ -75,6 +76,27 @@
|
|||||||
"history.picking.msg.title": "Storico Picking List",
|
"history.picking.msg.title": "Storico Picking List",
|
||||||
"history.picking.msg.load_error": "Errore caricamento:\n{error}",
|
"history.picking.msg.load_error": "Errore caricamento:\n{error}",
|
||||||
"history.picking.msg.detail_error": "Errore dettaglio:\n{error}",
|
"history.picking.msg.detail_error": "Errore dettaglio:\n{error}",
|
||||||
|
"diagnostics.title": "Diagnostica",
|
||||||
|
"diagnostics.button.shipped_not_disassociated": "UDC spedite non disassociate",
|
||||||
|
"diagnostics.button.multiple_udc_by_cell": "Celle con multiple UDC",
|
||||||
|
"diagnostics.button.sam_udc_not_in_wms": "Ultime UDC SAM non in WMS",
|
||||||
|
"diagnostics.button.export": "Esporta XLSX",
|
||||||
|
"diagnostics.busy.shipped_not_disassociated": "Cerco UDC spedite ma ancora in cella...",
|
||||||
|
"diagnostics.busy.multiple_udc_by_cell": "Cerco celle con multiple UDC...",
|
||||||
|
"diagnostics.busy.sam_udc_not_in_wms": "Cerco le ultime UDC presenti in SAM ma non ancora in WMS...",
|
||||||
|
"diagnostics.status.rows": "Righe trovate: {count}",
|
||||||
|
"diagnostics.col.udc": "UDC",
|
||||||
|
"diagnostics.col.cell": "CELLA",
|
||||||
|
"diagnostics.col.lot": "Lotto",
|
||||||
|
"diagnostics.col.product": "Prodotto",
|
||||||
|
"diagnostics.col.description": "Descrizione",
|
||||||
|
"diagnostics.col.shipped_not_disassociated": "Spedita ma non disassociata",
|
||||||
|
"diagnostics.col.symbolic_cell": "Nome simbolico cella",
|
||||||
|
"diagnostics.export.title": "Esporta",
|
||||||
|
"diagnostics.export.empty": "Non ci sono righe da esportare.",
|
||||||
|
"diagnostics.export.dep": "Per l'esportazione serve 'openpyxl' (pip install openpyxl).",
|
||||||
|
"diagnostics.export.ok": "File creato:\n{path}",
|
||||||
|
"diagnostics.export.error": "Errore durante l'esportazione:\n{error}",
|
||||||
"reset.title": "Gestione Corsie - svuotamento celle per corsia",
|
"reset.title": "Gestione Corsie - svuotamento celle per corsia",
|
||||||
"reset.label.aisle": "Corsia:",
|
"reset.label.aisle": "Corsia:",
|
||||||
"reset.button.refresh": "Carica",
|
"reset.button.refresh": "Carica",
|
||||||
@@ -107,6 +129,8 @@
|
|||||||
"scarico.col.last_insert": "Ultimo inserimento",
|
"scarico.col.last_insert": "Ultimo inserimento",
|
||||||
"scarico.col.diagnostic": "Diagnostica",
|
"scarico.col.diagnostic": "Diagnostica",
|
||||||
"scarico.button.submit": "Scarica",
|
"scarico.button.submit": "Scarica",
|
||||||
|
"scarico.button.shipped": "Scarico come spedita",
|
||||||
|
"scarico.button.non_shelved": "Scarico come non scaff.",
|
||||||
"scarico.button.close": "Chiudi",
|
"scarico.button.close": "Chiudi",
|
||||||
"scarico.msg.title": "Scarica",
|
"scarico.msg.title": "Scarica",
|
||||||
"scarico.msg.select_one": "Seleziona almeno una UDC da scaricare.",
|
"scarico.msg.select_one": "Seleziona almeno una UDC da scaricare.",
|
||||||
@@ -123,6 +147,7 @@
|
|||||||
"launcher.history_udc": "UDC Movement History",
|
"launcher.history_udc": "UDC Movement History",
|
||||||
"launcher.pickinglist": "Picking List Management",
|
"launcher.pickinglist": "Picking List Management",
|
||||||
"launcher.history_pickinglist": "Picking List History",
|
"launcher.history_pickinglist": "Picking List History",
|
||||||
|
"launcher.diagnostics": "Diagnostics",
|
||||||
"launcher.arrange": "Arrange windows",
|
"launcher.arrange": "Arrange windows",
|
||||||
"launcher.exit": "Exit",
|
"launcher.exit": "Exit",
|
||||||
"launcher.already_running_title": "Warehouse",
|
"launcher.already_running_title": "Warehouse",
|
||||||
@@ -188,6 +213,27 @@
|
|||||||
"history.picking.msg.title": "Picking List History",
|
"history.picking.msg.title": "Picking List History",
|
||||||
"history.picking.msg.load_error": "Load failed:\n{error}",
|
"history.picking.msg.load_error": "Load failed:\n{error}",
|
||||||
"history.picking.msg.detail_error": "Detail load failed:\n{error}",
|
"history.picking.msg.detail_error": "Detail load failed:\n{error}",
|
||||||
|
"diagnostics.title": "Diagnostics",
|
||||||
|
"diagnostics.button.shipped_not_disassociated": "Shipped UDC not disassociated",
|
||||||
|
"diagnostics.button.multiple_udc_by_cell": "Cells with multiple UDC",
|
||||||
|
"diagnostics.button.sam_udc_not_in_wms": "Latest UDC in SAM not in WMS",
|
||||||
|
"diagnostics.button.export": "Export XLSX",
|
||||||
|
"diagnostics.busy.shipped_not_disassociated": "Searching shipped UDC still assigned to cells...",
|
||||||
|
"diagnostics.busy.multiple_udc_by_cell": "Searching cells with multiple UDC...",
|
||||||
|
"diagnostics.busy.sam_udc_not_in_wms": "Searching latest UDC present in SAM but not yet in WMS...",
|
||||||
|
"diagnostics.status.rows": "Rows found: {count}",
|
||||||
|
"diagnostics.col.udc": "UDC",
|
||||||
|
"diagnostics.col.cell": "CELL",
|
||||||
|
"diagnostics.col.lot": "Lot",
|
||||||
|
"diagnostics.col.product": "Product",
|
||||||
|
"diagnostics.col.description": "Description",
|
||||||
|
"diagnostics.col.shipped_not_disassociated": "Shipped but not disassociated",
|
||||||
|
"diagnostics.col.symbolic_cell": "Symbolic cell name",
|
||||||
|
"diagnostics.export.title": "Export",
|
||||||
|
"diagnostics.export.empty": "There are no rows to export.",
|
||||||
|
"diagnostics.export.dep": "Export requires 'openpyxl' (pip install openpyxl).",
|
||||||
|
"diagnostics.export.ok": "File created:\n{path}",
|
||||||
|
"diagnostics.export.error": "Export failed:\n{error}",
|
||||||
"reset.title": "Aisle Management - empty cells by aisle",
|
"reset.title": "Aisle Management - empty cells by aisle",
|
||||||
"reset.label.aisle": "Aisle:",
|
"reset.label.aisle": "Aisle:",
|
||||||
"reset.button.refresh": "Load",
|
"reset.button.refresh": "Load",
|
||||||
@@ -220,6 +266,8 @@
|
|||||||
"scarico.col.last_insert": "Last insert",
|
"scarico.col.last_insert": "Last insert",
|
||||||
"scarico.col.diagnostic": "Diagnostics",
|
"scarico.col.diagnostic": "Diagnostics",
|
||||||
"scarico.button.submit": "Unload",
|
"scarico.button.submit": "Unload",
|
||||||
|
"scarico.button.shipped": "Unload as shipped",
|
||||||
|
"scarico.button.non_shelved": "Unload as non-shelved",
|
||||||
"scarico.button.close": "Close",
|
"scarico.button.close": "Close",
|
||||||
"scarico.msg.title": "Unload",
|
"scarico.msg.title": "Unload",
|
||||||
"scarico.msg.select_one": "Select at least one UDC to unload.",
|
"scarico.msg.select_one": "Select at least one UDC to unload.",
|
||||||
|
|||||||
11
main.py
11
main.py
@@ -22,6 +22,7 @@ from async_loop_singleton import get_global_loop, stop_global_loop
|
|||||||
from async_msssql_query import AsyncMSSQLClient
|
from async_msssql_query import AsyncMSSQLClient
|
||||||
from audit_log import log_session_event
|
from audit_log import log_session_event
|
||||||
from db_config import build_dsn_from_config, ensure_db_config
|
from db_config import build_dsn_from_config, ensure_db_config
|
||||||
|
from diagnostica import open_diagnostica_window
|
||||||
from gestione_layout import open_layout_window
|
from gestione_layout import open_layout_window
|
||||||
from gestione_pickinglist import open_pickinglist_window
|
from gestione_pickinglist import open_pickinglist_window
|
||||||
from login_window import prompt_login
|
from login_window import prompt_login
|
||||||
@@ -161,6 +162,7 @@ class Launcher(ctk.CTk):
|
|||||||
"storico_udc",
|
"storico_udc",
|
||||||
"pickinglist",
|
"pickinglist",
|
||||||
"storico_pickinglist",
|
"storico_pickinglist",
|
||||||
|
"diagnostica",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, session: UserSession, db_client: AsyncMSSQLClient):
|
def __init__(self, session: UserSession, db_client: AsyncMSSQLClient):
|
||||||
@@ -268,6 +270,15 @@ class Launcher(ctk.CTk):
|
|||||||
lambda: open_storico_pickinglist_window(self, self.db_client, session=self.session),
|
lambda: open_storico_pickinglist_window(self, self.db_client, session=self.session),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"diagnostica",
|
||||||
|
loc_text("launcher.diagnostics", catalog=self._locale_catalog, default="Diagnostica"),
|
||||||
|
"launcher.open_diagnostics",
|
||||||
|
lambda: self._open_or_focus_child_window(
|
||||||
|
"diagnostica",
|
||||||
|
lambda: open_diagnostica_window(self, self.db_client, session=self.session),
|
||||||
|
),
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"arrange",
|
"arrange",
|
||||||
loc_text("launcher.arrange", catalog=self._locale_catalog, default="Ridisponi finestre"),
|
loc_text("launcher.arrange", catalog=self._locale_catalog, default="Ridisponi finestre"),
|
||||||
|
|||||||
@@ -303,6 +303,23 @@ async def sp_xExePackingListPallet_async(db, IDOperatore: int, Documento: str, A
|
|||||||
rc = int(rows[0].get("RC") or 0)
|
rc = int(rows[0].get("RC") or 0)
|
||||||
except Exception:
|
except Exception:
|
||||||
rc = 0
|
rc = 0
|
||||||
|
if rc == 0 and azione == "P":
|
||||||
|
resolve_sql = """
|
||||||
|
UPDATE dbo.py_BarcodePickingListSkip
|
||||||
|
SET Risolto = 1
|
||||||
|
WHERE Documento COLLATE Latin1_General_CI_AS =
|
||||||
|
CAST(:Documento AS varchar(50)) COLLATE Latin1_General_CI_AS
|
||||||
|
AND Risolto = 0;
|
||||||
|
"""
|
||||||
|
_log_sql("resolve_skipped_pallets_on_prenota", resolve_sql, {"Documento": Documento})
|
||||||
|
if hasattr(db, "exec"):
|
||||||
|
await db.exec(resolve_sql, {"Documento": Documento}, commit=True)
|
||||||
|
else:
|
||||||
|
await db.query_json(
|
||||||
|
resolve_sql + "\nSELECT 0 AS RC;",
|
||||||
|
{"Documento": Documento},
|
||||||
|
commit=True,
|
||||||
|
)
|
||||||
_MODULE_LOGGER.log(_MODULE_LOG_LEVEL, f"Stored procedure completata documento={Documento} azione={azione} rc={rc}")
|
_MODULE_LOGGER.log(_MODULE_LOG_LEVEL, f"Stored procedure completata documento={Documento} azione={azione} rc={rc}")
|
||||||
return SPResult(rc=rc, message="", id_result=None)
|
return SPResult(rc=rc, message="", id_result=None)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ SELECT
|
|||||||
FROM meta m
|
FROM meta m
|
||||||
LEFT JOIN agg a ON a.Documento = m.Documento
|
LEFT JOIN agg a ON a.Documento = m.Documento
|
||||||
WHERE (:documento IS NULL OR CAST(m.Documento AS varchar(32)) LIKE CONCAT('%', :documento, '%'))
|
WHERE (:documento IS NULL OR CAST(m.Documento AS varchar(32)) LIKE CONCAT('%', :documento, '%'))
|
||||||
ORDER BY m.Documento DESC;
|
ORDER BY m.DataDocumento DESC, m.Documento DESC;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Detail query:
|
# Detail query:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"launcher.open_history_udc": "Apre lo storico movimenti UDC per ricostruire carichi, scarichi, celle e utenti coinvolti.",
|
"launcher.open_history_udc": "Apre lo storico movimenti UDC per ricostruire carichi, scarichi, celle e utenti coinvolti.",
|
||||||
"launcher.open_pickinglist": "Apre la gestione delle picking list per prenotare, controllare e aggiornare le liste di prelievo.",
|
"launcher.open_pickinglist": "Apre la gestione delle picking list per prenotare, controllare e aggiornare le liste di prelievo.",
|
||||||
"launcher.open_history_pickinglist": "Apre lo storico picking list per consultare liste, stato operativo e dettaglio UDC.",
|
"launcher.open_history_pickinglist": "Apre lo storico picking list per consultare liste, stato operativo e dettaglio UDC.",
|
||||||
|
"launcher.open_diagnostics": "Apre la diagnostica operativa con quadrature e controlli di coerenza sui dati di magazzino.",
|
||||||
"launcher.arrange_windows": "Dispone in cascata le finestre aperte seguendo l'ordine dei pulsanti del launcher.",
|
"launcher.arrange_windows": "Dispone in cascata le finestre aperte seguendo l'ordine dei pulsanti del launcher.",
|
||||||
"launcher.exit": "Chiude l'applicazione in modo pulito terminando la sessione utente e rilasciando la connessione condivisa al database.",
|
"launcher.exit": "Chiude l'applicazione in modo pulito terminando la sessione utente e rilasciando la connessione condivisa al database.",
|
||||||
"dbconfig.heading": "Spiega che qui si inseriscono i dati minimi per permettere al programma di collegarsi al database del magazzino al primo avvio.",
|
"dbconfig.heading": "Spiega che qui si inseriscono i dati minimi per permettere al programma di collegarsi al database del magazzino al primo avvio.",
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
"launcher.open_history_udc": "Open UDC movement history to review loads, unloads, cells and users involved.",
|
"launcher.open_history_udc": "Open UDC movement history to review loads, unloads, cells and users involved.",
|
||||||
"launcher.open_pickinglist": "Open picking list management to reserve, inspect and update picking lists.",
|
"launcher.open_pickinglist": "Open picking list management to reserve, inspect and update picking lists.",
|
||||||
"launcher.open_history_pickinglist": "Open picking-list history to inspect lists, operational status and UDC detail.",
|
"launcher.open_history_pickinglist": "Open picking-list history to inspect lists, operational status and UDC detail.",
|
||||||
|
"launcher.open_diagnostics": "Open operational diagnostics with data consistency checks and warehouse quadratures.",
|
||||||
"launcher.arrange_windows": "Arrange open windows in cascade order following the launcher buttons.",
|
"launcher.arrange_windows": "Arrange open windows in cascade order following the launcher buttons.",
|
||||||
"launcher.exit": "Close the application cleanly by ending the user session and releasing the shared database connection.",
|
"launcher.exit": "Close the application cleanly by ending the user session and releasing the shared database connection.",
|
||||||
"dbconfig.heading": "Explain that this form collects the minimum data needed to connect the program to the warehouse database on first startup.",
|
"dbconfig.heading": "Explain that this form collects the minimum data needed to connect the program to the warehouse database on first startup.",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ ALL_ACTIONS: FrozenSet[str] = frozenset(
|
|||||||
"launcher.open_history_udc",
|
"launcher.open_history_udc",
|
||||||
"launcher.open_pickinglist",
|
"launcher.open_pickinglist",
|
||||||
"launcher.open_history_pickinglist",
|
"launcher.open_history_pickinglist",
|
||||||
|
"launcher.open_diagnostics",
|
||||||
"launcher.arrange_windows",
|
"launcher.arrange_windows",
|
||||||
"launcher.exit",
|
"launcher.exit",
|
||||||
"reset_corsie.view",
|
"reset_corsie.view",
|
||||||
@@ -27,6 +28,7 @@ ALL_ACTIONS: FrozenSet[str] = frozenset(
|
|||||||
"non_shelved.view",
|
"non_shelved.view",
|
||||||
"history_udc.view",
|
"history_udc.view",
|
||||||
"history_pickinglist.view",
|
"history_pickinglist.view",
|
||||||
|
"diagnostics.view",
|
||||||
"multi_udc.view",
|
"multi_udc.view",
|
||||||
"layout.view",
|
"layout.view",
|
||||||
"layout.carico",
|
"layout.carico",
|
||||||
|
|||||||
@@ -10,30 +10,31 @@ APP_VERSION = "1.0.0"
|
|||||||
MODULE_VERSIONS: dict[str, str] = {
|
MODULE_VERSIONS: dict[str, str] = {
|
||||||
"app": APP_VERSION,
|
"app": APP_VERSION,
|
||||||
"async_loop_singleton": "1.0.0",
|
"async_loop_singleton": "1.0.0",
|
||||||
"async_msssql_query": "1.0.0",
|
"async_msssql_query": "1.0.1",
|
||||||
"audit_log": "1.0.0",
|
"audit_log": "1.0.0",
|
||||||
"main": "1.0.1",
|
"main": "1.0.2",
|
||||||
"barcode_client": "1.0.20",
|
"barcode_client": "1.0.26",
|
||||||
"barcode_repository": "1.0.6",
|
"barcode_repository": "1.0.12",
|
||||||
"barcode_service": "1.0.16",
|
"barcode_service": "1.0.24",
|
||||||
"busy_overlay": "1.0.0",
|
"busy_overlay": "1.0.0",
|
||||||
"db_config": "1.0.0",
|
"db_config": "1.0.0",
|
||||||
|
"diagnostica": "1.0.4",
|
||||||
"gestione_aree": "1.0.1",
|
"gestione_aree": "1.0.1",
|
||||||
"gestione_layout": "1.0.0",
|
"gestione_layout": "1.0.2",
|
||||||
"gestione_pickinglist": "1.0.2",
|
"gestione_pickinglist": "1.0.4",
|
||||||
"gestione_scarico": "1.0.0",
|
"gestione_scarico": "1.0.8",
|
||||||
"locale_text": "1.0.0",
|
"locale_text": "1.0.0",
|
||||||
"login_window": "1.0.0",
|
"login_window": "1.0.0",
|
||||||
"prenota_sprenota_sql": "1.0.0",
|
"prenota_sprenota_sql": "1.0.1",
|
||||||
"reset_corsie": "1.0.0",
|
"reset_corsie": "1.0.0",
|
||||||
"runtime_support": "1.0.1",
|
"runtime_support": "1.0.1",
|
||||||
"search_pallets": "1.0.0",
|
"search_pallets": "1.0.0",
|
||||||
"storico_pickinglist": "1.0.3",
|
"storico_pickinglist": "1.0.4",
|
||||||
"storico_udc": "1.0.0",
|
"storico_udc": "1.0.0",
|
||||||
"tooltips": "1.0.0",
|
"tooltips": "1.0.0",
|
||||||
"udc_non_scaffalate": "1.0.1",
|
"udc_non_scaffalate": "1.0.1",
|
||||||
"ui_theme": "1.0.0",
|
"ui_theme": "1.0.0",
|
||||||
"user_session": "1.0.0",
|
"user_session": "1.0.1",
|
||||||
"view_celle_multi_udc": "1.0.0",
|
"view_celle_multi_udc": "1.0.0",
|
||||||
"window_placement": "1.0.0",
|
"window_placement": "1.0.0",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user