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 e9ef87a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/oscar_accounts/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ 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)
# Django 4.2 requires a pk to use manager methods as in self._balance()
if self.pk is not None:
self.balance = self._balance()
super().save()

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

0 comments on commit e9ef87a

Please sign in to comment.