From 4acc008457c4d697c7662bb396b5c6cc6d5e92bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 19 Aug 2020 19:19:37 +0800 Subject: [PATCH] Renamed the Populator utility to DataFiller in the accounting application. --- .../management/commands/accounting_sample.py | 35 +++++++++++-------- accounting/utils.py | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/accounting/management/commands/accounting_sample.py b/accounting/management/commands/accounting_sample.py index c65fa0a..8cd4287 100644 --- a/accounting/management/commands/accounting_sample.py +++ b/accounting/management/commands/accounting_sample.py @@ -21,6 +21,7 @@ import datetime import random import sys +from typing import Optional from django.contrib.auth import get_user_model from django.core.management import BaseCommand, CommandParser @@ -28,13 +29,17 @@ from django.db import transaction from django.db.models import PositiveIntegerField from django.utils import timezone -from accounting.utils import Populator +from accounting.utils import DataFiller from mia_core.utils import new_pk class Command(BaseCommand): """Populates the database with sample accounting data.""" - help = "Populates the database with sample accounting data." + help = "Fills the database with sample accounting data." + + def __init__(self): + super().__init__() + self._filler: Optional[DataFiller] = None def add_arguments(self, parser): """Adds command line arguments to the parser. @@ -74,8 +79,8 @@ class Command(BaseCommand): user.set_digest_password("admin", "12345") user.save() - self._populator: Populator = Populator(user) - self._populator.add_accounts([ + self._filler = DataFiller(user) + self._filler.add_accounts([ (1, "資產", "assets", "资产"), (2, "負債", "liabilities", "负债"), (3, "業主權益", "owners’ equity", "业主权益"), @@ -141,43 +146,43 @@ class Command(BaseCommand): self.add_payrolls(5) - self._populator.add_income_transaction( + self._filler.add_income_transaction( -15, [(1113, "ATM withdrawal", 2000)]) - self._populator.add_transfer_transaction( + self._filler.add_transfer_transaction( -14, [(6254, "HSR—New Land→South Lake City", 1490)], [(2141, "HSR—New Land→South Lake City", 1490)]) - self._populator.add_transfer_transaction( + self._filler.add_transfer_transaction( -14, [(6273, "Movies—The Avengers", 80)], [(2141, "Movies—The Avengers", 80)]) - self._populator.add_transfer_transaction( + self._filler.add_transfer_transaction( -13, [(6273, "Movies—2001: A Space Odyssey", 80)], [(2141, "Movies—2001: A Space Odyssey", 80)]) - self._populator.add_transfer_transaction( + self._filler.add_transfer_transaction( -11, [(2141, "Movies—The Avengers", 80)], [(1113, "Movies—The Avengers", 80)]) - self._populator.add_expense_transaction( + self._filler.add_expense_transaction( -13, [(6273, "Bus—2623—Uptown→City Park", 30)]) - self._populator.add_expense_transaction( + self._filler.add_expense_transaction( -2, [(6272, "Lunch—Spaghetti", random.randint(40, 200)), (6272, "Drink—Tea", random.randint(40, 200))]) - self._populator.add_expense_transaction( + self._filler.add_expense_transaction( -1, ([(6272, "Lunch—Pizza", random.randint(40, 200)), (6272, "Drink—Tea", random.randint(40, 200))])) - self._populator.add_expense_transaction( + self._filler.add_expense_transaction( -1, [(6272, "Lunch—Spaghetti", random.randint(40, 200)), (6272, "Drink—Soda", random.randint(40, 200))]) - self._populator.add_expense_transaction( + self._filler.add_expense_transaction( 0, [(6272, "Lunch—Salad", random.randint(40, 200)), (6272, "Drink—Coffee", random.randint(40, 200))]) @@ -238,7 +243,7 @@ class Command(BaseCommand): if month < 1: month = 12 month_text = months[month - 1] - self._populator.add_transfer_transaction( + self._filler.add_transfer_transaction( payday, [(1113, "Payroll Transfer", savings), (1314, F"Pension for {month_text}", pension), diff --git a/accounting/utils.py b/accounting/utils.py index 30b731e..752b69d 100644 --- a/accounting/utils.py +++ b/accounting/utils.py @@ -128,7 +128,7 @@ class ReportUrl: current_app=self._namespace) -class Populator: +class DataFiller: """The helper to populate the accounting data. Args: