From 44e22d711f524eb260b13a7dd7b5375004630f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 4 Aug 2020 01:59:51 +0800 Subject: [PATCH] Renamed the sn column to id in the accounting application. --- accounting/models.py | 13 ++++++------- accounting/utils.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/accounting/models.py b/accounting/models.py index 78b1246..2a705be 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -28,10 +28,10 @@ from mia_core.utils import get_multi_lingual_attr, set_multi_lingual_attr class Account(DirtyFieldsMixin, models.Model): """An account.""" - sn = models.PositiveIntegerField(primary_key=True) + id = models.PositiveIntegerField(primary_key=True) parent = models.ForeignKey( "self", on_delete=models.PROTECT, null=True, blank=True, - db_column="parent_sn", related_name="child_set") + related_name="child_set") code = models.CharField(max_length=5, unique=True) title_zh_hant = models.CharField( max_length=32, db_column="title_zhtw") @@ -89,7 +89,7 @@ class Account(DirtyFieldsMixin, models.Model): class Transaction(DirtyFieldsMixin, models.Model): """An accounting transaction.""" - sn = models.PositiveIntegerField(primary_key=True) + id = models.PositiveIntegerField(primary_key=True) date = models.DateField() ord = models.PositiveSmallIntegerField(default=1) notes = models.CharField(max_length=128, null=True, blank=True) @@ -264,14 +264,13 @@ class Transaction(DirtyFieldsMixin, models.Model): class Record(DirtyFieldsMixin, models.Model): """An accounting record.""" - sn = models.PositiveIntegerField(primary_key=True) + id = models.PositiveIntegerField(primary_key=True) transaction = models.ForeignKey( - Transaction, on_delete=models.CASCADE, - db_column="transaction_sn") + Transaction, on_delete=models.CASCADE) is_credit = models.BooleanField() ord = models.PositiveSmallIntegerField() account = models.ForeignKey( - Account, on_delete=models.PROTECT, db_column="account_sn") + Account, on_delete=models.PROTECT) summary = models.CharField(max_length=128, blank=True, null=True) amount = models.PositiveIntegerField() created_at = models.DateTimeField( diff --git a/accounting/utils.py b/accounting/utils.py index 940d402..9dde5e8 100644 --- a/accounting/utils.py +++ b/accounting/utils.py @@ -273,7 +273,7 @@ def get_ledger_accounts(): FROM accounting_accounts AS s INNER JOIN (SELECT s.code FROM accounting_accounts AS s - INNER JOIN accounting_records AS r ON r.account_sn = s.sn + INNER JOIN accounting_records AS r ON r.account_id = s.id GROUP BY s.code) AS u ON u.code LIKE s.code || '%' GROUP BY s.code)