stock 실현손익에 세금란 추가
This commit is contained in:
@@ -75,6 +75,7 @@ def init_db():
|
|||||||
quantity INTEGER NOT NULL,
|
quantity INTEGER NOT NULL,
|
||||||
avg_price REAL NOT NULL,
|
avg_price REAL NOT NULL,
|
||||||
sell_price REAL NOT NULL,
|
sell_price REAL NOT NULL,
|
||||||
|
commission REAL NOT NULL DEFAULT 0,
|
||||||
buy_amount REAL NOT NULL,
|
buy_amount REAL NOT NULL,
|
||||||
sell_amount REAL NOT NULL,
|
sell_amount REAL NOT NULL,
|
||||||
realized_profit REAL NOT NULL,
|
realized_profit REAL NOT NULL,
|
||||||
@@ -83,6 +84,11 @@ def init_db():
|
|||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
# sell_history 마이그레이션: commission 컬럼 추가
|
||||||
|
sh_cols = {r["name"] for r in conn.execute("PRAGMA table_info(sell_history)").fetchall()}
|
||||||
|
if "commission" not in sh_cols:
|
||||||
|
conn.execute("ALTER TABLE sell_history ADD COLUMN commission REAL NOT NULL DEFAULT 0")
|
||||||
|
|
||||||
def save_articles(articles: List[Dict[str, str]]) -> int:
|
def save_articles(articles: List[Dict[str, str]]) -> int:
|
||||||
count = 0
|
count = 0
|
||||||
with _conn() as conn:
|
with _conn() as conn:
|
||||||
@@ -212,13 +218,13 @@ def add_sell_history(data: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
cur = conn.execute("""
|
cur = conn.execute("""
|
||||||
INSERT INTO sell_history
|
INSERT INTO sell_history
|
||||||
(broker, ticker, name, quantity, avg_price, sell_price,
|
(broker, ticker, name, quantity, avg_price, sell_price,
|
||||||
buy_amount, sell_amount, realized_profit, realized_rate, sold_at)
|
commission, buy_amount, sell_amount, realized_profit, realized_rate, sold_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""", (
|
""", (
|
||||||
data["broker"], data["ticker"], data["name"], data["quantity"],
|
data["broker"], data["ticker"], data["name"], data["quantity"],
|
||||||
data["avg_price"], data["sell_price"], data["buy_amount"],
|
data["avg_price"], data["sell_price"], data.get("commission", 0),
|
||||||
data["sell_amount"], data["realized_profit"], data["realized_rate"],
|
data["buy_amount"], data["sell_amount"], data["realized_profit"],
|
||||||
data["sold_at"],
|
data["realized_rate"], data["sold_at"],
|
||||||
))
|
))
|
||||||
row = conn.execute("SELECT * FROM sell_history WHERE id = ?", (cur.lastrowid,)).fetchone()
|
row = conn.execute("SELECT * FROM sell_history WHERE id = ?", (cur.lastrowid,)).fetchone()
|
||||||
return dict(row)
|
return dict(row)
|
||||||
@@ -244,9 +250,9 @@ def get_sell_history(broker: str = None, days: int = None) -> List[Dict[str, Any
|
|||||||
|
|
||||||
def update_sell_history(record_id: int, data: Dict[str, Any]) -> Dict[str, Any] | None:
|
def update_sell_history(record_id: int, data: Dict[str, Any]) -> Dict[str, Any] | None:
|
||||||
fields = ["broker", "ticker", "name", "quantity", "avg_price", "sell_price",
|
fields = ["broker", "ticker", "name", "quantity", "avg_price", "sell_price",
|
||||||
"buy_amount", "sell_amount", "realized_profit", "realized_rate", "sold_at"]
|
"commission", "buy_amount", "sell_amount", "realized_profit", "realized_rate", "sold_at"]
|
||||||
set_clause = ", ".join(f"{f} = ?" for f in fields)
|
set_clause = ", ".join(f"{f} = ?" for f in fields)
|
||||||
values = [data[f] for f in fields] + [record_id]
|
values = [data.get(f, 0) if f == "commission" else data[f] for f in fields] + [record_id]
|
||||||
with _conn() as conn:
|
with _conn() as conn:
|
||||||
cur = conn.execute(f"UPDATE sell_history SET {set_clause} WHERE id = ?", values)
|
cur = conn.execute(f"UPDATE sell_history SET {set_clause} WHERE id = ?", values)
|
||||||
if cur.rowcount == 0:
|
if cur.rowcount == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user