42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""发票额度流水汇总与退回幂等。"""
|
|
from decimal import Decimal
|
|
|
|
from app.services.bx.invoice_ledger import (
|
|
ENTRY_CREDIT_RELEASE,
|
|
ENTRY_CREDIT_UPLOAD,
|
|
ENTRY_DEBIT_DELETE,
|
|
ENTRY_DEBIT_REIMBURSE,
|
|
should_skip_release,
|
|
summarize_entries,
|
|
)
|
|
|
|
|
|
def test_summarize_upload_and_reimburse():
|
|
rows = [
|
|
{"entry_type": ENTRY_CREDIT_UPLOAD, "amount": Decimal("1000")},
|
|
{"entry_type": ENTRY_DEBIT_REIMBURSE, "amount": Decimal("300")},
|
|
]
|
|
s = summarize_entries(rows)
|
|
assert s["total_amount"] == Decimal("1000")
|
|
assert s["used_amount"] == Decimal("300")
|
|
assert s["balance"] == Decimal("700")
|
|
|
|
|
|
def test_summarize_delete_and_release():
|
|
rows = [
|
|
{"entry_type": ENTRY_CREDIT_UPLOAD, "amount": Decimal("500")},
|
|
{"entry_type": ENTRY_DEBIT_DELETE, "amount": Decimal("100")},
|
|
{"entry_type": ENTRY_DEBIT_REIMBURSE, "amount": Decimal("200")},
|
|
{"entry_type": ENTRY_CREDIT_RELEASE, "amount": Decimal("200")},
|
|
]
|
|
s = summarize_entries(rows)
|
|
assert s["total_amount"] == Decimal("400")
|
|
assert s["used_amount"] == Decimal("0")
|
|
assert s["balance"] == Decimal("400")
|
|
|
|
|
|
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
|