Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #177

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

fix #177

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool.setuptools_scm]

[build-system]
requires = ["setuptools>=64", "setuptools-scm>=8.0"]
build-backend = "setuptools.build_meta"

11 changes: 10 additions & 1 deletion src/oscar_accounts/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def save(self, *args, **kwargs):
if self.code:
self.code = self.code.upper()
# Ensure the balance is always correct when saving
return super().save(*args, **kwargs)
self.balance = self._balance()
return super().save(*args, **kwargs)

Expand All @@ -161,6 +162,10 @@ def num_transactions(self):
def has_credit_limit(self):
return self.credit_limit is not None

@property
def realbalance(self):
return self._balance()

def is_debit_permitted(self, amount):
"""
Test if the a debit for the passed amount is permitted
Expand Down Expand Up @@ -193,7 +198,7 @@ def permitted_allocation(self, basket, shipping_total, order_total):
range_total = D('0.00')
for line in basket.all_lines():
if self.product_range.contains_product(line.product):
range_total += line.line_price_incl_tax_and_discounts
range_total += line.line_price_incl_tax_incl_discounts
if self.can_be_used_for_non_products:
range_total += shipping_total
return min(range_total, self.balance)
Expand Down Expand Up @@ -380,6 +385,10 @@ def save(self, *args, **kwargs):
if not self.reference:
self.reference = self._generate_reference()
super().save(update_fields=['reference'])
self.destination.balance += self.amount
self.destination.save()
self.source.balance -= self.amount
self.source.save()

def _generate_reference(self):
obj = hmac.new(key=settings.SECRET_KEY.encode(),
Expand Down