From db51e069bc18ce3b31d3b21d76eb5cca80a9e7e7 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 14 Sep 2023 23:23:59 +0200 Subject: [PATCH] Database: Add weighing_reason to delivery_part --- sql/v01/10.create.sql | 1 + wgmaster/migrate.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sql/v01/10.create.sql b/sql/v01/10.create.sql index 111ec25..6d9347d 100644 --- a/sql/v01/10.create.sql +++ b/sql/v01/10.create.sql @@ -542,6 +542,7 @@ CREATE TABLE delivery_part ( scale_id TEXT, weighing_id TEXT, + weighing_reason TEXT CHECK (NOT (manual_weighing = TRUE AND weighing_reason IS NOT NULL)), comment TEXT DEFAULT NULL, ctime INTEGER NOT NULL DEFAULT (UNIXEPOCH()), diff --git a/wgmaster/migrate.py b/wgmaster/migrate.py index a9709c1..d723d8a 100755 --- a/wgmaster/migrate.py +++ b/wgmaster/migrate.py @@ -1354,7 +1354,7 @@ def migrate_deliveries(in_dir: str, out_dir: str) -> None: f_delivery.header('year', 'did', 'date', 'time', 'zwstid', 'lnr', 'lsnr', 'mgnr', 'comment') f_part.header('year', 'did', 'dpnr', 'sortid', 'weight', 'kmw', 'qualid', 'hkid', 'kgnr', 'rdnr', 'gerebelt', 'manual_weighing', 'spl_check', 'hand_picked', 'lesewagen', - 'temperature', 'acid', 'scale_id', 'weighing_id', 'comment') + 'temperature', 'acid', 'scale_id', 'weighing_id', 'weighing_reason', 'comment') f_attr.header('year', 'did', 'dpnr', 'attrid') for lsnr, linrs, date in fixed: @@ -1475,19 +1475,21 @@ def migrate_deliveries(in_dir: str, out_dir: str) -> None: if comment.startswith('Säure'): acid = float(comment.split(' ')[-1].replace(',', '.')) comment = None - elif comment == 'Maschine': + elif comment in ('Maschine', 'Masschine'): hand = False comment = None elif comment == 'Hand': hand = True comment = None + elif comment == '.': + comment = None if comment: comments.append(comment) gerebelt = True if CLIENT == WG.MATZEN or (CLIENT == WG.WINZERKELLER and zwstid == 'W') else d['Gerebelt'] or False f_part.row( date.year, snr, dpnr, sortid, int(d['Gewicht']), kmw, qualid, hkid, kgnr, rdnr, gerebelt, handwiegung, d['Spaetlese-Ueberpruefung'] or False, - hand, lesemaschine, d['Temperatur'], acid, scale_id, weighing_id, comment + hand, lesemaschine, d['Temperatur'], acid, scale_id, weighing_id, None, comment ) for attrid in attributes: f_attr.row(date.year, snr, dpnr, attrid)