Skip to content

Commit

Permalink
Merge pull request #20 from Sha-yol/abstract-foreign-currency
Browse files Browse the repository at this point in the history
Refactor adding amount to transaction from `getExpenseTransactionBody`
  • Loading branch information
adyanth authored Oct 22, 2024
2 parents 6caefef + 9f706fa commit e2fd225
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,23 +349,37 @@ def getExpenseTransactionBody(exp: Expense, myshare: ExpenseUser, data: list[str
"destination_name": dest,
"category_name": category,
"type": "withdrawal",
"amount": myshare.getOwedShare(),
"date": getDate(exp.getCreatedAt()).isoformat(),
"payment_date": getDate(exp.getDate()).isoformat(),
"description": description,
"reconciled": False,
"notes": notes,
"external_url": getSWUrlForExpense(exp),
"tags": [],
}
if getAccountCurrencyCode(source) != exp.getCurrencyCode():
newTxn["foreign_currency_code"] = exp.getCurrencyCode()
newTxn["foreign_amount"] = myshare.getOwedShare()
newTxn["amount"] = 0.1
newTxn["tags"] = [conf["FOREIGN_CURRENCY_TOFIX_TAG"]]
newTxn = applyExpenseAmountToTransaction(newTxn, exp, myshare)
print(
f"Processing {category} {formatExpense(exp, myshare)} from {source} to {dest}")
return newTxn

def applyExpenseAmountToTransaction(transaction: dict, exp: Expense, myshare: ExpenseUser) -> dict:
"""Apply the amount to the transaction based on the currency of the account.
:param transaction: The transaction dictionary
:param exp: The Splitwise expense
:param myshare: The user's share in the expense
:return: The updated transaction dictionary
"""
amount = myshare.getOwedShare()
if getAccountCurrencyCode(transaction["source_name"]) == exp.getCurrencyCode():
transaction["amount"] = amount
else:
transaction["foreign_currency_code"] = exp.getCurrencyCode()
transaction["foreign_amount"] = amount
transaction["amount"] = 0.1
transaction["tags"].append(conf["FOREIGN_CURRENCY_TOFIX_TAG"])


def getAccounts(account_type: str="asset") -> list:
"""Get accounts from Firefly.
Expand Down

2 comments on commit e2fd225

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
main.py2025771%93, 97, 104, 108, 112, 127, 137, 149, 175–178, 232–233, 235–236, 238–239, 242–245, 247–248, 250, 253, 255–258, 260–261, 271, 276–279, 281–282, 301, 303, 340, 377–380, 416, 420, 423, 425, 427–430, 432–433, 435
TOTAL2025771% 

Tests Skipped Failures Errors Time
16 0 💤 1 ❌ 0 🔥 0.649s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
main.py2025771%93, 97, 104, 108, 112, 127, 137, 149, 175–178, 232–233, 235–236, 238–239, 242–245, 247–248, 250, 253, 255–258, 260–261, 271, 276–279, 281–282, 301, 303, 340, 377–380, 416, 420, 423, 425, 427–430, 432–433, 435
TOTAL2025771% 

Tests Skipped Failures Errors Time
16 0 💤 1 ❌ 0 🔥 2.830s ⏱️

Please sign in to comment.