Repository navigation
Conversation
… RATE_LINE
t0() 内部 buy_money/sale_money 是 Decimal,而 w_rate 是 float,
Decimal * float 会直接抛 TypeError。由于只有在金额超过 RATE_LINE
(20000)时才会走 buy_money * w_rate 这条分支,所以任何单笔 2 万元
以上的交易都会崩溃:
>>> office.finance.t0(100, 110, 700)
TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'
修复方式与同函数内已有的 Decimal(str(stamp_tax)) 保持一致,先把
w_rate 转成 Decimal 再参与运算。低于 RATE_LINE 时走 min_rate 分支,
行为不变。
同时新增 tests/test_utils/test_finance_t0.py 覆盖大额/小额/自定义费率
三种场景(该模块此前没有测试)。
CoderWanFeng
pushed a commit
that referenced
this pull request
Oct 25, 2026
Owner
|
感谢贡献!🎉 你的修复已合入 合入 commit: 验证情况:
改动很干净:3 行修复 + 33 行测试,正是我们想要的最小侵入式修法。期待你继续贡献! |
CoderWanFeng
pushed a commit
that referenced
this pull request
Oct 26, 2026
发布 1.1.0:合入 #183 / #184 / #185 三个 PR,以及自 1.0.6 以来的全部修复。 主要内容: - feat(cli): 第一波 CLI 实现 —— `po` 命令 (#184) - feat(contributors): 5 个 Excel 数据核对与整理方法 (#185) - feat(contributor): batch_rename_by_excel (#183) - fix(excel): 拆分时保留 0 值 (#180) - fix(finance): t0 的 Decimal/float TypeError (#181) - fix(excel): 拆分输出工作簿有效性 (#182) - 及其他 1.0.6 以来的修复与文档更新 - 合并 main 独有的 #141 / #155 版本号: 1.0.6 → 1.1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
office/api/finance.py的t0()(做T收益计算)中,buy_money/sale_money是Decimal,而w_rate是float:Decimal与float不能直接相乘。由于只有在金额超过RATE_LINE = 10000 * 2(2 万元)时才会走到乘法分支,所以任何单笔 2 万元以上的交易都会崩溃:修复
先把
w_rate转成Decimal,与同一函数里已有的Decimal(str(stamp_tax))写法保持一致:金额低于
RATE_LINE时走min_rate分支,行为完全不变;用str()中转可以避免把 float 的二进制误差带进金额计算。测试
新增
tests/test_utils/test_finance_t0.py(该模块此前没有测试),覆盖三个场景:RATE_LINE,佣金按比例计算)RATE_LINE,按最低手续费min_rate)w_rate修复前 / 修复后对比(修复前有 2 个用例失败):
补充说明
函数签名标注的是
-> float,但实际返回的是Decimal(原有行为,本 PR 未改动,以免影响已有调用方)。如果希望返回值与文档一致,可另改为return float(stock_returns),需要的话我再单独提一个 PR。