Skip to content

Commit

Permalink
fix regression for recurring transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JJtan2002 committed Jun 18, 2024
1 parent 5bbb613 commit 659ca1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/budget_tracking/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create_recurrent_transaction(self, user_pk, **kwargs):
'title': self.faker.text(max_nb_chars=10),
'value': self.faker.random_number(digits=2),
'type': self.faker.transaction_type(),
'date': datetime.datetime.now(),
'date': get_and_pop(kwargs, 'date') or datetime.datetime.now(),
'recurrent': True,
# Recurrency section
'amount': kwargs.get('amount') or self.faker.random_int(min=1, max=31),
Expand Down
6 changes: 4 additions & 2 deletions backend/budget_tracking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@ def create_from_json(data: dict, user_pk: int) -> 'Transaction':
transaction.type = data.get("type")
if data.get("date"):
date_string = data.get("date")
if isinstance(date_string, datetime):
transaction.date = date_string.date()
else: transaction.date = datetime.strptime(date_string, "%Y-%m-%d")
#date_object = datetime.strptime(
#date_string, "%Y-%m-%dT%H:%M:%S.%fZ")
transaction.date = datetime.strptime(date_string, "%Y-%m-%d")
#date_string, "%Y-%m-%dT%H:%M:%S.%fZ")
if data.get("updateWallet") is not None:
transaction.update_wallet = data.get("updateWallet")

Expand Down
22 changes: 11 additions & 11 deletions backend/budget_tracking/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_transaction_updates_wallet(self):
Check if a given transaction of type `EXPENSE`, when `update_wallet` is True, updates the wallet's current
amount
"""
transaction = self.factory.create_transaction_filled(self.wallet, type='EXPENSE', update_wallet=True)
transaction = self.factory.create_transaction_filled(self.wallet, type='Expense', update_wallet=True)
current_wallet_amount = self.STARTER_WALLET_AMOUNT - transaction.value
self.assertEqual(Decimal(current_wallet_amount), self.wallet.get_current_amount())

Expand All @@ -47,15 +47,15 @@ def test_get_monthly_earnings(self):
out_of_range = one_month_ago - relativedelta(days=1)
in_range = datetime.datetime.today() - relativedelta(days=1)

earnings_in_range = self.factory.create_transaction_filled(self.wallet, type="EARNING", value=150)
earning_in_range2 = self.factory.create_transaction_filled(self.wallet, type="EARNING", value=50, date=in_range)
earning_out_of_range1 = self.factory.create_transaction_filled(self.wallet, type="EARNING", value=300,
earnings_in_range = self.factory.create_transaction_filled(self.wallet, type="Earning", value=150)
earning_in_range2 = self.factory.create_transaction_filled(self.wallet, type="Earning", value=50, date=in_range)
earning_out_of_range1 = self.factory.create_transaction_filled(self.wallet, type="Earning", value=300,
date=one_month_ago)

earning_out_of_range2 = self.factory.create_transaction_filled(self.wallet, type="EARNING", date=out_of_range)
earning_out_of_range2 = self.factory.create_transaction_filled(self.wallet, type="Earning", date=out_of_range)

# these transactions shouldn't be considered in the queryset since it's not an earning
expense_in_range = self.factory.create_transaction_filled(self.wallet, type="EXPENSE", date=in_range)
expense_in_range = self.factory.create_transaction_filled(self.wallet, type="Expense", date=in_range)

# Sum of all set transactions values
expected_value = 200
Expand All @@ -67,14 +67,14 @@ def test_get_monthly_expenses(self):
out_of_range = one_month_ago - relativedelta(days=1)
in_range = datetime.datetime.today() + relativedelta(days=1)

expense_in_range = self.factory.create_transaction_filled(self.wallet, type="EXPENSE", value=150)
expense_in_range2 = self.factory.create_transaction_filled(self.wallet, type="EXPENSE", value=50, date=in_range)
expense_out_of_range1 = self.factory.create_transaction_filled(self.wallet, type="EXPENSE", value=300,
expense_in_range = self.factory.create_transaction_filled(self.wallet, type="Expense", value=150)
expense_in_range2 = self.factory.create_transaction_filled(self.wallet, type="Expense", value=50, date=in_range)
expense_out_of_range1 = self.factory.create_transaction_filled(self.wallet, type="Expense", value=300,
date=one_month_ago)
expense_out_of_range2 = self.factory.create_transaction_filled(self.wallet, type="EXPENSE",date=out_of_range)
expense_out_of_range2 = self.factory.create_transaction_filled(self.wallet, type="Expense",date=out_of_range)

# this transaction shouldn't be considered in the queryset since it's an earning
earning_in_range = self.factory.create_transaction_filled(self.wallet, type="EARNING", date=in_range)
earning_in_range = self.factory.create_transaction_filled(self.wallet, type="Earning", date=in_range)

expected_value = 200
monthly_earning = self.wallet.get_monthly_expenses()
Expand Down

0 comments on commit 659ca1d

Please sign in to comment.