refactor(m3): calc_receipt 五段拆分——218 行收敛为编排 + 私有函数
code-review 约定合规项(CLAUDE.md「单一职责 ≤50 行」):原 218 行单函数 把锁行校验、模式预处理、输入装载、逐行折算、计提组成、落库全部内联, 待澄清答复回填时改动回归面大。按原执行顺序拆为四段私有函数 + 两个 冻结 dataclass(_Conversion/_Amounts),主函数只做编排;行为零变化 (M3 全部用例原样通过): - _load_and_guard:锁行 + 模式校验 + 月结锁定拦截 + 业务归属校验 - _prepare_mode:重算作废旧版本 / 首算判一次性计提(进度登记提前返回) - _load_shipment / _load_person / _load_items:输入装载三查 - _convert_items → _Conversion:逐行折算(行级阈值/缺成本标记/行级明细) - _compose_amounts → _Amounts:比例分派 → 绩效 → 抵顶 → 权重 → 应付 - _persist_ledger:落台账行 + 首算 CAS - 局部 q2 提为模块级 _q2(新增单测锁定 HALF_UP:2.345→2.35, 缺省银行家舍入会得 2.34) 验证:全量 780 passed;type-check 绿 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
45c268b146
commit
7a99994d17
2 files changed
+339
-199
No files matched your search
@@ -0,0 +1,28 @@
|
||||
"""核算落库辅助纯函数测试。
|
||||
|
||||
守的是:金额两位固化的舍入模式 —— quantize 缺省是上下文 ROUND_HALF_EVEN
|
||||
(银行家舍入),x.xx5 会舍成偶数尾数,与业务四舍五入口径差 1 分
|
||||
(docstring 声称 HALF_UP,必须用测试锁死实际行为)。
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from app.services.calc_service import _q2
|
||||
|
||||
|
||||
class TestQ2:
|
||||
"""金额两位小数(HALF_UP)。"""
|
||||
|
||||
def test_半进位一律入(self) -> None:
|
||||
# 缺省 ROUND_HALF_EVEN 会舍成 2.34(4 是偶数)
|
||||
assert _q2(Decimal("2.345")) == Decimal("2.35")
|
||||
|
||||
def test_负数半进位远离零(self) -> None:
|
||||
assert _q2(Decimal("-2.345")) == Decimal("-2.35")
|
||||
|
||||
def test_普通进位不变(self) -> None:
|
||||
assert _q2(Decimal("39.111111")) == Decimal("39.11")
|
||||
assert _q2(Decimal("39.115000")) == Decimal("39.12")
|
||||
|
||||
def test_None直通(self) -> None:
|
||||
assert _q2(None) is None
|
||||
Reference in new issue
Block a user