diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5bb298f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.setuptools_scm] + +[build-system] +requires = ["setuptools>=64", "setuptools-scm>=8.0"] +build-backend = "setuptools.build_meta" + diff --git a/src/oscar_accounts/abstract_models.py b/src/oscar_accounts/abstract_models.py index 35c9535..d877683 100644 --- a/src/oscar_accounts/abstract_models.py +++ b/src/oscar_accounts/abstract_models.py @@ -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) @@ -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 @@ -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) @@ -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(),