fix: 写接口entity_id token优先(resolve_entity_for_request)+ 登录页用顶层entity_id
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
import json
|
||||
from datetime import datetime, date
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import get_db
|
||||
from app.deps import get_entity_id
|
||||
from app.deps import get_entity_id, resolve_entity_for_request
|
||||
from app.auth_middleware import require_auth, require_role
|
||||
from app.models import TaxRecord, InvoiceCheck, SocialSecurity, ExpenseReimbursement
|
||||
|
||||
@@ -159,6 +159,7 @@ def list_tax_records(
|
||||
|
||||
@router.post("/records")
|
||||
def create_tax_record(
|
||||
request: Request,
|
||||
data: dict,
|
||||
db: Session = Depends(get_db),
|
||||
_=Depends(require_role("ceo", "finance")),
|
||||
@@ -171,7 +172,7 @@ def create_tax_record(
|
||||
if tax_type not in TAX_TYPE_LABELS:
|
||||
raise HTTPException(400, f"无效税种: {tax_type},可选 vat/income/surtax")
|
||||
t = TaxRecord(
|
||||
entity_id=data.get("entity_id") or 1,
|
||||
entity_id=resolve_entity_for_request(request, data.get("entity_id") or 1),
|
||||
period=period,
|
||||
tax_type=tax_type,
|
||||
tax_payable=data.get("tax_payable") or 0,
|
||||
@@ -382,6 +383,7 @@ def list_invoices(
|
||||
|
||||
@router.post("/invoices")
|
||||
def create_invoice(
|
||||
request: Request,
|
||||
data: dict,
|
||||
db: Session = Depends(get_db),
|
||||
_=Depends(require_role("ceo", "finance")),
|
||||
@@ -393,7 +395,7 @@ def create_invoice(
|
||||
if data.get("amount") is None:
|
||||
raise HTTPException(400, "缺少必要参数: amount")
|
||||
inv = InvoiceCheck(
|
||||
entity_id=data.get("entity_id") or 1,
|
||||
entity_id=resolve_entity_for_request(request, data.get("entity_id") or 1),
|
||||
invoice_no=str(invoice_no).strip(),
|
||||
amount=data.get("amount"),
|
||||
invoice_type=data.get("invoice_type") or "vat",
|
||||
@@ -577,6 +579,7 @@ def list_ss_records(
|
||||
|
||||
@router.post("/ss")
|
||||
def create_ss_record(
|
||||
request: Request,
|
||||
data: dict,
|
||||
db: Session = Depends(get_db),
|
||||
_=Depends(require_role("ceo", "finance")),
|
||||
@@ -586,9 +589,9 @@ def create_ss_record(
|
||||
period = data.get("period")
|
||||
if not employee or not period:
|
||||
raise HTTPException(400, "缺少必要参数: employee, period")
|
||||
all_records = db.query(SocialSecurity).filter(SocialSecurity.entity_id == (data.get("entity_id") or 1)).all()
|
||||
all_records = db.query(SocialSecurity).filter(SocialSecurity.entity_id == resolve_entity_for_request(request, data.get("entity_id") or 1)).all()
|
||||
s = SocialSecurity(
|
||||
entity_id=data.get("entity_id") or 1,
|
||||
entity_id=resolve_entity_for_request(request, data.get("entity_id") or 1),
|
||||
employee=employee,
|
||||
period=period,
|
||||
base_amount=data.get("base_amount") or 0,
|
||||
|
||||
Reference in New Issue
Block a user