Wrapped the accounting_sample command in a transaction in the accounting application.
This commit is contained in:
parent
2b9034cfe8
commit
6cbef81088
@ -21,6 +21,7 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
from django.core.management import BaseCommand, CommandParser
|
from django.core.management import BaseCommand, CommandParser
|
||||||
|
from django.db import transaction
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from accounting.utils import Populator
|
from accounting.utils import Populator
|
||||||
@ -50,119 +51,128 @@ class Command(BaseCommand):
|
|||||||
if input().lower() not in ("y", "yes"):
|
if input().lower() not in ("y", "yes"):
|
||||||
return
|
return
|
||||||
|
|
||||||
user = User(pk=923153018, login_id="imacat",
|
with transaction.atomic():
|
||||||
password="5486b64881adaf7bc1485cc26e57e51e", name="依瑪貓",
|
user = User(pk=923153018, login_id="imacat",
|
||||||
is_disabled=False, is_deleted=False)
|
password="5486b64881adaf7bc1485cc26e57e51e",
|
||||||
user.created_by = user
|
name="依瑪貓", is_disabled=False, is_deleted=False)
|
||||||
user.updated_by = user
|
user.created_by = user
|
||||||
user.save()
|
user.updated_by = user
|
||||||
|
user.save()
|
||||||
|
|
||||||
p = Populator(user)
|
p = Populator(user)
|
||||||
p.add_accounts((
|
p.add_accounts((
|
||||||
(1, "資產", "assets", "资产"),
|
(1, "資產", "assets", "资产"),
|
||||||
(2, "負債", "liabilities", "负债"),
|
(2, "負債", "liabilities", "负债"),
|
||||||
(3, "業主權益", "owners’ equity", "业主权益"),
|
(3, "業主權益", "owners’ equity", "业主权益"),
|
||||||
(4, "營業收入", "operating revenue", "营业收入"),
|
(4, "營業收入", "operating revenue", "营业收入"),
|
||||||
(5, "營業成本", "operating costs", "营业成本"),
|
(5, "營業成本", "operating costs", "营业成本"),
|
||||||
(6, "營業費用", "operating expenses", "营业费用"),
|
(6, "營業費用", "operating expenses", "营业费用"),
|
||||||
(7, "營業外收入及費用",
|
(7, "營業外收入及費用",
|
||||||
"non-operating revenue and expenses, other income (expense)",
|
"non-operating revenue and expenses, other income (expense)",
|
||||||
"营业外收入及费用"),
|
"营业外收入及费用"),
|
||||||
(8, "所得稅費用(或利益)", "income tax expense (or benefit)",
|
(8, "所得稅費用(或利益)", "income tax expense (or benefit)",
|
||||||
"所得税费用(或利益)"),
|
"所得税费用(或利益)"),
|
||||||
(9, "非經常營業損益", "nonrecurring gain or loss", "非经常营业损益"),
|
(9, "非經常營業損益", "nonrecurring gain or loss",
|
||||||
|
"非经常营业损益"),
|
||||||
|
|
||||||
(11, "流動資產", "current assets", "流动资产"),
|
(11, "流動資產", "current assets", "流动资产"),
|
||||||
(111, "現金及約當現金", "cash and cash equivalents", "现金及约当现金"),
|
(111, "現金及約當現金", "cash and cash equivalents",
|
||||||
(1111, "庫存現金", "petty cash/revolving funds", "库存现金"),
|
"现金及约当现金"),
|
||||||
(1112, "零用金/週轉金", "cash on hand", "零用金/周转金"),
|
(1111, "庫存現金", "petty cash/revolving funds", "库存现金"),
|
||||||
(1113, "銀行存款", "cash in banks", "银行存款"),
|
(1112, "零用金/週轉金", "cash on hand", "零用金/周转金"),
|
||||||
(12, "流動資產", "current assets", "流动资产"),
|
(1113, "銀行存款", "cash in banks", "银行存款"),
|
||||||
(125, "預付費用", "prepaid expenses", "预付费用"),
|
(12, "流動資產", "current assets", "流动资产"),
|
||||||
(1255, "預付所得稅", "prepaid income tax", "预付所得税"),
|
(125, "預付費用", "prepaid expenses", "预付费用"),
|
||||||
(13, "基金及長期投資", "funds and long-term investments",
|
(1255, "預付所得稅", "prepaid income tax", "预付所得税"),
|
||||||
"基金及长期投资"),
|
(13, "基金及長期投資", "funds and long-term investments",
|
||||||
(131, "基金", "funds", "基金"),
|
"基金及长期投资"),
|
||||||
(1314, "退休基金", "pension fund", "退休基金"),
|
(131, "基金", "funds", "基金"),
|
||||||
|
(1314, "退休基金", "pension fund", "退休基金"),
|
||||||
|
|
||||||
(21, "流動負債", "current liabilities", "流动负债"),
|
(21, "流動負債", "current liabilities", "流动负债"),
|
||||||
(214, "應付帳款", "accounts payable", "应付帐款"),
|
(214, "應付帳款", "accounts payable", "应付帐款"),
|
||||||
(2141, "應付帳款", "accounts payable", "应付帐款"),
|
(2141, "應付帳款", "accounts payable", "应付帐款"),
|
||||||
|
|
||||||
(33, "保留盈餘(或累積虧損)",
|
(33, "保留盈餘(或累積虧損)",
|
||||||
"retained earnings (accumulated deficit)", "保留盈余(或累积亏损)"),
|
"retained earnings (accumulated deficit)",
|
||||||
(335, "未分配盈餘(或累積虧損)",
|
"保留盈余(或累积亏损)"),
|
||||||
"retained earnings-unappropriated (or accumulated deficit)",
|
(335, "未分配盈餘(或累積虧損)",
|
||||||
"未分配盈余(或累积亏损)"),
|
"retained earnings-unappropriated (or accumulated deficit)",
|
||||||
(3351, "累積盈虧", "accumulated profit or loss", "累积盈亏"),
|
"未分配盈余(或累积亏损)"),
|
||||||
(3353, "本期損益", "net income or loss for current period", "本期损益"),
|
(3351, "累積盈虧", "accumulated profit or loss", "累积盈亏"),
|
||||||
|
(3353, "本期損益", "net income or loss for current period",
|
||||||
|
"本期损益"),
|
||||||
|
|
||||||
(46, "勞務收入", "service revenue", "劳务收入"),
|
(46, "勞務收入", "service revenue", "劳务收入"),
|
||||||
(461, "勞務收入", "service revenue", "劳务收入"),
|
(461, "勞務收入", "service revenue", "劳务收入"),
|
||||||
(4611, "勞務收入", "service revenue", "劳务收入"),
|
(4611, "勞務收入", "service revenue", "劳务收入"),
|
||||||
|
|
||||||
(62, "管理及總務費用", "general & administrative expenses", "管理及总务费用"),
|
(62, "管理及總務費用", "general & administrative expenses",
|
||||||
(625, "管理及總務費用", "general & administrative expenses", "管理及总务费用"),
|
"管理及总务费用"),
|
||||||
(6254, "旅費", "travelling expense, travel", "旅费"),
|
(625, "管理及總務費用", "general & administrative expenses",
|
||||||
(626, "管理及總務費用", "general & administrative expenses", "管理及总务费用"),
|
"管理及总务费用"),
|
||||||
(6262, "保險費", "insurance (expense)", "保险费"),
|
(6254, "旅費", "travelling expense, travel", "旅费"),
|
||||||
(627, "管理及總務費用", "general & administrative expenses", "管理及总务费用"),
|
(626, "管理及總務費用", "general & administrative expenses",
|
||||||
(6272, "伙食費", "meal (expenses)", "伙食费"),
|
"管理及总务费用"),
|
||||||
(6273, "職工福利", "employee benefits/welfare", "职工福利"),
|
(6262, "保險費", "insurance (expense)", "保险费"),
|
||||||
))
|
(627, "管理及總務費用", "general & administrative expenses",
|
||||||
|
"管理及总务费用"),
|
||||||
|
(6272, "伙食費", "meal (expenses)", "伙食费"),
|
||||||
|
(6273, "職工福利", "employee benefits/welfare", "职工福利"),
|
||||||
|
))
|
||||||
|
|
||||||
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\
|
||||||
else 966 if income <= 43900\
|
else 966 if income <= 43900\
|
||||||
else 1008
|
else 1008
|
||||||
insurance = 564 if income <= 40100\
|
insurance = 564 if income <= 40100\
|
||||||
else 591 if income <= 42000\
|
else 591 if income <= 42000\
|
||||||
else 618 if income <= 43900\
|
else 618 if income <= 43900\
|
||||||
else 644 if income <= 45800\
|
else 644 if income <= 45800\
|
||||||
else 678 if income <= 48200\
|
else 678 if income <= 48200\
|
||||||
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)
|
date = timezone.localdate() - timezone.timedelta(days=15)
|
||||||
month = (date.replace(day=1) - timezone.timedelta(days=1)).month
|
month = (date.replace(day=1) - timezone.timedelta(days=1)).month
|
||||||
p.add_transfer_transaction(
|
p.add_transfer_transaction(
|
||||||
date,
|
date,
|
||||||
(("1113", "薪資轉帳", savings),
|
(("1113", "薪資轉帳", savings),
|
||||||
("1314", F"勞保{month}月", pension),
|
("1314", F"勞保{month}月", pension),
|
||||||
("6262", F"健保{month}月", insurance),
|
("6262", F"健保{month}月", insurance),
|
||||||
("1255", "代扣所得稅", tax)),
|
("1255", "代扣所得稅", tax)),
|
||||||
(("4611", F"{month}月份薪水", income),))
|
(("4611", F"{month}月份薪水", income),))
|
||||||
|
|
||||||
p.add_income_transaction(
|
p.add_income_transaction(
|
||||||
-15,
|
-15,
|
||||||
(("1113", "ATM提款", 2000),))
|
(("1113", "ATM提款", 2000),))
|
||||||
p.add_transfer_transaction(
|
p.add_transfer_transaction(
|
||||||
-14,
|
-14,
|
||||||
(("6254", "高鐵—台北→左營", 1490),),
|
(("6254", "高鐵—台北→左營", 1490),),
|
||||||
(("2141", "高鐵—台北→左營", 1490),))
|
(("2141", "高鐵—台北→左營", 1490),))
|
||||||
p.add_transfer_transaction(
|
p.add_transfer_transaction(
|
||||||
-14,
|
-14,
|
||||||
(("6273", "電影—復仇者聯盟", 80),),
|
(("6273", "電影—復仇者聯盟", 80),),
|
||||||
(("2141", "電影—復仇者聯盟", 80),))
|
(("2141", "電影—復仇者聯盟", 80),))
|
||||||
p.add_transfer_transaction(
|
p.add_transfer_transaction(
|
||||||
-11,
|
-11,
|
||||||
(("2141", "電影—復仇者聯盟", 80),),
|
(("2141", "電影—復仇者聯盟", 80),),
|
||||||
(("1113", "電影—復仇者聯盟", 80),))
|
(("1113", "電影—復仇者聯盟", 80),))
|
||||||
|
|
||||||
p.add_expense_transaction(
|
p.add_expense_transaction(
|
||||||
-2,
|
-2,
|
||||||
(("6272", "午餐—排骨飯", random.randint(40, 200)),
|
(("6272", "午餐—排骨飯", random.randint(40, 200)),
|
||||||
("6272", "飲料—紅茶", random.randint(40, 200))))
|
("6272", "飲料—紅茶", random.randint(40, 200))))
|
||||||
p.add_expense_transaction(
|
p.add_expense_transaction(
|
||||||
-1,
|
-1,
|
||||||
(("6272", "午餐—牛肉麵", random.randint(40, 200)),
|
(("6272", "午餐—牛肉麵", random.randint(40, 200)),
|
||||||
("6272", "飲料—紅茶", random.randint(40, 200))))
|
("6272", "飲料—紅茶", random.randint(40, 200))))
|
||||||
p.add_expense_transaction(
|
p.add_expense_transaction(
|
||||||
-1,
|
-1,
|
||||||
(("6272", "午餐—排骨飯", random.randint(40, 200)),
|
(("6272", "午餐—排骨飯", random.randint(40, 200)),
|
||||||
("6272", "飲料—冬瓜茶", random.randint(40, 200))))
|
("6272", "飲料—冬瓜茶", random.randint(40, 200))))
|
||||||
p.add_expense_transaction(
|
p.add_expense_transaction(
|
||||||
0,
|
0,
|
||||||
(("6272", "午餐—雞腿飯", random.randint(40, 200)),
|
(("6272", "午餐—雞腿飯", random.randint(40, 200)),
|
||||||
("6272", "飲料—咖啡", random.randint(40, 200))))
|
("6272", "飲料—咖啡", random.randint(40, 200))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user