feat(bx): add list Excel export for reimbursement module pages
Wire ListExportDropdown on advance/reimburse/payment/expense/view/wallet lists, with matching POST export endpoints. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fe15a130cb
commit
dbba755fd8
16 files changed
+901
-11
No files matched your search
@@ -5,7 +5,16 @@ from fastapi import APIRouter, Depends, HTTPException, Request, status, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from starlette.datastructures import UploadFile as StarletteUploadFile
|
||||
|
||||
from app.api.bx.export_common import (
|
||||
EXPORT_MAX_ROWS,
|
||||
ExportColumn,
|
||||
ExportValidationError,
|
||||
BxExportBodyBase,
|
||||
dump_export_row,
|
||||
respond_xlsx,
|
||||
)
|
||||
from app.core.bx_auth import BxUserContext, get_bx_current_user
|
||||
from app.core.tenant_context import get_tenant_no
|
||||
from app.core.database import get_db
|
||||
from app.schemas.bx.common import ApiResponse, PagedData
|
||||
from app.schemas.bx.invoice import InvoiceOut, LedgerOut, WalletSummaryOut
|
||||
@@ -39,6 +48,46 @@ def list_invoice_wallets(
|
||||
return ApiResponse(data=PagedData(rows=out_rows, total=total, page=page, page_size=pageSize))
|
||||
|
||||
|
||||
|
||||
WALLET_EXPORT_COLUMNS = [
|
||||
ExportColumn(title="员工", field="ownerUserName"),
|
||||
ExportColumn(title="总额(元)", field="totalAmount"),
|
||||
ExportColumn(title="已报销占用(元)", field="usedAmount"),
|
||||
ExportColumn(title="余额(元)", field="balance"),
|
||||
ExportColumn(title="发票张数", field="invoiceCount"),
|
||||
]
|
||||
|
||||
|
||||
class WalletExportBody(BxExportBodyBase):
|
||||
keyword: str = ""
|
||||
|
||||
|
||||
@router.post("/invoice-wallets/export")
|
||||
def export_invoice_wallets(
|
||||
body: WalletExportBody,
|
||||
db: Session = Depends(get_db),
|
||||
user: BxUserContext = Depends(get_bx_current_user),
|
||||
):
|
||||
try:
|
||||
tenant_no = get_tenant_no(db, user.to_tenant_user_dict())
|
||||
rows, _ = InvoiceService.list_wallets(
|
||||
db, user=user, page=1, page_size=EXPORT_MAX_ROWS, keyword=body.keyword or ""
|
||||
)
|
||||
outs = [WalletSummaryOut.model_validate(InvoiceService._summary_to_dict(r)) for r in rows]
|
||||
if body.ids:
|
||||
id_set = {str(i) for i in body.ids}
|
||||
# wallet may key by ownerUserId
|
||||
outs = [o for o in outs if str(getattr(o, "owner_user_id", None) or getattr(o, "id", "")) in id_set or str(o.model_dump(by_alias=True).get("ownerUserId") or o.model_dump(by_alias=True).get("id") or "") in id_set]
|
||||
export_rows = [dump_export_row(o, status_fields=()) for o in outs]
|
||||
return respond_xlsx(
|
||||
db, tenant_no=tenant_no, sheet_title="发票夹", columns=WALLET_EXPORT_COLUMNS,
|
||||
rows=export_rows, filename_stem="发票夹汇总", requested_columns=body.columns,
|
||||
)
|
||||
except ExportValidationError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
|
||||
|
||||
|
||||
@router.get("/invoices", response_model=ApiResponse[PagedData[InvoiceOut]])
|
||||
def list_invoices(
|
||||
page: int = 1,
|
||||
|
||||
Reference in new issue
Block a user