Skip to content

Commit

Permalink
Refine and document totals calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
NeryK committed Feb 1, 2022
1 parent 2c7d2a5 commit 43ce2ce
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion steampurch/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ def convert(data):

def sum_transactions(transactions, currency):
"""Sum debit and credit transactions for a given currency"""
# Total debit = sum of transactions that are not refunds and do not decrease wallet
total_debit = sum([
transaction.total_amount_numeric
for transaction in transactions
if not transaction.is_refund
and not transaction.wallet_change.startswith("-")
and transaction.total_currency == currency])
# Total credit = sum of transactions that are either:
# - refunds that do not increase wallet
# - credits (likely from the marketplace)
total_credit = sum([
transaction.total_amount_numeric
for transaction in transactions
if (transaction.is_refund or transaction.is_credit)
if ((transaction.is_refund and not transaction.wallet_change.startswith("+")) or transaction.is_credit)
and transaction.total_currency == currency])
return currency, round(total_debit - total_credit, 2)

Expand Down

0 comments on commit 43ce2ce

Please sign in to comment.