瀏覽代碼

fix(bx): allow reimburse submit when invoice wallet balance is insufficient

Drop the hard balance check in debit_reimburse so occupancy can exceed uploaded invoices; balance may go negative until later top-ups.

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu 2 月之前
父節點
當前提交
99e4d4c69a
共有 2 個文件被更改,包括 12 次插入 和 7 次删除
  1. 0 7
      backend/app/services/bx/invoice_ledger.py
  2. 12 0
      backend/tests/test_bx_invoice_ledger.py

+ 0 - 7
backend/app/services/bx/invoice_ledger.py

@@ -223,13 +223,6 @@ class InvoiceLedgerService:
             user_id=user.id,
             dept_id=user.dept_id,
         )
-        totals = InvoiceLedgerService.calc_summary(db, tenant_no, owner_user_id)
-        balance = totals["balance"]
-        if balance < amt:
-            raise HTTPException(
-                status_code=status.HTTP_400_BAD_REQUEST,
-                detail=f"发票额度不足(余额 {balance},本次 {amt})",
-            )
         entry = InvoiceLedgerService.add_entry(
             db,
             tenant_no=tenant_no,

+ 12 - 0
backend/tests/test_bx_invoice_ledger.py

@@ -39,3 +39,15 @@ def test_release_idempotent_guard():
     assert should_skip_release(has_debit=True, has_release=True) is True
     assert should_skip_release(has_debit=True, has_release=False) is False
     assert should_skip_release(has_debit=False, has_release=False) is True
+
+
+def test_summarize_allows_negative_balance():
+    """提交占用可超过已上传总额,余额可为负(补票后再回升)。"""
+    rows = [
+        {"entry_type": ENTRY_CREDIT_UPLOAD, "amount": Decimal("100")},
+        {"entry_type": ENTRY_DEBIT_REIMBURSE, "amount": Decimal("300")},
+    ]
+    s = summarize_entries(rows)
+    assert s["total_amount"] == Decimal("100")
+    assert s["used_amount"] == Decimal("300")
+    assert s["balance"] == Decimal("-200")