feat: add time
This commit is contained in:
parent
db96a5057b
commit
a090a89589
3 changed files with 46 additions and 38 deletions
|
@ -28,14 +28,15 @@ CREATE TABLE category (
|
||||||
-- 流水表
|
-- 流水表
|
||||||
CREATE TABLE transaction (
|
CREATE TABLE transaction (
|
||||||
t_id SERIAL PRIMARY KEY, -- 流水号
|
t_id SERIAL PRIMARY KEY, -- 流水号
|
||||||
c_id INTEGER REFERENCES category(c_id), -- 关联类别号
|
a_id INTEGER REFERENCES account(a_id) NOT NULL, -- 关联账户号
|
||||||
a_id INTEGER REFERENCES account(a_id), -- 关联账户号
|
c_id INTEGER REFERENCES category(c_id), -- 关联类别号
|
||||||
s_id INTEGER REFERENCES category(c_id), -- 源账户号
|
s_id INTEGER REFERENCES category(c_id), -- 源账户号
|
||||||
|
time TIMESTAMP,
|
||||||
amount MONEY,
|
amount MONEY,
|
||||||
meta JSONB -- 元数据
|
meta JSONB -- 元数据
|
||||||
);
|
);
|
||||||
-- {"discription":"something",(可选)
|
-- {"discription":"something",(可选)
|
||||||
-- "type":"in"/"out"/"transfer",
|
-- "type":"in"/"out"/"transfer"/"init"/"modify",
|
||||||
|
|
||||||
-- "reimburse":{ (报销)
|
-- "reimburse":{ (报销)
|
||||||
-- "finish": true,
|
-- "finish": true,
|
||||||
|
|
|
@ -86,19 +86,19 @@ class AccountTab(TabPage):
|
||||||
print(data)
|
print(data)
|
||||||
|
|
||||||
# 绘制界面并填充数据
|
# 绘制界面并填充数据
|
||||||
label1 = QLabel("Account Name:")
|
accountNameLabel = QLabel("Account Name:")
|
||||||
line1 = QLineEdit()
|
accountNameLine = QLineEdit()
|
||||||
line1.setText(data[0][0])
|
accountNameLine.setText(data[0][0])
|
||||||
|
|
||||||
label2 = QLabel("Account Balance:")
|
balanceLabel = QLabel("Account Balance:")
|
||||||
line2 = QLineEdit()
|
balanceLine = QLineEdit()
|
||||||
line2.setText(f'{float(data[0][1]):.2f}')
|
balanceLine.setText(f'{float(data[0][1]):.2f}')
|
||||||
# 只允许输入两位小数
|
# 只允许输入两位小数
|
||||||
line2.setValidator(QDoubleValidator(0.00, 999999999.99, 2))
|
balanceLine.setValidator(QDoubleValidator(0.00, 999999999.99, 2))
|
||||||
|
|
||||||
label3 = QLabel("Description:")
|
descriptionLabel = QLabel("Description:")
|
||||||
line3 = QLineEdit()
|
descriptionLine = QLineEdit()
|
||||||
line3.setText(data[0][2])
|
descriptionLine.setText(data[0][2])
|
||||||
|
|
||||||
button1 = QPushButton("Confirm")
|
button1 = QPushButton("Confirm")
|
||||||
button3 = QPushButton("Delete")
|
button3 = QPushButton("Delete")
|
||||||
|
@ -114,9 +114,9 @@ class AccountTab(TabPage):
|
||||||
button2.clicked.connect(self.aDialog.reject)
|
button2.clicked.connect(self.aDialog.reject)
|
||||||
|
|
||||||
layout = QFormLayout()
|
layout = QFormLayout()
|
||||||
layout.addRow(label1,line1)
|
layout.addRow(accountNameLabel,accountNameLine)
|
||||||
layout.addRow(label2,line2)
|
layout.addRow(balanceLabel,balanceLine)
|
||||||
layout.addRow(label3,line3)
|
layout.addRow(descriptionLabel,descriptionLine)
|
||||||
layout.addRow(buttonLayout)
|
layout.addRow(buttonLayout)
|
||||||
layout.setSpacing(12)
|
layout.setSpacing(12)
|
||||||
layout.setContentsMargins(15, 15, 15, 15)
|
layout.setContentsMargins(15, 15, 15, 15)
|
||||||
|
@ -127,15 +127,15 @@ class AccountTab(TabPage):
|
||||||
if self.aDialog.exec() == QDialog.DialogCode.Accepted:
|
if self.aDialog.exec() == QDialog.DialogCode.Accepted:
|
||||||
try:
|
try:
|
||||||
# 获取输入数据
|
# 获取输入数据
|
||||||
name = line1.text()
|
name = accountNameLine.text()
|
||||||
balance = float(line2.text())
|
balance = float(balanceLine.text())
|
||||||
|
|
||||||
description = line3.text()
|
description = descriptionLine.text()
|
||||||
if (name == ''):
|
if (name == ''):
|
||||||
raise Exception('Account name cannot be empty')
|
raise Exception('Account name cannot be empty')
|
||||||
|
|
||||||
# JSONB插入数据
|
# JSONB插入数据
|
||||||
data = {"name": line1.text(), "balance": balance, "description": description}
|
data = {"name": accountNameLine.text(), "balance": balance, "description": description}
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
print("insert data:",data)
|
print("insert data:",data)
|
||||||
|
|
||||||
|
@ -154,15 +154,15 @@ class AccountTab(TabPage):
|
||||||
self.aDialog = QDialog(self)
|
self.aDialog = QDialog(self)
|
||||||
self.aDialog.setWindowTitle('Add New Account')
|
self.aDialog.setWindowTitle('Add New Account')
|
||||||
|
|
||||||
label1 = QLabel("Account Name:")
|
accountNameLabel = QLabel("Account Name:")
|
||||||
line1 = QLineEdit()
|
accountNameLine = QLineEdit()
|
||||||
label2 = QLabel("Account Balance:")
|
balanceLabel = QLabel("Account Balance:")
|
||||||
line2 = QLineEdit()
|
balanceLine = QLineEdit()
|
||||||
line2.setText("0.00")
|
balanceLine.setText("0.00")
|
||||||
# 只允许输入两位小数
|
# 只允许输入两位小数
|
||||||
line2.setValidator(QDoubleValidator(0.00, 999999999.99, 2))
|
balanceLine.setValidator(QDoubleValidator(0.00, 999999999.99, 2))
|
||||||
label3 = QLabel("Description:")
|
descriptionLabel = QLabel("Description:")
|
||||||
line3 = QLineEdit()
|
descriptionLine = QLineEdit()
|
||||||
|
|
||||||
button1 = QPushButton("Confirm")
|
button1 = QPushButton("Confirm")
|
||||||
button2 = QPushButton("Abort")
|
button2 = QPushButton("Abort")
|
||||||
|
@ -174,9 +174,9 @@ class AccountTab(TabPage):
|
||||||
button2.clicked.connect(self.aDialog.reject)
|
button2.clicked.connect(self.aDialog.reject)
|
||||||
|
|
||||||
layout = QFormLayout()
|
layout = QFormLayout()
|
||||||
layout.addRow(label1,line1)
|
layout.addRow(accountNameLabel,accountNameLine)
|
||||||
layout.addRow(label2,line2)
|
layout.addRow(balanceLabel,balanceLine)
|
||||||
layout.addRow(label3,line3)
|
layout.addRow(descriptionLabel,descriptionLine)
|
||||||
layout.addRow(buttonLayout)
|
layout.addRow(buttonLayout)
|
||||||
layout.setSpacing(12)
|
layout.setSpacing(12)
|
||||||
layout.setContentsMargins(15, 15, 15, 15)
|
layout.setContentsMargins(15, 15, 15, 15)
|
||||||
|
@ -187,19 +187,26 @@ class AccountTab(TabPage):
|
||||||
if self.aDialog.exec() == QDialog.DialogCode.Accepted:
|
if self.aDialog.exec() == QDialog.DialogCode.Accepted:
|
||||||
try:
|
try:
|
||||||
# 获取输入数据
|
# 获取输入数据
|
||||||
name = line1.text()
|
name = accountNameLine.text()
|
||||||
balance = float(line2.text())
|
balance = float(balanceLine.text())
|
||||||
|
|
||||||
description = line3.text()
|
description = descriptionLine.text()
|
||||||
if (name == ''):
|
if (name == ''):
|
||||||
raise Exception('Account name cannot be empty')
|
raise Exception('Account name cannot be empty')
|
||||||
|
|
||||||
# JSONB插入数据
|
# JSONB插入数据
|
||||||
data = {"name": line1.text(), "description": description}
|
data = {"name": accountNameLine.text(), "description": description}
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
print("insert data:",data)
|
print("insert data:",data)
|
||||||
|
|
||||||
self.pg.execute("INSERT INTO account (balance, meta) VALUES (%s, %s)", (balance, data,))
|
self.pg.execute("INSERT INTO account (balance, meta) VALUES (%s, %s) RETURNING a_id", (balance, data,))
|
||||||
|
a_id = self.pg.fetchall()[0][0]
|
||||||
|
|
||||||
|
# 添加账户时,在transaction表中添加一条记录
|
||||||
|
data = {"type":"init", "description": "Initial Balance"}
|
||||||
|
data = json.dumps(data)
|
||||||
|
self.pg.execute(
|
||||||
|
"INSERT INTO transaction (a_id, time, amount, meta) VALUES (%s, now(), %s,%s)", (a_id, balance, data,))
|
||||||
|
|
||||||
# 刷新表格
|
# 刷新表格
|
||||||
self.selected()
|
self.selected()
|
||||||
|
|
|
@ -42,7 +42,7 @@ class PostgresTab(TabPage):
|
||||||
|
|
||||||
def connectToDatabase(self):
|
def connectToDatabase(self):
|
||||||
try:
|
try:
|
||||||
self.conn = psycopg2.connect(database=self.dbName, user=self.user, password=self.password, host=self.host, port=self.port)
|
self.conn = psycopg2.connect(database=self.dbName, user=self.user, password=self.password, host=self.host, port=self.port, timezone="Asia/Shanghai")
|
||||||
self.cur = self.conn.cursor()
|
self.cur = self.conn.cursor()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Reference in a new issue