migrate.py: Update payment migration

This commit is contained in:
2024-01-23 00:48:22 +01:00
parent 26f1bda85e
commit d44eb85639

View File

@ -1333,7 +1333,7 @@ def fix_deliveries(deliveries: Iterable[Dict[str, Any]]) -> Iterable[Tuple[str,
def migrate_deliveries(in_dir: str, out_dir: str) -> None: def migrate_deliveries(in_dir: str, out_dir: str) -> None:
global DELIVERY_MAP, MODIFIER_MAP, SORT_MAP global DELIVERY_MAP, MODIFIER_MAP, SORT_MAP
DELIVERY_MAP, MODIFIER_MAP, SORT_MAP = {}, {}, {} DELIVERY_MAP, MODIFIER_MAP, SORT_MAP = {}, {}, {'HU/': 'GV/HU', 'SV/': 'SW/'}
modifiers = { modifiers = {
m['ASNR']: m m['ASNR']: m
@ -1439,8 +1439,7 @@ def migrate_deliveries(in_dir: str, out_dir: str) -> None:
attributes.remove('F') attributes.remove('F')
if d['SNR'] != sortid: if d['SNR'] != sortid:
SORT_MAP[f'{d["SNR"]}/{d["SANR"] or ""}'] = f'{sortid}/{",".join(list(attributes)) or ""}' \ SORT_MAP[f'{d["SNR"]}/{d["SANR"] or ""}'] = f'{sortid}/{",".join(list(attributes)) or ""}'
if len(attributes) > 0 else None
line = f'{d["SNR"]}/{d["SANR"]} -> {sortid}/{",".join(list(attributes)) or None}' line = f'{d["SNR"]}/{d["SANR"]} -> {sortid}/{",".join(list(attributes)) or None}'
if line not in updated_varieties: if line not in updated_varieties:
updated_varieties[line] = 0 updated_varieties[line] = 0
@ -1611,9 +1610,9 @@ def migrate_payments(in_dir: str, out_dir: str) -> None:
keys = list(n.keys()) keys = list(n.keys())
vals = list(n.values()) vals = list(n.values())
if len(n) == 0: if len(n) == 0:
n = {'73oe': 0} n = {'15kmw': 0}
elif len(n) == 1: elif len(n) == 1:
n = {'73oe': list(n.values())[0]} n = {'15kmw': list(n.values())[0]}
return n return n
with (utils.csv_open(f'{out_dir}/payment_variant.csv') as f_payment): with (utils.csv_open(f'{out_dir}/payment_variant.csv') as f_payment):
@ -1647,7 +1646,7 @@ def migrate_payments(in_dir: str, out_dir: str) -> None:
if s['Oechsle'] is None: if s['Oechsle'] is None:
continue continue
key = SORT_MAP.get(f'{s["SNR"]}/{s["SANR"] or ""}', f'{s["SNR"].upper()}/{s["SANR"] or ""}') key = SORT_MAP.get(f'{s["SNR"]}/{s["SANR"] or ""}', f'{s["SNR"].upper()}/{s["SANR"] or ""}')
if key is None: if key is None or len(key) < 3:
continue continue
azs[key] = azs.get(key, {'Gebunden': {}, 'NichtGebunden': {}}) azs[key] = azs.get(key, {'Gebunden': {}, 'NichtGebunden': {}})
azs[key]['Gebunden' if s['gebunden'] else 'NichtGebunden'][s['Oechsle']] = s['Betrag'] azs[key]['Gebunden' if s['gebunden'] else 'NichtGebunden'][s['Oechsle']] = s['Betrag']
@ -1703,10 +1702,10 @@ def migrate_payments(in_dir: str, out_dir: str) -> None:
del q['ID'] del q['ID']
qualid = QUAL_MAP[q['QSNR']] qualid = QUAL_MAP[q['QSNR']]
key = SORT_MAP.get(f'{q["SNR"]}/{q["SANR"] or ""}', f'{q["SNR"].upper()}/{q["SANR"] or ""}') key = SORT_MAP.get(f'{q["SNR"]}/{q["SANR"] or ""}', f'{q["SNR"].upper()}/{q["SANR"] or ""}')
if key is None: if key is None or len(key) < 3:
continue continue
azq[qualid] = azq.get(qualid, {}) azq[qualid] = azq.get(qualid, {})
azq[qualid][key] = q['Betrag'] azq[qualid][key] = q['Betrag'] or 0
for qualid, d1 in azq.items(): for qualid, d1 in azq.items():
azq[qualid] = collapse_data(d1) azq[qualid] = collapse_data(d1)