Skip to content

Commit

Permalink
Fix entries always using value read, not absolute (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: Ramon <ramon.guimera@skyscanner.net>
  • Loading branch information
w0rmr1d3r and Ramon committed Oct 21, 2022
1 parent 2ae8f04 commit 1b42a12
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion finance_tracker/entries/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ def month_from_date_of_action(self) -> int:

@classmethod
def from_revolut_entry(cls, revolut_entry: RevolutEntry):
"""
Returns an entry from a RevolutEntry. Values not recognized or not being in RevolutEntry will be created
with default values.
:param revolut_entry: RevolutEntry to obtain data from
:return: Entry from a RevolutEntry
"""
return cls(
entry_date=revolut_entry.started_date_for_entry(),
date_of_action=revolut_entry.completed_date_for_entry(),
title=revolut_entry.description,
other_data="",
quantity=revolut_entry.quantity_as_absolute(),
quantity=revolut_entry.quantity(),
balance=revolut_entry.balance_as_money(),
)
8 changes: 8 additions & 0 deletions finance_tracker/entries/revolut_entry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from dataclasses import dataclass
from datetime import date, datetime

from deprecated.classic import deprecated

from finance_tracker.money.currency_codes import CurrencyCodes
from finance_tracker.money.money import Money

Expand All @@ -19,8 +21,14 @@ class RevolutEntry:
balance: float

def quantity(self) -> Money:
"""
Returns the quantity of this entry as a Money object composed of
the same amount and currency code from its currency.
:return: Money from amount and currency
"""
return Money(amount=self.amount, currency_code=CurrencyCodes[self.currency])

@deprecated(reason="Use quantity. Entries use the value its read, no absolute.", version="1.1.0")
def quantity_as_absolute(self) -> Money:
return Money(amount=abs(self.amount), currency_code=CurrencyCodes[self.currency])

Expand Down
2 changes: 1 addition & 1 deletion tests/entries/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def test_entry_from_revolut_entry(revolut_entry):
assert entry.date_of_action_as_time() == date(day=3, month=10, year=2022)
assert entry.title == "Supermarket purchase"
assert entry.other_data == ""
assert entry.quantity == Money(amount=4, currency_code=CurrencyCodes.EUR)
assert entry.quantity == Money(amount=-4, currency_code=CurrencyCodes.EUR)
assert entry.balance == Money(amount=100, currency_code=CurrencyCodes.EUR)

0 comments on commit 1b42a12

Please sign in to comment.