Migrate contracts
This commit is contained in:
@ -9,9 +9,9 @@ import csv
|
|||||||
|
|
||||||
|
|
||||||
TABLES = ['branch', 'wb_gl', 'wb_kg', 'wb_rd', 'wine_attribute', 'wine_cultivation',
|
TABLES = ['branch', 'wb_gl', 'wb_kg', 'wb_rd', 'wine_attribute', 'wine_cultivation',
|
||||||
'member', 'member_billing_address', 'contract', 'area_commitment',
|
'member', 'member_billing_address', 'contract', 'area_commitment', ]
|
||||||
'season', 'modifier', 'delivery', 'delivery_part', 'delivery_part_modifier',
|
# 'season', 'modifier', 'delivery', 'delivery_part', 'delivery_part_modifier',
|
||||||
'payment_variant', 'delivery_payment', 'member_payment']
|
# 'payment_variant', 'delivery_payment', 'member_payment']
|
||||||
|
|
||||||
|
|
||||||
def get_sql_files() -> List[str]:
|
def get_sql_files() -> List[str]:
|
||||||
@ -51,6 +51,7 @@ def import_csv(cur: sqlite3.Cursor, table_name: str) -> None:
|
|||||||
sql = f'INSERT INTO {table_name} ({", ".join(names)}) VALUES ({", ".join(["?"] * len(names))})'
|
sql = f'INSERT INTO {table_name} ({", ".join(names)}) VALUES ({", ".join(["?"] * len(names))})'
|
||||||
print(sql)
|
print(sql)
|
||||||
cur.executemany(sql, values)
|
cur.executemany(sql, values)
|
||||||
|
print(f'{len(values)} inserts')
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
@ -81,8 +82,15 @@ if __name__ == '__main__':
|
|||||||
DB_CNX.executescript(sql_file.read())
|
DB_CNX.executescript(sql_file.read())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
DB_CNX.isolation_level = None
|
||||||
|
DB_CNX.execute("PRAGMA foreign_keys = OFF")
|
||||||
|
DB_CNX.execute("BEGIN")
|
||||||
for table in TABLES:
|
for table in TABLES:
|
||||||
import_csv(DB_CNX.cursor(), table)
|
import_csv(DB_CNX.cursor(), table)
|
||||||
DB_CNX.commit()
|
DB_CNX.execute("COMMIT")
|
||||||
|
except Exception as err:
|
||||||
|
DB_CNX.execute("ROLLBACK")
|
||||||
|
raise err
|
||||||
finally:
|
finally:
|
||||||
|
DB_CNX.execute("PRAGMA foreign_keys = ON")
|
||||||
DB_CNX.close()
|
DB_CNX.close()
|
||||||
|
@ -314,7 +314,7 @@ def migrate_members(in_dir: str, out_dir: str) -> None:
|
|||||||
'country;postal_dest;address;'
|
'country;postal_dest;address;'
|
||||||
'email;phone_landline;phone_mobile_1;phone_mobile_2;'
|
'email;phone_landline;phone_mobile_1;phone_mobile_2;'
|
||||||
'default_kgnr;comment\n')
|
'default_kgnr;comment\n')
|
||||||
f_mba.write('mgr;name;country;postal_dest;address\n')
|
f_mba.write('mgnr;name;country;postal_dest;address\n')
|
||||||
|
|
||||||
for m in members:
|
for m in members:
|
||||||
mgnr: int = m['MGNR']
|
mgnr: int = m['MGNR']
|
||||||
@ -507,20 +507,26 @@ def migrate_members(in_dir: str, out_dir: str) -> None:
|
|||||||
|
|
||||||
okz = postal_dest % 100000 if postal_dest else None
|
okz = postal_dest % 100000 if postal_dest else None
|
||||||
kgnr = lookup_kgnr(okz)
|
kgnr = lookup_kgnr(okz)
|
||||||
|
active = m['Aktives Mitglied'] or False
|
||||||
if kgnr is None:
|
if kgnr is None:
|
||||||
invalid(mgnr, 'KgNr.', ort)
|
invalid(mgnr, 'KgNr.', ort)
|
||||||
|
active = False
|
||||||
|
|
||||||
|
if postal_dest is None:
|
||||||
|
invalid(mgnr, 'PLZ', None)
|
||||||
|
continue
|
||||||
|
|
||||||
f_m.write(csv.format_row(
|
f_m.write(csv.format_row(
|
||||||
mgnr, m['MGNR-Vorgänger'], prefix, given_name, middle_names, family_name, suffix,
|
mgnr, m['MGNR-Vorgänger'], prefix, given_name, middle_names, family_name, suffix,
|
||||||
m['Geburtsjahr'], m['Eintrittsdatum'], m['Austrittsdatum'], m['Geschäftsanteile1'] or 0,
|
m['Geburtsjahr'], m['Eintrittsdatum'], m['Austrittsdatum'], m['Geschäftsanteile1'] or 0,
|
||||||
m['BHKontonummer'], zwstid, bnr, ustid,
|
m['BHKontonummer'], zwstid, bnr, ustid,
|
||||||
m['Volllieferant'] or False, m['Buchführend'] or False, False, m['Aktives Mitglied'] or False,
|
m['Volllieferant'] or False, m['Buchführend'] or False, False, active,
|
||||||
iban, bic, 'AT', postal_dest, address, email, phone_landline,
|
iban, bic, 'AT', postal_dest, address or '-', email, phone_landline,
|
||||||
phone_mobile[0] if len(phone_mobile) > 0 else None, phone_mobile[1] if len(phone_mobile) > 1 else None,
|
phone_mobile[0] if len(phone_mobile) > 0 else None, phone_mobile[1] if len(phone_mobile) > 1 else None,
|
||||||
kgnr, m['Anmerkung']
|
kgnr, m['Anmerkung']
|
||||||
))
|
))
|
||||||
if billing_name:
|
if billing_name:
|
||||||
f_mba.write(csv.format_row(mgnr, billing_name, 'AT', None, None))
|
f_mba.write(csv.format_row(mgnr, billing_name, 'AT', postal_dest, address or '-'))
|
||||||
|
|
||||||
|
|
||||||
def migrate_contracts(in_dir: str, out_dir: str) -> None:
|
def migrate_contracts(in_dir: str, out_dir: str) -> None:
|
||||||
@ -572,7 +578,7 @@ def migrate_contracts(in_dir: str, out_dir: str) -> None:
|
|||||||
]
|
]
|
||||||
|
|
||||||
invalid(mgnr, 'GstNr.', f'{kgnr:05}-{nr_str}')
|
invalid(mgnr, 'GstNr.', f'{kgnr:05}-{nr_str}')
|
||||||
return [nr_str]
|
return []
|
||||||
|
|
||||||
with open(f'{out_dir}/contract.csv', 'w+') as f_c, open(f'{out_dir}/area_commitment.csv', 'w+') as f_fb:
|
with open(f'{out_dir}/contract.csv', 'w+') as f_c, open(f'{out_dir}/area_commitment.csv', 'w+') as f_fb:
|
||||||
f_c.write('vnr;mgnr;year_from;year_to\n')
|
f_c.write('vnr;mgnr;year_from;year_to\n')
|
||||||
@ -596,10 +602,11 @@ def migrate_contracts(in_dir: str, out_dir: str) -> None:
|
|||||||
|
|
||||||
if parz is None or parz == '0000':
|
if parz is None or parz == '0000':
|
||||||
invalid(fb['MGNR'], 'GstNr.', f'{kgnr or 0:05}-{parz}')
|
invalid(fb['MGNR'], 'GstNr.', f'{kgnr or 0:05}-{parz}')
|
||||||
|
gstnrs = ['99999']
|
||||||
elif len(gstnrs) > 1 or (len(gstnrs) == 1 and gstnrs[0] != parz):
|
elif len(gstnrs) > 1 or (len(gstnrs) == 1 and gstnrs[0] != parz):
|
||||||
convert(fb['MGNR'], 'GstNr.', f'{kgnr or 0:05}-{parz or ""}', ', '.join(gstnrs))
|
convert(fb['MGNR'], 'GstNr.', f'{kgnr or 0:05}-{parz or ""}', ', '.join(gstnrs))
|
||||||
|
|
||||||
for i, gstnr in enumerate(gstnrs or ['0000']):
|
for i, gstnr in enumerate(gstnrs):
|
||||||
a = area - gst_area * (len(gstnrs) - 1) if i == 0 else gst_area
|
a = area - gst_area * (len(gstnrs) - 1) if i == 0 else gst_area
|
||||||
rdnr = REED_MAP[fb['RNR']][1] if fb['RNR'] else None
|
rdnr = REED_MAP[fb['RNR']][1] if fb['RNR'] else None
|
||||||
f_fb.write(csv.format_row(
|
f_fb.write(csv.format_row(
|
||||||
|
Reference in New Issue
Block a user