diff --git a/src/allmende_payment_system/cli.py b/src/allmende_payment_system/cli.py index 9f08b46..f7fd0bf 100644 --- a/src/allmende_payment_system/cli.py +++ b/src/allmende_payment_system/cli.py @@ -76,7 +76,14 @@ def import_csv(filepath: str): ) for row in rows: - if row["typ"].lower() not in ["essen", "essen kind"]: + transaction_type = row["typ"].lower() + if transaction_type not in [ + "essen", + "essen kind", + "einzahlung", + "einkauf", + "auszahlung", + ]: # TODO: Handle other types continue @@ -91,36 +98,55 @@ def import_csv(filepath: str): db.add(account) db.flush() - if row["stueck"] == 0: - # if no quantity is given, assume it's 1 for non-zero amounts - quantity = row["betrag"] / (3 if row["typ"].lower() == "essen" else 1.5) - else: - quantity = row["stueck"] + if transaction_type == "essen" or transaction_type == "essen kind": + if row["stueck"] == 0: + # if no quantity is given, assume it's 1 for non-zero amounts + quantity = row["betrag"] / (3 if transaction_type == "essen" else 1.5) + else: + quantity = row["stueck"] - timestamp = datetime.combine(row["datum"], time(18, 30, 0)) + timestamp = datetime.combine(row["datum"], time(18, 30, 0)) - order = Order(user_id=1) + order = Order(user_id=1) - order.items.append( - OrderItem( - order=order, - product=( - meal_product if row["typ"].lower() == "essen" else kids_meal_product - ), + order.items.append( + OrderItem( + order=order, + product=( + meal_product + if transaction_type == "essen" + else kids_meal_product + ), + total_amount=row["betrag"], + quantity=quantity, + ) + ) + + transaction = Transaction( + type="order", + timestamp=timestamp, total_amount=row["betrag"], quantity=quantity, + account_id=account.id, + order=order, ) - ) - - transaction = Transaction( - type="order", - timestamp=timestamp, - total_amount=row["betrag"], - quantity=quantity, - account_id=account.id, - order=order, - ) - db.add(transaction) + db.add(transaction) + elif transaction_type == "einzahlung" or transaction_type == "einkauf": + transaction = Transaction( + type="deposit", + timestamp=datetime.combine(row["datum"], time(12, 0, 0)), + total_amount=row["betrag"], + account_id=account.id, + ) + db.add(transaction) + elif transaction_type == "auszahlung": + transaction = Transaction( + type="withdrawal", + timestamp=datetime.combine(row["datum"], time(12, 0, 0)), + total_amount=row["betrag"], + account_id=account.id, + ) + db.add(transaction) db.flush() db.commit()