Changed the sample data from Chinese to English in the accounting application.

This commit is contained in:
依瑪貓 2020-08-18 22:50:36 +08:00
parent ea9d4601ef
commit dddc27402e

View File

@ -18,6 +18,7 @@
"""The command to populate the database with sample accounting data. """The command to populate the database with sample accounting data.
""" """
import datetime
import random import random
import sys import sys
@ -73,8 +74,8 @@ class Command(BaseCommand):
user.set_digest_password("admin", "12345") user.set_digest_password("admin", "12345")
user.save() user.save()
p = Populator(user) self.p: Populator = Populator(user)
p.add_accounts([ self.p.add_accounts([
(1, "資產", "assets", "资产"), (1, "資產", "assets", "资产"),
(2, "負債", "liabilities", "负债"), (2, "負債", "liabilities", "负债"),
(3, "業主權益", "owners equity", "业主权益"), (3, "業主權益", "owners equity", "业主权益"),
@ -138,6 +139,85 @@ class Command(BaseCommand):
(6273, "職工福利", "employee benefits/welfare", "职工福利"), (6273, "職工福利", "employee benefits/welfare", "职工福利"),
]) ])
self.add_payrolls(5)
self.p.add_income_transaction(
-15,
[(1113, "ATM withdrawal", 2000)])
self.p.add_transfer_transaction(
-14,
[(6254, "HSR—New Land→South Lake City", 1490)],
[(2141, "HSR—New Land→South Lake City", 1490)])
self.p.add_transfer_transaction(
-14,
[(6273, "Movies—The Avengers", 80)],
[(2141, "Movies—The Avengers", 80)])
self.p.add_transfer_transaction(
-13,
[(6273, "Movies—2001: A Space Odyssey", 80)],
[(2141, "Movies—2001: A Space Odyssey", 80)])
self.p.add_transfer_transaction(
-11,
[(2141, "Movies—The Avengers", 80)],
[(1113, "Movies—The Avengers", 80)])
self.p.add_expense_transaction(
-13,
[(6273, "Bus—2623—Uptown→City Park", 30)])
self.p.add_expense_transaction(
-2,
[(6272, "Lunch—Spaghetti", random.randint(40, 200)),
(6272, "Drink—Tea", random.randint(40, 200))])
self.p.add_expense_transaction(
-1,
([(6272, "Lunch—Pizza", random.randint(40, 200)),
(6272, "Drink—Tea", random.randint(40, 200))]))
self.p.add_expense_transaction(
-1,
[(6272, "Lunch—Spaghetti", random.randint(40, 200)),
(6272, "Drink—Soda", random.randint(40, 200))])
self.p.add_expense_transaction(
0,
[(6272, "Lunch—Salad", random.randint(40, 200)),
(6272, "Drink—Coffee", random.randint(40, 200))])
def add_payrolls(self, months: int):
"""Adds the payrolls for certain number of months.
Args:
months: The number of months to add.
"""
today = timezone.localdate()
payday = today.replace(day=5)
if payday > today:
payday = self.previous_month(payday)
for i in range(months):
self.add_payroll(payday)
payday = self.previous_month(payday)
@staticmethod
def previous_month(date: datetime.date):
"""Obtain the same day in the previous month.
Args:
date: The date.
Returns:
The same day in the previous month.
"""
month = date.month - 1
if month < 1:
year = date.year - 1
return date.replace(year=year, month=12)
return date.replace(month=month)
def add_payroll(self, payday: datetime.date):
"""Adds the payroll for a payday.
Args:
payday: The payday.
"""
income = random.randint(40000, 50000) income = random.randint(40000, 50000)
pension = 882 if income <= 40100\ pension = 882 if income <= 40100\
else 924 if income <= 42000\ else 924 if income <= 42000\
@ -151,53 +231,17 @@ class Command(BaseCommand):
else 712 else 712
tax = round(income * 0.05) tax = round(income * 0.05)
savings = income - pension - insurance - tax savings = income - pension - insurance - tax
date = timezone.localdate() - timezone.timedelta(days=15) months = ["January", "February", "March", "April", "May", "June",
month = (date.replace(day=1) - timezone.timedelta(days=1)).month "July", "August", "September", "October", "November",
p.add_transfer_transaction( "December"]
date, month = payday.month - 1
[(1113, "薪資轉帳", savings), if month < 1:
(1314, F"勞保{month}", pension), month = 12
(6262, F"健保{month}", insurance), month_text = months[month - 1]
(1255, "代扣所得稅", tax)], self.p.add_transfer_transaction(
[(4611, F"{month}月份薪水", income)]) payday,
[(1113, "Payroll Transfer", savings),
p.add_income_transaction( (1314, F"Pension for {month_text}", pension),
-15, (6262, F"Health insurance for {month_text}", insurance),
[(1113, "ATM提款", 2000)]) (1255, "Income Tax", tax)],
p.add_transfer_transaction( [(4611, F"Payroll for {month_text}", income)])
-14,
[(6254, "高鐵—台北→左營", 1490)],
[(2141, "高鐵—台北→左營", 1490)])
p.add_transfer_transaction(
-14,
[(6273, "電影—復仇者聯盟", 80)],
[(2141, "電影—復仇者聯盟", 80)])
p.add_transfer_transaction(
-13,
[(6273, "電影—2001太空漫遊", 80)],
[(2141, "電影—2001太空漫遊", 80)])
p.add_transfer_transaction(
-11,
[(2141, "電影—復仇者聯盟", 80)],
[(1113, "電影—復仇者聯盟", 80)])
p.add_expense_transaction(
-13,
[(6273, "公車—262—民生社區→頂溪捷運站", 30)])
p.add_expense_transaction(
-2,
[(6272, "午餐—排骨飯", random.randint(40, 200)),
(6272, "飲料—紅茶", random.randint(40, 200))])
p.add_expense_transaction(
-1,
([(6272, "午餐—牛肉麵", random.randint(40, 200)),
(6272, "飲料—紅茶", random.randint(40, 200))]))
p.add_expense_transaction(
-1,
[(6272, "午餐—排骨飯", random.randint(40, 200)),
(6272, "飲料—冬瓜茶", random.randint(40, 200))])
p.add_expense_transaction(
0,
[(6272, "午餐—雞腿飯", random.randint(40, 200)),
(6272, "飲料—咖啡", random.randint(40, 200))])