summaryrefslogtreecommitdiff
path: root/talerbank/app/models.py
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2017-12-22 21:55:56 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2017-12-22 21:55:56 +0100
commit4e1f605a97f48f6300f632b64f46b4d9e98714f5 (patch)
tree7df2771acd9aa0313ddf282c6e9d86e3befe6e66 /talerbank/app/models.py
parent9db330755e89eb233900474fcf454320eb5f678c (diff)
downloadbank-4e1f605a97f48f6300f632b64f46b4d9e98714f5.tar.gz
bank-4e1f605a97f48f6300f632b64f46b4d9e98714f5.tar.bz2
bank-4e1f605a97f48f6300f632b64f46b4d9e98714f5.zip
Implementing #5222.
Diffstat (limited to 'talerbank/app/models.py')
-rw-r--r--talerbank/app/models.py63
1 files changed, 41 insertions, 22 deletions
diff --git a/talerbank/app/models.py b/talerbank/app/models.py
index f8c5c47..a584912 100644
--- a/talerbank/app/models.py
+++ b/talerbank/app/models.py
@@ -1,16 +1,18 @@
# This file is part of TALER
# (C) 2014, 2015, 2016 INRIA
#
-# TALER is free software; you can redistribute it and/or modify it under the
-# terms of the GNU Affero General Public License as published by the Free Software
-# Foundation; either version 3, or (at your option) any later version.
+# TALER is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation; either version 3, or
+# (at your option) any later version. TALER is distributed in the
+# hope that it will be useful, but WITHOUT ANY WARRANTY; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
#
-# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+# You should have received a copy of the GNU General Public License
+# along with TALER; see the file COPYING. If not, see
+# <http://www.gnu.org/licenses/>
#
# @author Marcello Stanisci
# @author Florian Dold
@@ -20,7 +22,9 @@ from typing import Any, Tuple
from django.contrib.auth.models import User
from django.db import models
from django.conf import settings
-from django.core.exceptions import ValidationError
+from django.core.exceptions import \
+ ValidationError, \
+ ObjectDoesNotExist
from .amount import Amount, BadFormatAmount
class AmountField(models.Field):
@@ -28,7 +32,8 @@ class AmountField(models.Field):
description = 'Amount object in Taler style'
def deconstruct(self) -> Tuple[str, str, list, dict]:
- name, path, args, kwargs = super(AmountField, self).deconstruct()
+ name, path, args, kwargs = super(
+ AmountField, self).deconstruct()
return name, path, args, kwargs
def db_type(self, connection: Any) -> str:
@@ -55,28 +60,42 @@ class AmountField(models.Field):
return Amount.parse(settings.TALER_CURRENCY)
return Amount.parse(value)
except BadFormatAmount:
- raise ValidationError("Invalid input for an amount string: %s" % value)
+ raise ValidationError(
+ "Invalid input for an amount string: %s" % value)
def get_zero_amount() -> Amount:
return Amount(settings.TALER_CURRENCY)
+class BankAccountDoesNotExist(ObjectDoesNotExist):
+ hint = "Specified bank account does not exist"
+ http_status_code = 404
+
+class BankTransactionDoesNotExist(ObjectDoesNotExist):
+ hint = "Specified bank transaction does not exist"
+ http_status_code = 404
+
class BankAccount(models.Model):
is_public = models.BooleanField(default=False)
debit = models.BooleanField(default=False)
account_no = models.AutoField(primary_key=True)
user = models.OneToOneField(User, on_delete=models.CASCADE)
amount = AmountField(default=get_zero_amount)
+ DoesNotExist = BankAccountDoesNotExist
class BankTransaction(models.Model):
amount = AmountField(default=False)
- debit_account = models.ForeignKey(BankAccount,
- on_delete=models.CASCADE,
- db_index=True,
- related_name="debit_account")
- credit_account = models.ForeignKey(BankAccount,
- on_delete=models.CASCADE,
- db_index=True,
- related_name="credit_account")
- subject = models.CharField(default="(no subject given)", max_length=200)
- date = models.DateTimeField(auto_now=True, db_index=True)
+ debit_account = models.ForeignKey(
+ BankAccount,
+ on_delete=models.CASCADE,
+ db_index=True,
+ related_name="debit_account")
+ credit_account = models.ForeignKey(
+ BankAccount,
+ on_delete=models.CASCADE,
+ db_index=True,
+ related_name="credit_account")
+ subject = models.CharField(
+ default="(no subject given)", max_length=200)
+ date = models.DateTimeField(
+ auto_now=True, db_index=True)
cancelled = models.BooleanField(default=False)