fix: handle risk explanation standard adjustment
This commit is contained in:
@@ -19,7 +19,12 @@ from app.models.organization import OrganizationUnit
|
||||
from app.models.role import Role
|
||||
from app.schemas.ontology import OntologyParseRequest
|
||||
from app.schemas.ocr import OcrRecognizeBatchRead, OcrRecognizeDocumentRead
|
||||
from app.schemas.reimbursement import ExpenseClaimItemCreate, ExpenseClaimItemUpdate, ExpenseClaimUpdate
|
||||
from app.schemas.reimbursement import (
|
||||
ExpenseClaimItemCreate,
|
||||
ExpenseClaimItemUpdate,
|
||||
ExpenseClaimStandardAdjustmentPayload,
|
||||
ExpenseClaimUpdate,
|
||||
)
|
||||
from app.services.agent_conversations import AgentConversationService
|
||||
from app.services.budget import BudgetService
|
||||
from app.services.expense_claim_attachment_storage import ExpenseClaimAttachmentStorage
|
||||
@@ -2615,6 +2620,77 @@ def test_submit_claim_runs_ai_review_and_routes_to_direct_manager() -> None:
|
||||
assert submitted.submitted_at is not None
|
||||
|
||||
|
||||
def test_accept_standard_adjustment_recalculates_claim_amount_and_preserves_on_submit() -> None:
|
||||
current_user = CurrentUserContext(
|
||||
username="emp-standard@example.com",
|
||||
name="张三",
|
||||
role_codes=[],
|
||||
is_admin=False,
|
||||
)
|
||||
|
||||
with build_session() as db:
|
||||
manager = Employee(
|
||||
employee_no="E7030",
|
||||
name="李经理",
|
||||
email="manager-standard@example.com",
|
||||
)
|
||||
employee = Employee(
|
||||
employee_no="E7031",
|
||||
name="张三",
|
||||
email="emp-standard@example.com",
|
||||
manager=manager,
|
||||
)
|
||||
claim = build_claim(expense_type="hotel", location="北京")
|
||||
claim.employee = employee
|
||||
claim.employee_id = employee.id
|
||||
claim.amount = Decimal("880.00")
|
||||
claim.items[0].item_type = "hotel_ticket"
|
||||
claim.items[0].item_reason = "北京住宿"
|
||||
claim.items[0].item_amount = Decimal("880.00")
|
||||
db.add_all([manager, employee, claim])
|
||||
db.commit()
|
||||
|
||||
service = ExpenseClaimService(db)
|
||||
adjusted = service.accept_standard_adjustment(
|
||||
claim_id=claim.id,
|
||||
payload=ExpenseClaimStandardAdjustmentPayload(
|
||||
risks=[
|
||||
{
|
||||
"risk_id": "risk-hotel-1",
|
||||
"item_id": claim.items[0].id,
|
||||
"title": "住宿超标待说明",
|
||||
"risk": "住宿标准为 600 元/晚,当前酒店识别金额约 880 元/晚。",
|
||||
"original_amount": Decimal("880.00"),
|
||||
"reimbursable_amount": Decimal("600.00"),
|
||||
}
|
||||
]
|
||||
),
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
assert adjusted is not None
|
||||
assert adjusted.amount == Decimal("600.00")
|
||||
standard_flag = next(
|
||||
flag
|
||||
for flag in adjusted.risk_flags_json
|
||||
if isinstance(flag, dict) and flag.get("source") == "reimbursement_standard_adjustment"
|
||||
)
|
||||
assert standard_flag["original_amount"] == "880.00"
|
||||
assert standard_flag["reimbursable_amount"] == "600.00"
|
||||
assert standard_flag["employee_absorbed_amount"] == "280.00"
|
||||
assert standard_flag["visibility_scope"] == "leader"
|
||||
|
||||
submitted = service.submit_claim(claim.id, current_user)
|
||||
|
||||
assert submitted is not None
|
||||
assert submitted.status == "submitted"
|
||||
assert submitted.amount == Decimal("600.00")
|
||||
assert any(
|
||||
isinstance(flag, dict) and flag.get("source") == "reimbursement_standard_adjustment"
|
||||
for flag in submitted.risk_flags_json
|
||||
)
|
||||
|
||||
|
||||
def test_pre_review_claim_records_ai_result_without_submitting() -> None:
|
||||
current_user = CurrentUserContext(
|
||||
username="emp-pre-review@example.com",
|
||||
|
||||
Reference in New Issue
Block a user