Renamed the Populator utility to DataFiller in the accounting application.

This commit is contained in:
依瑪貓 2020-08-19 19:19:37 +08:00
parent 007fd7d73f
commit 4acc008457
2 changed files with 21 additions and 16 deletions

View File

@ -21,6 +21,7 @@
import datetime import datetime
import random import random
import sys import sys
from typing import Optional
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.management import BaseCommand, CommandParser from django.core.management import BaseCommand, CommandParser
@ -28,13 +29,17 @@ from django.db import transaction
from django.db.models import PositiveIntegerField from django.db.models import PositiveIntegerField
from django.utils import timezone from django.utils import timezone
from accounting.utils import Populator from accounting.utils import DataFiller
from mia_core.utils import new_pk from mia_core.utils import new_pk
class Command(BaseCommand): class Command(BaseCommand):
"""Populates the database with sample accounting data.""" """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): def add_arguments(self, parser):
"""Adds command line arguments to the parser. """Adds command line arguments to the parser.
@ -74,8 +79,8 @@ class Command(BaseCommand):
user.set_digest_password("admin", "12345") user.set_digest_password("admin", "12345")
user.save() user.save()
self._populator: Populator = Populator(user) self._filler = DataFiller(user)
self._populator.add_accounts([ self._filler.add_accounts([
(1, "資產", "assets", "资产"), (1, "資產", "assets", "资产"),
(2, "負債", "liabilities", "负债"), (2, "負債", "liabilities", "负债"),
(3, "業主權益", "owners equity", "业主权益"), (3, "業主權益", "owners equity", "业主权益"),
@ -141,43 +146,43 @@ class Command(BaseCommand):
self.add_payrolls(5) self.add_payrolls(5)
self._populator.add_income_transaction( self._filler.add_income_transaction(
-15, -15,
[(1113, "ATM withdrawal", 2000)]) [(1113, "ATM withdrawal", 2000)])
self._populator.add_transfer_transaction( self._filler.add_transfer_transaction(
-14, -14,
[(6254, "HSR—New Land→South Lake City", 1490)], [(6254, "HSR—New Land→South Lake City", 1490)],
[(2141, "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, -14,
[(6273, "Movies—The Avengers", 80)], [(6273, "Movies—The Avengers", 80)],
[(2141, "Movies—The Avengers", 80)]) [(2141, "Movies—The Avengers", 80)])
self._populator.add_transfer_transaction( self._filler.add_transfer_transaction(
-13, -13,
[(6273, "Movies—2001: A Space Odyssey", 80)], [(6273, "Movies—2001: A Space Odyssey", 80)],
[(2141, "Movies—2001: A Space Odyssey", 80)]) [(2141, "Movies—2001: A Space Odyssey", 80)])
self._populator.add_transfer_transaction( self._filler.add_transfer_transaction(
-11, -11,
[(2141, "Movies—The Avengers", 80)], [(2141, "Movies—The Avengers", 80)],
[(1113, "Movies—The Avengers", 80)]) [(1113, "Movies—The Avengers", 80)])
self._populator.add_expense_transaction( self._filler.add_expense_transaction(
-13, -13,
[(6273, "Bus—2623—Uptown→City Park", 30)]) [(6273, "Bus—2623—Uptown→City Park", 30)])
self._populator.add_expense_transaction( self._filler.add_expense_transaction(
-2, -2,
[(6272, "Lunch—Spaghetti", random.randint(40, 200)), [(6272, "Lunch—Spaghetti", random.randint(40, 200)),
(6272, "Drink—Tea", random.randint(40, 200))]) (6272, "Drink—Tea", random.randint(40, 200))])
self._populator.add_expense_transaction( self._filler.add_expense_transaction(
-1, -1,
([(6272, "Lunch—Pizza", random.randint(40, 200)), ([(6272, "Lunch—Pizza", random.randint(40, 200)),
(6272, "Drink—Tea", random.randint(40, 200))])) (6272, "Drink—Tea", random.randint(40, 200))]))
self._populator.add_expense_transaction( self._filler.add_expense_transaction(
-1, -1,
[(6272, "Lunch—Spaghetti", random.randint(40, 200)), [(6272, "Lunch—Spaghetti", random.randint(40, 200)),
(6272, "Drink—Soda", random.randint(40, 200))]) (6272, "Drink—Soda", random.randint(40, 200))])
self._populator.add_expense_transaction( self._filler.add_expense_transaction(
0, 0,
[(6272, "Lunch—Salad", random.randint(40, 200)), [(6272, "Lunch—Salad", random.randint(40, 200)),
(6272, "Drink—Coffee", random.randint(40, 200))]) (6272, "Drink—Coffee", random.randint(40, 200))])
@ -238,7 +243,7 @@ class Command(BaseCommand):
if month < 1: if month < 1:
month = 12 month = 12
month_text = months[month - 1] month_text = months[month - 1]
self._populator.add_transfer_transaction( self._filler.add_transfer_transaction(
payday, payday,
[(1113, "Payroll Transfer", savings), [(1113, "Payroll Transfer", savings),
(1314, F"Pension for {month_text}", pension), (1314, F"Pension for {month_text}", pension),

View File

@ -128,7 +128,7 @@ class ReportUrl:
current_app=self._namespace) current_app=self._namespace)
class Populator: class DataFiller:
"""The helper to populate the accounting data. """The helper to populate the accounting data.
Args: Args: