Skip to content

Commit

Permalink
fix Account.save()
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgalloway-nobleai committed Apr 23, 2024
1 parent bd2ec46 commit 9e106da
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/oscar_accounts/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ def save(self, *args, **kwargs):
if self.code:
self.code = self.code.upper()
# Ensure the balance is always correct when saving
self.balance = self._balance()
return super().save(*args, **kwargs)
if self.pk is None:
# Django 4.2 requires a pk to use manager methods like in self._balance()
self.balance = 0
else:
self.balance = self._balance()
super().save()

def _balance(self):
aggregates = self.transactions.aggregate(sum=Sum('amount'))
Expand Down

0 comments on commit 9e106da

Please sign in to comment.