diff --git a/server/src/app/services/expense_claims.py b/server/src/app/services/expense_claims.py index a03bd07..81c4b10 100644 --- a/server/src/app/services/expense_claims.py +++ b/server/src/app/services/expense_claims.py @@ -510,6 +510,71 @@ class ExpenseClaimService: return claim + def save_or_submit_from_ontology( + self, + *, + run_id: str, + user_id: str | None, + message: str, + ontology: OntologyParseResult, + context_json: dict[str, Any], + ) -> dict[str, Any]: + result = self.upsert_draft_from_ontology( + run_id=run_id, + user_id=user_id, + message=message, + ontology=ontology, + context_json=context_json, + ) + + review_action = str(context_json.get("review_action") or "").strip() + if review_action != "next_step": + return result + + claim_id = str(result.get("claim_id") or "").strip() + if not claim_id or result.get("draft_limit_reached"): + return result + + current_user = CurrentUserContext( + username=str(user_id or context_json.get("name") or "anonymous").strip() or "anonymous", + name=str(context_json.get("name") or user_id or "anonymous").strip() or "anonymous", + role_codes=[ + str(item).strip() + for item in list(context_json.get("role_codes") or []) + if str(item).strip() + ], + is_admin=bool(context_json.get("is_admin")), + ) + + try: + claim = self.submit_claim(claim_id, current_user) + except ValueError as exc: + return { + **result, + "message": str(exc), + "submission_blocked": True, + "draft_only": False, + } + + if claim is None: + return { + **result, + "message": "未找到可提交的报销单,请刷新后重试。", + "submission_blocked": True, + "draft_only": False, + } + + return { + "message": f"报销单 {claim.claim_no} 已提交审批,当前节点为 {claim.approval_stage or '审批中'}。", + "draft_only": False, + "claim_id": claim.id, + "claim_no": claim.claim_no, + "status": claim.status, + "approval_stage": claim.approval_stage, + "amount": float(claim.amount), + "invoice_count": int(claim.invoice_count or 0), + } + def delete_claim(self, claim_id: str, current_user: CurrentUserContext) -> ExpenseClaim | None: claim = self.get_claim(claim_id, current_user) if claim is None: