Import: Handle deposits, withdrawals and expenses
This commit is contained in:
@@ -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,9 +98,10 @@ def import_csv(filepath: str):
|
||||
db.add(account)
|
||||
db.flush()
|
||||
|
||||
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 row["typ"].lower() == "essen" else 1.5)
|
||||
quantity = row["betrag"] / (3 if transaction_type == "essen" else 1.5)
|
||||
else:
|
||||
quantity = row["stueck"]
|
||||
|
||||
@@ -105,7 +113,9 @@ def import_csv(filepath: str):
|
||||
OrderItem(
|
||||
order=order,
|
||||
product=(
|
||||
meal_product if row["typ"].lower() == "essen" else kids_meal_product
|
||||
meal_product
|
||||
if transaction_type == "essen"
|
||||
else kids_meal_product
|
||||
),
|
||||
total_amount=row["betrag"],
|
||||
quantity=quantity,
|
||||
@@ -121,6 +131,22 @@ def import_csv(filepath: str):
|
||||
order=order,
|
||||
)
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user