From a48a885ed6ad6557ad9a8b0965f9aee120e6dc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 1 Jul 2020 00:43:46 +0800 Subject: [PATCH] Added the get_absolute_url() method to the accounting transactions. --- accounting/models.py | 10 ++++++++++ accounting/templates/accounting/cash.html | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/accounting/models.py b/accounting/models.py index 40eb5f6..4edf2af 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -20,6 +20,7 @@ """ from django.db import models +from django.urls import reverse class Subject(models.Model): @@ -101,6 +102,15 @@ class Transaction(models.Model): and credit_records[0].subject.code == "1111" and credit_records[0].summary is None) + def get_absolute_url(self): + """Returns the URL to view this transaction.""" + if self.is_cash_expense: + return reverse("accounting:transaction", args=("expense", self.sn)) + elif self.is_cash_income: + return reverse("accounting:transaction", args=("income", self.sn)) + else: + return reverse("accounting:transaction", args=("transfer", self.sn)) + def __str__(self): """Returns the string representation of this accounting transaction.""" diff --git a/accounting/templates/accounting/cash.html b/accounting/templates/accounting/cash.html index 51f739f..9cea317 100644 --- a/accounting/templates/accounting/cash.html +++ b/accounting/templates/accounting/cash.html @@ -22,7 +22,7 @@ {{ record.debit_amount }} {{ record.credit_amount }} {{ record.amount }} - View + View {% endfor %}