Renamed the sn column to id in the accounting application.

This commit is contained in:
依瑪貓 2020-08-04 01:59:51 +08:00
parent 733335c715
commit 44e22d711f
2 changed files with 7 additions and 8 deletions

View File

@ -28,10 +28,10 @@ from mia_core.utils import get_multi_lingual_attr, set_multi_lingual_attr
class Account(DirtyFieldsMixin, models.Model): class Account(DirtyFieldsMixin, models.Model):
"""An account.""" """An account."""
sn = models.PositiveIntegerField(primary_key=True) id = models.PositiveIntegerField(primary_key=True)
parent = models.ForeignKey( parent = models.ForeignKey(
"self", on_delete=models.PROTECT, null=True, blank=True, "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) code = models.CharField(max_length=5, unique=True)
title_zh_hant = models.CharField( title_zh_hant = models.CharField(
max_length=32, db_column="title_zhtw") max_length=32, db_column="title_zhtw")
@ -89,7 +89,7 @@ class Account(DirtyFieldsMixin, models.Model):
class Transaction(DirtyFieldsMixin, models.Model): class Transaction(DirtyFieldsMixin, models.Model):
"""An accounting transaction.""" """An accounting transaction."""
sn = models.PositiveIntegerField(primary_key=True) id = models.PositiveIntegerField(primary_key=True)
date = models.DateField() date = models.DateField()
ord = models.PositiveSmallIntegerField(default=1) ord = models.PositiveSmallIntegerField(default=1)
notes = models.CharField(max_length=128, null=True, blank=True) notes = models.CharField(max_length=128, null=True, blank=True)
@ -264,14 +264,13 @@ class Transaction(DirtyFieldsMixin, models.Model):
class Record(DirtyFieldsMixin, models.Model): class Record(DirtyFieldsMixin, models.Model):
"""An accounting record.""" """An accounting record."""
sn = models.PositiveIntegerField(primary_key=True) id = models.PositiveIntegerField(primary_key=True)
transaction = models.ForeignKey( transaction = models.ForeignKey(
Transaction, on_delete=models.CASCADE, Transaction, on_delete=models.CASCADE)
db_column="transaction_sn")
is_credit = models.BooleanField() is_credit = models.BooleanField()
ord = models.PositiveSmallIntegerField() ord = models.PositiveSmallIntegerField()
account = models.ForeignKey( 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) summary = models.CharField(max_length=128, blank=True, null=True)
amount = models.PositiveIntegerField() amount = models.PositiveIntegerField()
created_at = models.DateTimeField( created_at = models.DateTimeField(

View File

@ -273,7 +273,7 @@ def get_ledger_accounts():
FROM accounting_accounts AS s FROM accounting_accounts AS s
INNER JOIN (SELECT s.code INNER JOIN (SELECT s.code
FROM accounting_accounts AS s 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 GROUP BY s.code) AS u
ON u.code LIKE s.code || '%' ON u.code LIKE s.code || '%'
GROUP BY s.code) GROUP BY s.code)