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