[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-bank] branch master updated: fix #4824's related iss
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-bank] branch master updated: fix #4824's related issues |
Date: |
Tue, 21 Mar 2017 14:54:11 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository bank.
The following commit(s) were added to refs/heads/master by this push:
new a37e84d fix #4824's related issues
a37e84d is described below
commit a37e84da7c180ac44c6b9c43ab4219be67d375b8
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Mar 21 14:30:28 2017 +0100
fix #4824's related issues
---
talerbank/app/amounts.py | 18 +++++++++++++++++-
talerbank/app/models.py | 27 ++++++++++++++++++++++++---
talerbank/app/static/web-common | 2 +-
talerbank/app/views.py | 6 +++---
4 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/talerbank/app/amounts.py b/talerbank/app/amounts.py
index 93f65e6..d76eaff 100644
--- a/talerbank/app/amounts.py
+++ b/talerbank/app/amounts.py
@@ -24,6 +24,22 @@ logger = logging.getLogger(__name__)
FRACTION = 100000000
+def amount_add(a1, a2):
+ assert(a1["currency"] == a2["currency"])
+ a1_float = floatify(a1)
+ a2_float = floatify(a2)
+ return parse_amount("%s %s" % (str(a1_float + a2_float), a2["currency"]))
+
+def amount_sub(a1, a2):
+ assert(a1["currency"] == a2["currency"])
+ a1_float = floatify(a1)
+ a2_float = floatify(a2)
+ sub = a1_float - a2_float
+ fmt = "%s %s" % (str(sub), a2["currency"])
+ logger.info(fmt)
+ return parse_amount(fmt)
+
+
def floatify(amount_dict):
return amount_dict['value'] + (float(amount_dict['fraction']) /
float(FRACTION))
@@ -36,7 +52,7 @@ def parse_amount(amount_str):
Parse amount of return None if not a
valid amount string
"""
- parsed = re.search("^\s*([0-9]+)(\.[0-9]+)? ([-_*A-Za-z0-9]+)\s*$",
amount_str)
+ parsed = re.search("^\s*((-)?[0-9]+)(\.[0-9]+)? ([-_*A-Za-z0-9]+)\s*$",
amount_str)
if not parsed:
return None
value = int(parsed.group(1))
diff --git a/talerbank/app/models.py b/talerbank/app/models.py
index 0543fbb..f87caa2 100644
--- a/talerbank/app/models.py
+++ b/talerbank/app/models.py
@@ -28,13 +28,34 @@ class BankAccount(models.Model):
currency = models.CharField(max_length=12, default="")
account_no = models.AutoField(primary_key=True)
user = models.OneToOneField(User, on_delete=models.CASCADE)
-
+ def _get_balance(self):
+ return dict(value=self.balance_value,
+ fraction=self.balance_fraction,
+ currency=self.currency)
+ def _set_balance(self, amount):
+ self.balance_value = amount["value"]
+ self.balance_fraction = amount["fraction"]
+ self.currency = amount["currency"]
+ balance_obj = property(_get_balance, _set_balance)
class BankTransaction(models.Model):
amount_value = models.IntegerField(default=0)
amount_fraction = models.IntegerField(default=0)
currency = models.CharField(max_length=12)
- debit_account = models.ForeignKey(BankAccount, on_delete=models.CASCADE,
related_name="debit_account")
- credit_account = models.ForeignKey(BankAccount, on_delete=models.CASCADE,
related_name="credit_account")
+ debit_account = models.ForeignKey(BankAccount,
+ on_delete=models.CASCADE,
+ related_name="debit_account")
+ credit_account = models.ForeignKey(BankAccount,
+ on_delete=models.CASCADE,
+ related_name="credit_account")
subject = models.CharField(default="(no subject given)", max_length=200)
date = models.DateTimeField(auto_now=True)
+ def _get_amount(self):
+ return dict(value=self.amount_value,
+ fraction=self.amount_fraction,
+ currency=self.currency)
+ def _set_amount(self, amount):
+ self.amount_value = amount["value"]
+ self.amount_fraction = amount["fraction"]
+ self.currency = amount["currency"]
+ amount_obj = property(_get_amount, _set_amount)
diff --git a/talerbank/app/static/web-common b/talerbank/app/static/web-common
index 6dd8ca1..dc9d5ab 160000
--- a/talerbank/app/static/web-common
+++ b/talerbank/app/static/web-common
@@ -1 +1 @@
-Subproject commit 6dd8ca1675817cc0ca65f0819489234eeafaa2ed
+Subproject commit dc9d5ab2308fef7cdd1e8c95fbf4fdd51bed7bfb
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 4225956..57dc42a 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -263,7 +263,7 @@ def extract_history(account):
counterpart = item.credit_account
sign = -1
entry = dict(
- float_amount=amounts.stringify(item.amount * sign),
+ float_amount=amounts.stringify(amounts.floatify(item.amount_obj) *
sign),
float_currency=item.currency,
counterpart=counterpart.account_no,
counterpart_username=counterpart.user.username,
@@ -391,8 +391,8 @@ def wire_transfer(amount,
credit_account=credit_account,
debit_account=debit_account,
subject=subject)
- debit_account.balance -= float_amount
- credit_account.balance += float_amount
+ debit_account.balance_obj = amounts.amount_sub(debit_account.balance_obj,
amount)
+ credit_account.balance_obj =
amounts.amount_add(credit_account.balance_obj, amount)
with transaction.atomic():
debit_account.save()
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-bank] branch master updated: fix #4824's related issues,
gnunet <=