更新
This commit is contained in:
@@ -16,8 +16,8 @@ app = FastAPI(
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # 本地开发先用 *
|
||||
allow_credentials=True,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=False,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@@ -91,6 +91,11 @@ def fetch_trial_balance(date_from: str, date_to: str):
|
||||
credit = D(row["credit"])
|
||||
|
||||
closing = opening + debit - credit
|
||||
|
||||
# 負債・資本は絶対値で表示(見やすくするため)
|
||||
if acc["account_type"] in ("liability", "equity"):
|
||||
opening = abs(opening)
|
||||
closing = abs(closing)
|
||||
|
||||
account_data[code] = {
|
||||
"account_id": aid,
|
||||
|
||||
@@ -38,7 +38,8 @@ class JournalEntryDeleteRequest(BaseModel):
|
||||
def get_journal_entries(
|
||||
from_date: date = None,
|
||||
to_date: date = None,
|
||||
keyword: str = None
|
||||
keyword: str = None,
|
||||
account_id: int = None
|
||||
):
|
||||
"""
|
||||
仕訳一覧を検索して取得
|
||||
@@ -73,6 +74,14 @@ def get_journal_entries(
|
||||
sql += " AND je.description LIKE %s"
|
||||
params.append(f"%{keyword}%")
|
||||
|
||||
if account_id:
|
||||
sql += """ AND je.journal_entry_id IN (
|
||||
SELECT DISTINCT journal_entry_id
|
||||
FROM journal_lines
|
||||
WHERE account_id = %s
|
||||
)"""
|
||||
params.append(account_id)
|
||||
|
||||
sql += """
|
||||
GROUP BY je.journal_entry_id, je.entry_date, je.description, je.fiscal_year
|
||||
ORDER BY je.entry_date DESC, je.journal_entry_id DESC
|
||||
@@ -116,7 +125,9 @@ def get_journal_entry(journal_id: int):
|
||||
a.account_code,
|
||||
a.account_name,
|
||||
jl.debit,
|
||||
jl.credit
|
||||
jl.credit,
|
||||
jl.tax_rate,
|
||||
jl.tax_direction
|
||||
FROM journal_lines jl
|
||||
JOIN accounts a ON jl.account_id = a.account_id
|
||||
WHERE jl.journal_entry_id = %s
|
||||
@@ -301,19 +312,35 @@ def create_journal_entry(req: JournalEntryRequest):
|
||||
|
||||
# 明細(税行を含む)
|
||||
for line in all_lines:
|
||||
# tax_directionの値を変換: paid->INPUT, received->OUTPUT, none->NONE
|
||||
tax_dir_db = None
|
||||
if line.tax_direction:
|
||||
if line.tax_direction == 'paid':
|
||||
tax_dir_db = 'INPUT'
|
||||
elif line.tax_direction == 'received':
|
||||
tax_dir_db = 'OUTPUT'
|
||||
elif line.tax_direction == 'none':
|
||||
tax_dir_db = 'NONE'
|
||||
else:
|
||||
tax_dir_db = line.tax_direction.upper()
|
||||
|
||||
cur.execute("""
|
||||
INSERT INTO journal_lines (
|
||||
journal_entry_id,
|
||||
account_id,
|
||||
debit,
|
||||
credit
|
||||
credit,
|
||||
tax_rate,
|
||||
tax_direction
|
||||
)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)
|
||||
""", (
|
||||
entry_id,
|
||||
line.account_id,
|
||||
line.debit,
|
||||
line.credit
|
||||
line.credit,
|
||||
line.tax_rate,
|
||||
tax_dir_db
|
||||
))
|
||||
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user