Integra inventario WMS-SAM nella versione monolista con test e guida deploy
This commit is contained in:
202
tests/test_inventory.py
Normal file
202
tests/test_inventory.py
Normal file
@@ -0,0 +1,202 @@
|
||||
"""Domain and XLSX regression tests: no live stock is modified."""
|
||||
import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from inventory_service import (DETAIL_KEYS, SUMMARY_KEYS, build_report, export_inventory,
|
||||
inventory_cutoff, load_inventory)
|
||||
from locale_text import text
|
||||
|
||||
DAY = date(2025, 12, 31)
|
||||
HISTORY = dict(Kind="META", Component="HIST_MIN", SourceDate=datetime(2022, 1, 1))
|
||||
|
||||
|
||||
def stock(**changes):
|
||||
r = dict(Kind="ROW", Component="A", Product="P1", Description="Product",
|
||||
Unit="NR", ContainerId=1, Lot="L1", Serial="600001/000001",
|
||||
Pallet="600001", Cell=1101, Location="1A.1.a", Balance=Decimal(1),
|
||||
Quantity=Decimal(20), SamQuantity=Decimal(20), Locations=1,
|
||||
NegativeBalances=0, Shipped=0, AssignmentIssue=0,
|
||||
MovementIssues=0, OtherReceipts=0)
|
||||
r.update(changes)
|
||||
return r
|
||||
|
||||
|
||||
def report(*records):
|
||||
return build_report(DAY, [HISTORY, *records])
|
||||
|
||||
|
||||
def packing(**changes):
|
||||
return stock(Component="B", ContainerId=2, Pallet="600002", Serial="600002/000002",
|
||||
Cell=None, Location=None, Balance=None, Locations=0, **changes)
|
||||
|
||||
|
||||
def loose(**changes):
|
||||
return stock(Component="C", ContainerId=3, Pallet="000000", Serial="000000/000003",
|
||||
Cell=None, Location=None, Balance=None, Locations=0, **changes)
|
||||
|
||||
|
||||
class InventoryTests(unittest.TestCase):
|
||||
def test_year_end_exclusive_cutoff(self):
|
||||
self.assertEqual(inventory_cutoff("31/12/2025"), (DAY, datetime(2026, 1, 1), 46023))
|
||||
|
||||
def test_dates_invalid_future_and_leap(self):
|
||||
for value in ("31/02/2025", "2025-12-31", "01/01/3000", "31/12/2009"):
|
||||
with self.assertRaises(ValueError):
|
||||
inventory_cutoff(value)
|
||||
self.assertEqual(inventory_cutoff("29/02/2024")[1], datetime(2024, 3, 1))
|
||||
|
||||
def test_three_components_and_sign(self):
|
||||
r = report(stock(), packing(Quantity=10, SamQuantity=10), loose(Quantity=5, SamQuantity=5))
|
||||
row = r.rows[0]
|
||||
self.assertEqual([row[k] for k in ("WMS", "Packing", "Loose", "Reconstructed", "SAM", "Difference")],
|
||||
[20, 10, 5, 35, 35, 0])
|
||||
self.assertEqual(row["InitialDifference"], 15)
|
||||
self.assertEqual(row["LooseContainers"], 1)
|
||||
|
||||
def test_non_shelved_is_a_not_b(self):
|
||||
row = report(stock(Cell=1000)).rows[0]
|
||||
self.assertEqual((row["NonShelved"], row["Packing"], row["UDCs"]), (20, 0, 1))
|
||||
|
||||
def test_multilot_counts_udc_once_and_keeps_lots(self):
|
||||
r = report(stock(), stock(ContainerId=4, Lot="L2", Serial="600001/000004"))
|
||||
self.assertEqual((r.rows[0]["UDCs"], r.rows[0]["WMS"]), (1, 40))
|
||||
self.assertEqual(len(r.lots), 2)
|
||||
|
||||
def test_multi_product_udc(self):
|
||||
r = report(stock(), stock(ContainerId=4, Product="P2"))
|
||||
self.assertEqual([row["UDCs"] for row in r.rows], [1, 1])
|
||||
|
||||
def test_lot_offsets_do_not_look_like_a_match(self):
|
||||
row = report(stock(SamQuantity=10), stock(ContainerId=2, Lot="L2", SamQuantity=30)).rows[0]
|
||||
self.assertEqual(row["Difference"], 0)
|
||||
self.assertIn("lot_offsets", row["Issues"])
|
||||
|
||||
def test_multilocation_does_not_double_sam(self):
|
||||
r = report(stock(Locations=2), stock(Locations=2, Cell=8004))
|
||||
self.assertEqual((r.rows[0]["SAM"], r.rows[0]["UDCs"]), (20, 1))
|
||||
self.assertIsNone(r.rows[0]["WMS"])
|
||||
self.assertIn("locations", r.rows[0]["Issues"])
|
||||
|
||||
def test_duplicate_incompatible_data_invalidates(self):
|
||||
row = report(stock(), stock(Quantity=50)).rows[0]
|
||||
self.assertIn("duplicate", row["Issues"])
|
||||
self.assertIsNone(row["SAM"])
|
||||
|
||||
def test_missing_content_is_not_zero(self):
|
||||
row = report(stock(Quantity=None)).rows[0]
|
||||
self.assertIsNone(row["WMS"])
|
||||
self.assertIsNone(row["Difference"])
|
||||
self.assertEqual(row["SAM"], 20)
|
||||
|
||||
def test_shipped_residual_is_not_packaging(self):
|
||||
row = report(
|
||||
stock(), stock(Component="X", ContainerId=9, Pallet="600009",
|
||||
Cell=None, Locations=1, Shipped=1, Quantity=5, SamQuantity=5)).rows[0]
|
||||
self.assertEqual((row["Packing"], row["SAM"], row["Difference"]), (0, 25, 5))
|
||||
self.assertIn("shipped", row["Issues"])
|
||||
|
||||
def test_sam_zero_does_not_hide_wms_presence(self):
|
||||
row = report(stock(SamQuantity=0)).rows[0]
|
||||
self.assertEqual((row["WMS"], row["Difference"]), (20, -20))
|
||||
|
||||
def test_partial_container_uses_actual_quantity(self):
|
||||
row = report(loose(Quantity=Decimal("3.5"), SamQuantity=Decimal("3.5"))).rows[0]
|
||||
self.assertEqual(row["Loose"], Decimal("3.5"))
|
||||
|
||||
def test_history_missing_or_ambiguous_is_not_certified(self):
|
||||
for r in (build_report(DAY, [stock()]), report(stock(AssignmentIssue=1)),
|
||||
build_report(date(2020, 1, 1), [HISTORY, stock()])):
|
||||
self.assertIn("history", r.rows[0]["Issues"])
|
||||
self.assertIsNone(r.rows[0]["Difference"])
|
||||
|
||||
def test_movements_missing_invalidates_sam(self):
|
||||
row = report(stock(MovementIssues=1)).rows[0]
|
||||
self.assertIsNone(row["SAM"])
|
||||
|
||||
def test_negative_balance_flagged(self):
|
||||
row = report(loose(Quantity=-5, SamQuantity=-5)).rows[0]
|
||||
self.assertIn("negative", row["Issues"])
|
||||
self.assertIsNone(row["Difference"])
|
||||
|
||||
def test_other_receipt_requires_validation(self):
|
||||
row = report(stock(OtherReceipts=1)).rows[0]
|
||||
self.assertIsNone(row["WMS"])
|
||||
|
||||
def test_unknown_unit(self):
|
||||
row = report(stock(Unit="KG")).rows[0]
|
||||
self.assertIn("unit", row["Issues"])
|
||||
self.assertIsNone(row["SAM"])
|
||||
|
||||
def test_undated_wms(self):
|
||||
row = report(stock(), dict(Kind="META", Component="UNDATED", Quantity=1)).rows[0]
|
||||
self.assertIsNone(row["Difference"])
|
||||
|
||||
def test_missing_label_remains_visible(self):
|
||||
row = report(stock(Product=None, ContainerId=None, Quantity=None)).rows[0]
|
||||
self.assertIn("600001", row["Product"])
|
||||
self.assertIsNone(row["WMS"])
|
||||
|
||||
def test_empty_report(self):
|
||||
r = report()
|
||||
self.assertEqual((r.rows, r.lots, r.details), ([], [], []))
|
||||
|
||||
def test_export_roundtrip(self):
|
||||
from openpyxl import load_workbook
|
||||
r = report(stock(Product="=CODE"), stock(Product="P2", ContainerId=2, Quantity=None))
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path = str(Path(folder) / "inventory.xlsx")
|
||||
export_inventory(r, path, translate=text)
|
||||
wb = load_workbook(path)
|
||||
ws = wb.active
|
||||
self.assertEqual(len(wb.worksheets), 3)
|
||||
self.assertEqual(ws["B1"].value.date(), DAY)
|
||||
self.assertEqual((ws["A7"].value, ws["A7"].data_type), ("=CODE", "s"))
|
||||
diff_col = SUMMARY_KEYS.index("Difference") + 1
|
||||
self.assertEqual(ws.cell(7, diff_col).value, 0)
|
||||
self.assertIsNone(ws.cell(8, SUMMARY_KEYS.index("WMS")+1).value)
|
||||
self.assertEqual(ws.freeze_panes, "A7")
|
||||
self.assertEqual(wb.worksheets[2].cell(2, DETAIL_KEYS.index("Serial")+1).value, "600001/000001")
|
||||
wb.close()
|
||||
|
||||
def test_translations_complete(self):
|
||||
catalog = json.loads(Path("locale.json").read_text(encoding="utf-8"))
|
||||
for language in ("IT", "ENG"):
|
||||
for key in SUMMARY_KEYS + DETAIL_KEYS:
|
||||
self.assertIn("inventory.col." + key, catalog[language])
|
||||
for component in "ABCX":
|
||||
self.assertIn("inventory.component." + component, catalog[language])
|
||||
self.assertEqual({k for k in catalog["IT"] if k.startswith("inventory.")},
|
||||
{k for k in catalog["ENG"] if k.startswith("inventory.")})
|
||||
|
||||
def test_sqlalchemy_has_only_two_actual_bind_markers(self):
|
||||
from sqlalchemy import text as sql_text
|
||||
from sqlalchemy.dialects.mssql.pyodbc import dialect
|
||||
from inventory_service import SQL_PATH
|
||||
compiled = sql_text(SQL_PATH.read_text(encoding="utf-8")).compile(dialect=dialect(paramstyle="qmark"))
|
||||
self.assertEqual(compiled.positiontup, ["cutoff", "sam_cutoff"])
|
||||
|
||||
|
||||
class InventoryAsyncTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_bound_cutoffs_without_commit(self):
|
||||
db = type("DB", (), {"query_json": AsyncMock(return_value={"rows": []})})()
|
||||
r = await load_inventory(db, "31/12/2025")
|
||||
args, kwargs = db.query_json.call_args
|
||||
self.assertEqual(args[1]["cutoff"], datetime(2026, 1, 1))
|
||||
self.assertEqual(args[1]["sam_cutoff"], 46023)
|
||||
self.assertNotIn("commit", kwargs)
|
||||
self.assertEqual(r.selected_date, DAY)
|
||||
|
||||
async def test_invalid_date_never_queries(self):
|
||||
db = type("DB", (), {"query_json": AsyncMock()})()
|
||||
with self.assertRaises(ValueError):
|
||||
await load_inventory(db, "31/02/2025")
|
||||
db.query_json.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
132
tests/test_inventory_gui.py
Normal file
132
tests/test_inventory_gui.py
Normal file
@@ -0,0 +1,132 @@
|
||||
"""Real Tk widget checks with synthetic report data; no database connection."""
|
||||
|
||||
import tkinter as tk
|
||||
import unittest
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import customtkinter as ctk
|
||||
|
||||
from inventario import InventarioWindow, display_number
|
||||
from inventory_service import build_report
|
||||
from test_inventory import stock, HISTORY
|
||||
|
||||
|
||||
class InventoryGuiTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.root = ctk.CTk()
|
||||
self.root.withdraw()
|
||||
self.win = InventarioWindow(self.root, Mock())
|
||||
self.win.withdraw()
|
||||
self.root.update_idletasks()
|
||||
|
||||
def tearDown(self):
|
||||
for token in self.root.tk.call("after", "info"):
|
||||
try:
|
||||
# Cancel the timer without deleting another widget's Tcl command.
|
||||
self.root.tk.call("after", "cancel", token)
|
||||
except tk.TclError:
|
||||
pass
|
||||
self.win.destroy()
|
||||
self.root.destroy()
|
||||
|
||||
def sample(self):
|
||||
return build_report(date(2025, 12, 31), [
|
||||
HISTORY,
|
||||
stock(Product="A", Quantity=Decimal(10), SamQuantity=Decimal(10)),
|
||||
stock(Product="B", ContainerId=2, Quantity=Decimal(2), SamQuantity=Decimal(2)),
|
||||
])
|
||||
|
||||
def test_no_query_at_open_and_render_zeros(self):
|
||||
self.win.db_client.query_json.assert_not_called()
|
||||
self.win._loaded(self.sample())
|
||||
values = self.win.tree.item("0", "values")
|
||||
self.assertEqual(values[3:9], ("1", "10", "0", "10", "0", "0"))
|
||||
self.assertEqual(self.win.btn_export.cget("state"), "normal")
|
||||
self.assertIn("31/12/2025", self.win.var_status.get())
|
||||
|
||||
def test_selection_populates_lot_and_container_details(self):
|
||||
self.win._loaded(self.sample())
|
||||
self.win.tree.selection_set("0")
|
||||
self.win._select()
|
||||
self.assertEqual(len(self.win.lot_tree.get_children()), 1)
|
||||
self.assertEqual(len(self.win.detail_tree.get_children()), 1)
|
||||
|
||||
def test_sort_uses_numbers_not_formatted_strings(self):
|
||||
self.win._loaded(self.sample())
|
||||
self.win._sort("SAM")
|
||||
self.assertEqual([r["Product"] for r in self.win._rows], ["B", "A"])
|
||||
self.win._sort("SAM")
|
||||
self.assertEqual([r["Product"] for r in self.win._rows], ["A", "B"])
|
||||
|
||||
def test_load_disables_export_and_repeated_requests(self):
|
||||
self.win._loaded(self.sample())
|
||||
with patch.object(self.win._async, "run") as run:
|
||||
self.win._load()
|
||||
self.assertEqual(self.win.btn_export.cget("state"), "disabled")
|
||||
self.win._load()
|
||||
self.assertEqual(run.call_count, 1)
|
||||
run.call_args.args[0].close()
|
||||
|
||||
def test_export_uses_result_date_not_edited_entry(self):
|
||||
self.win._loaded(self.sample())
|
||||
self.win.var_date.set("01/01/2026")
|
||||
with patch("inventario.filedialog.asksaveasfilename", return_value="") as save:
|
||||
self.win._export()
|
||||
self.assertEqual(save.call_args.kwargs["initialfile"], "inventario_20251231.xlsx")
|
||||
|
||||
def test_decimal_formatting(self):
|
||||
self.assertEqual(display_number(Decimal("0.000000")), "0")
|
||||
self.assertEqual(display_number(Decimal("1200.000000")), "1200")
|
||||
self.assertEqual(display_number(None), "?")
|
||||
|
||||
def test_failed_load_restores_controls_without_old_export(self):
|
||||
self.win._loaded(self.sample())
|
||||
with patch.object(self.win._async, "run") as run:
|
||||
self.win._load()
|
||||
run.call_args.args[0].close()
|
||||
with patch("inventario.messagebox.showerror"), patch("inventario.log_exception"):
|
||||
self.win._error(RuntimeError("Synthetic failure"))
|
||||
self.assertEqual(self.win.btn_load.cget("state"), "normal")
|
||||
self.assertEqual(self.win.btn_export.cget("state"), "disabled")
|
||||
self.assertEqual(self.win.tree.get_children(), ())
|
||||
|
||||
|
||||
class InventoryLauncherTests(unittest.TestCase):
|
||||
def test_menu_opens_single_inventory_child(self):
|
||||
from main import Launcher
|
||||
from user_session import UserSession
|
||||
session = UserSession(1, "TEST", "Test operator")
|
||||
with patch.object(Launcher, "_apply_dynamic_geometry"), patch.object(Launcher, "lift"), \
|
||||
patch.object(Launcher, "focus_force"), patch.object(Launcher, "_make_exit_icon", return_value=None):
|
||||
root = Launcher(session, Mock())
|
||||
root.withdraw()
|
||||
try:
|
||||
def widgets(widget):
|
||||
for child in widget.winfo_children():
|
||||
yield child
|
||||
yield from widgets(child)
|
||||
buttons = [w for w in widgets(root) if isinstance(w, ctk.CTkButton) and w.cget("text") == "Inventario"]
|
||||
self.assertEqual(len(buttons), 1)
|
||||
def create(*args, **kwargs):
|
||||
win = InventarioWindow(*args, **kwargs)
|
||||
win.withdraw()
|
||||
return win
|
||||
with patch("main.open_inventario_window", side_effect=create) as factory, \
|
||||
patch("main.place_window_below_parent_later"), \
|
||||
patch.object(InventarioWindow, "lift"), patch.object(InventarioWindow, "focus_force"):
|
||||
buttons[0].invoke()
|
||||
first = root._child_windows_by_key["inventario"]
|
||||
buttons[0].invoke()
|
||||
self.assertIs(root._child_windows_by_key["inventario"], first)
|
||||
self.assertEqual(factory.call_count, 1)
|
||||
root.db_client.query_json.assert_not_called()
|
||||
finally:
|
||||
for token in root.tk.call("after", "info"):
|
||||
root.tk.call("after", "cancel", token)
|
||||
root.destroy()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
139
tests/test_inventory_sql.py
Normal file
139
tests/test_inventory_sql.py
Normal file
@@ -0,0 +1,139 @@
|
||||
"""Opt-in SQL Server integration tests using ONLY local #temporary fixtures.
|
||||
|
||||
Set INVENTORY_TEST_CONFIG to a local db_connection.json. Source object names in
|
||||
the production batch are replaced with #fixtures before execution: no warehouse
|
||||
or ERP table is read or written by the test. Credentials are never printed.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
from datetime import date, datetime
|
||||
|
||||
from inventory_service import SQL_PATH, build_report
|
||||
|
||||
|
||||
@unittest.skipUnless(os.environ.get("INVENTORY_TEST_CONFIG"), "SQL fixture test is opt-in")
|
||||
class InventorySQLTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
import pyodbc
|
||||
with open(os.environ["INVENTORY_TEST_CONFIG"], encoding="utf-8") as handle:
|
||||
c = json.load(handle)
|
||||
self.cn = pyodbc.connect("DRIVER={" + c["driver"] + "};SERVER=" + c["server"]
|
||||
+ ";DATABASE=" + c["database"] + ";UID=" + c["user"] + ";PWD=" + c["password"]
|
||||
+ ";TrustServerCertificate=yes;", timeout=5)
|
||||
self.cn.timeout = 60
|
||||
self.addCleanup(self.cn.close)
|
||||
self.addCleanup(self.cn.rollback)
|
||||
self.cur = self.cn.cursor()
|
||||
definitions = {
|
||||
"ANAMAG": "ID int, DESCR varchar(100)",
|
||||
"ALLMAG": "ID int, IDANAMAG int",
|
||||
"MagazziniPallet": "Attributo varchar(20),IDCella int,Tipo char(1),PesoUnitario decimal(28,6),DataMagazzino datetime",
|
||||
"Celle": "ID int,IDArea int,Corsia varchar(20),Colonna varchar(20),Fila varchar(20)",
|
||||
"Aree": "ID int,IDMagazzino int",
|
||||
"Magazzini": "ID int,Descrizione varchar(20)",
|
||||
"LOTSER": "ID int,IDARTICO int,NUMLOT varchar(30),NUMSER varchar(30)",
|
||||
"EXTTACLOTSER": "IDLOTSER float,EXNUMSER varchar(30),NUMSER varchar(30),AGGIORNAMENTO datetime",
|
||||
"GIAMAG": "IDARTICO int,IDMAG int,QTTGIAI decimal(28,6)",
|
||||
"MOVMAG": "IDARTICO int,IDCAUMOV int,IDMAGPAR int,IDMAGARR int,QTAINV decimal(28,6),DATMOV float",
|
||||
"CAUMOV": "ID int,CODICE varchar(10),QTGIUP char(1),QTGIUA char(1)",
|
||||
"ARTICO": "ID int,CODICE varchar(30),DESCR varchar(100),UMI varchar(8)",
|
||||
}
|
||||
for name, definition in definitions.items():
|
||||
self.cur.execute(f"CREATE TABLE #fixture_{name} ({definition})")
|
||||
self.sql = SQL_PATH.read_text(encoding="utf-8")
|
||||
for name in definitions:
|
||||
self.sql = self.sql.replace("SAMA1.dbo." + name, "#fixture_" + name)
|
||||
self.sql = self.sql.replace("dbo." + name, "#fixture_" + name)
|
||||
self.assertNotIn("SAMA1.dbo.", self.sql)
|
||||
self.assertNotIn("dbo.", self.sql)
|
||||
self.sql = self.sql.replace(":sam_cutoff", "?").replace(":cutoff", "?")
|
||||
self.insert("ANAMAG", (20, "Magazzino Principale"))
|
||||
self.insert("ALLMAG", (4, 20), (6, 30))
|
||||
self.insert("Magazzini", (1, "MDE5"), (2, "MDE6"), (3, "OTHER"))
|
||||
self.insert("Aree", (1, 1), (2, 2), (3, 3))
|
||||
self.insert("Celle", (1101, 1, "1A", "1", "a"), (8004, 2, "4P", "1", "d"),
|
||||
(1000, 1, "5E", "1", "1"), (9999, 1, "7G", "1", "1"),
|
||||
(9900, 3, "Z", "1", "1"))
|
||||
self.insert("ARTICO", (1, "PROD", "Product", "NR"))
|
||||
self.insert("CAUMOV", (1, "CP", None, "+"), (2, "VEN", "-", None))
|
||||
self.insert("EXTTACLOTSER", (999, "000000/000999", "600999/000999", datetime(2022, 1, 1)))
|
||||
self.day = date(2026, 1, 1)
|
||||
self.cutoff = datetime(2026, 1, 2)
|
||||
self.serial_cutoff = (self.cutoff - datetime(1899, 12, 30)).days
|
||||
for pallet, cell in (("600001", 1101), ("600002", 1000), ("600006", 9999), ("600007", 9999)):
|
||||
self.insert("MagazziniPallet", (pallet, cell, "V", 1, datetime(2025, 12, 30)))
|
||||
# Real WMS stock: 60 + 40 + 10 pieces. ID3 is another lot in the SAME UDC.
|
||||
self.container(1, "L1", "600001/000001", 60, 0)
|
||||
self.container(2, "L1", "600002/000002", 40, 40)
|
||||
self.container(3, "L2", "600001/000003", 10, 10)
|
||||
self.container(4, "L1", "600004/000004", 30, 30) # partial packing UDC
|
||||
self.container(5, "L1", "000000/000005", 20, 20)
|
||||
self.container(6, "L1", "600006/000006", 15, 15) # shipped with SAM residual
|
||||
self.container(7, "L1", "600007/000007", 99, 0) # fully shipped
|
||||
self.container(8, "EXCLUDED", "000000/000008", 777, 777) # same product, other lot
|
||||
self.container(9, "L1", "600009/000009", 6, 6) # was unassigned at cutoff
|
||||
self.insert("EXTTACLOTSER", (9, "000000/000009", "600009/000009", datetime(2026, 1, 3)))
|
||||
# ID1 shipped AFTER inventory. Current GIAMAG=0 must be reversed to 60.
|
||||
self.insert("MOVMAG", (1, 2, 4, None, 60, self.serial_cutoff + 1))
|
||||
self.insert("MagazziniPallet", ("600001", 1101, "P", 1, datetime(2026, 1, 3)),
|
||||
("600001", 9999, "V", 1, datetime(2026, 1, 3)))
|
||||
|
||||
def insert(self, name, *rows):
|
||||
for row in rows:
|
||||
self.cur.execute(f"INSERT INTO #fixture_{name} VALUES ({','.join('?' for _ in row)})", row)
|
||||
|
||||
def container(self, identity, lot, serial, receipt, current):
|
||||
self.insert("LOTSER", (identity, 1, lot, serial))
|
||||
self.insert("GIAMAG", (identity, 4, current))
|
||||
self.insert("MOVMAG", (identity, 1, None, 4, receipt, self.serial_cutoff - 2))
|
||||
|
||||
def run_query(self):
|
||||
self.cur.execute(self.sql, self.cutoff, self.serial_cutoff)
|
||||
columns = [c[0] for c in self.cur.description]
|
||||
records = [dict(zip(columns, row)) for row in self.cur.fetchall()]
|
||||
return build_report(self.day, records)
|
||||
|
||||
def test_scope_history_shipments_three_components(self):
|
||||
r = self.run_query()
|
||||
row = r.rows[0]
|
||||
self.assertEqual((row["WMS"], row["Packing"], row["Loose"], row["SAM"], row["Difference"]),
|
||||
(110, 30, 26, 181, 15))
|
||||
self.assertEqual((row["UDCs"], row["PackingUDCs"], row["LooseContainers"]), (2, 1, 2))
|
||||
self.assertEqual({x["Lot"] for x in r.lots}, {"L1", "L2"})
|
||||
by_id = {x["ContainerId"]: x for x in r.details}
|
||||
self.assertEqual(by_id[9]["Component"], "C")
|
||||
self.assertEqual(by_id[9]["Serial"], "000000/000009")
|
||||
self.assertEqual(by_id[6]["Component"], "X")
|
||||
self.assertNotIn(7, by_id)
|
||||
self.assertNotIn(8, by_id)
|
||||
self.assertEqual(by_id[1]["SamQuantity"], 60)
|
||||
|
||||
def test_principal_only_and_incremental_receipts(self):
|
||||
self.insert("GIAMAG", (4, 6, 10000))
|
||||
self.insert("MOVMAG", (1, 1, None, 4, 5, self.serial_cutoff - 1))
|
||||
row = self.run_query().rows[0]
|
||||
self.assertEqual(row["WMS"], 115)
|
||||
self.assertEqual(row["SAM"], 181)
|
||||
|
||||
def test_multiple_locations_never_double_sam(self):
|
||||
self.insert("MagazziniPallet", ("600001", 8004, "V", 1, datetime(2025, 12, 31)))
|
||||
row = self.run_query().rows[0]
|
||||
self.assertEqual(row["SAM"], 181)
|
||||
self.assertIsNone(row["WMS"])
|
||||
self.assertIn("locations", row["Issues"])
|
||||
|
||||
def test_assignment_tie_is_unknown(self):
|
||||
self.insert("EXTTACLOTSER", (9, "000000/000009", "600010/000009", datetime(2026, 1, 3)))
|
||||
row = self.run_query().rows[0]
|
||||
self.assertIn("history", row["Issues"])
|
||||
self.assertIsNone(row["Difference"])
|
||||
|
||||
def test_midnight_is_exclusive(self):
|
||||
self.insert("MOVMAG", (2, 2, 4, None, 7, self.serial_cutoff))
|
||||
row = self.run_query().rows[0]
|
||||
self.assertEqual(row["SAM"], 188)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user