mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-21 07:22:02 +00:00
列表中间像小计的行:照常导入、要人确认,带「改作小计核对」的修复按钮
为什么:配方没配小计的列表(期 4 起草的、或者某一期才开始出现小计的文件),首列写着「小计」、其余文字列空着的行
以前静默当数据导入,对金额列求和就把小计重复算了进去,核对也看不出来(H2)。细案 E 的复用里列了「recipe_fixes
加一个小计修复按钮」,这里补上它的触发。
- 执行器:没配 subtotals 时,首列以合计字样开头、其余文字和日期列为空、至少一格有数的行,照常按数据导入,收尾时
合成一条 subtotal_suspect(需确认类,不拒收:确实是数据的,勾确认项照常导入);首列以「累计」开头、别的文字列有字
的商品名这类数据行不算。
- 修复按钮 declare_subtotals(FIX_KINDS 末尾新增):给这个列表加 rows.subtotals(标签列、开头词取自文件里的合计
字样),可选只核对或另存成「{表}_小计」;块已配小计、开头词含数字时不提议。
- 确认项 subtotal_suspect:<块>;前端修复按钮文字「改作小计核对」。
This commit is contained in:
@@ -488,7 +488,8 @@ def test_closed_value_sets():
|
||||
"header", "row_label", "section_title", "total_word", "axis", "after_title", "outside_text")
|
||||
assert _literal(T.EditResult, "kind") == ("fix", "selection")
|
||||
assert _literal(T.ChangeClass, "change") == ("same", "compatible", "retire", "semantic")
|
||||
assert T.FIX_KINDS == ("remove_label", "add_label", "edit_members", "rename_title", "declare_total",
|
||||
assert T.FIX_KINDS[-1] == "declare_subtotals" # 期 5 加在末尾
|
||||
assert T.FIX_KINDS[:-1] == ("remove_label", "add_label", "edit_members", "rename_title", "declare_total",
|
||||
"ignore_cells", "declare_placeholder", "declare_hidden", "rename_sheet")
|
||||
assert T.SELECTION_AS == ("list", "crosstab", "segment", "derived", "section_title", "ignore_rows",
|
||||
"ignore_columns", "ignore_outside")
|
||||
|
||||
@@ -330,6 +330,18 @@ def c_subtotal_blank(mp):
|
||||
return _run(sales_book(edit=edit), data), [N]
|
||||
|
||||
|
||||
def c_subtotal_suspect(mp):
|
||||
"""期 5:没配小计时,首列以合计字样开头、其余文字列空着的行像夹在中间的小计:照常导入,要人确认。"""
|
||||
data = list_recipe()
|
||||
|
||||
def edit(ws):
|
||||
ws["D4"] = N
|
||||
ws.insert_rows(6)
|
||||
ws["A6"] = "小计"
|
||||
ws["D6"] = N
|
||||
return _run(sales_book(edit=edit), data), [N]
|
||||
|
||||
|
||||
def c_value_not_integer(mp):
|
||||
return _run(_flow(_set(C11=9876.54)), FLOW), [9876.54]
|
||||
|
||||
|
||||
@@ -119,7 +119,9 @@ def test_problem_fix_table_follows_spec_3_1():
|
||||
"label_unparsed": "declare_total", "value_not_number": "declare_placeholder",
|
||||
"axis_extra_cells": "ignore_cells", "column_extra": "ignore_cells", "row_unclaimed": "ignore_cells",
|
||||
"outside_number": "ignore_cells", "hidden_rows": "declare_hidden", "hidden_cols": "declare_hidden",
|
||||
"sheet_missing": "rename_sheet"}
|
||||
"sheet_missing": "rename_sheet",
|
||||
# 期 5:没配小计的列表里像小计的行
|
||||
"subtotal_suspect": "declare_subtotals"}
|
||||
assert set(recipe_engine.PROBLEM_FIX.values()) <= set(FIX_KINDS)
|
||||
# edit_members 只来自静态校验;cell_unclaimed、rows_after_stop 没有修复按钮
|
||||
assert "edit_members" not in recipe_engine.PROBLEM_FIX.values()
|
||||
@@ -367,9 +369,17 @@ def _column_extra():
|
||||
return sales_book(edit=edit), LIST
|
||||
|
||||
|
||||
def _subtotal_suspect():
|
||||
def edit(ws):
|
||||
ws.insert_rows(6)
|
||||
ws["A6"], ws["D6"], ws["E6"] = "小计", N, N + 1
|
||||
return sales_book(edit=edit), LIST
|
||||
|
||||
|
||||
@pytest.mark.parametrize("code", sorted(recipe_engine.PROBLEM_FIX))
|
||||
def test_fix_args_never_carry_cell_values(code):
|
||||
book, recipe = _column_extra() if code == "column_extra" else _crosstab_cases()[code]
|
||||
book, recipe = (_column_extra() if code == "column_extra" else _subtotal_suspect() if code == "subtotal_suspect"
|
||||
else _crosstab_cases()[code])
|
||||
ex = run(book, recipe)
|
||||
hits = [p for p in ex.problems if p.code == code and p.fix_args is not None]
|
||||
assert hits, f"{code}:{[(p.code, p.fix, p.message) for p in ex.problems]}"
|
||||
|
||||
@@ -433,3 +433,46 @@ def test_csv_drafts_a_list_and_the_engine_runs_it(tmp_path):
|
||||
# 回执的坐标照 Excel 打开这个 CSV 时的 A1 写
|
||||
[excluded] = [x for x in ex.rows_excluded if x.reason == "subtotal"]
|
||||
assert excluded.sheet == "CSV" and excluded.rows == [[4, 4]]
|
||||
|
||||
|
||||
# ==========================================================================
|
||||
# 没配小计时,像小计的行:照常导入、要人确认,带「改作小计核对」的修复按钮
|
||||
# ==========================================================================
|
||||
|
||||
|
||||
def test_a_subtotal_like_row_without_subtotals_is_flagged_and_fixable(tmp_path):
|
||||
from app.data import recipe_confirm, recipe_fixes
|
||||
from app.data.recipe import apply_patch
|
||||
|
||||
plain = _list(STORE_COLS, rows={"total_row": {"label_column": "地区", "pick": "合计"}})
|
||||
ex = _run(_book(STORES), plain)
|
||||
[p] = [p for p in ex.problems if p.code == "subtotal_suspect"]
|
||||
assert p.category == "confirm" and p.fix == "declare_subtotals"
|
||||
assert p.cells == ["明细!A4", "明细!A7"] and p.fix_args["pick"] == "小计" and p.fix_args["label_column"] == "地区"
|
||||
assert ex.ok # 需确认类:照常导入,提交时勾确认项
|
||||
full = Recipe.model_validate(plain).model_dump(mode="json")
|
||||
[prop] = recipe_fixes.propose_fixes(full, [recipe_fixes.dataclasses.asdict(p)], [], None)
|
||||
assert prop.kind == "declare_subtotals" and [o.value for o in prop.options] == ["check_only", "keep"]
|
||||
res = recipe_fixes.fix_ops(full, prop, "check_only", None)
|
||||
assert res.ok, res.problems
|
||||
fixed = apply_patch(full, res.ops)
|
||||
assert fixed["sheets"][0]["blocks"][0]["rows"]["subtotals"]["pick"] == "小计"
|
||||
db = str(tmp_path / "f.db")
|
||||
ex2 = _run(_book(STORES), fixed, db)
|
||||
assert ex2.ok and not [p for p in ex2.problems if p.code == "subtotal_suspect"]
|
||||
assert _checks(db, ex2, fixed)["T2"].status == "passed"
|
||||
keep = apply_patch(full, recipe_fixes.fix_ops(full, prop, "keep", None).ops)
|
||||
assert keep["tables"][-1] == {"name": "明细_小计", "grain": [], "kind": "reported_total", "units": {}, "note": ""}
|
||||
assert validate_recipe(keep, facts=None, origin="rules")[1] == []
|
||||
# 确认项:没改作小计核对就提交的,要勾「确实是数据」
|
||||
items = recipe_confirm.confirm_items(recipe_confirm.ConfirmContext(kind="first", recipe=plain, extraction=ex,
|
||||
checks=[]))
|
||||
[item] = [i for i in items if i.id == "subtotal_suspect:列表1"]
|
||||
assert item.required and "改作小计核对" in item.label
|
||||
|
||||
|
||||
def test_ordinary_rows_starting_with_a_total_word_are_not_flagged():
|
||||
"""首列以「累计」开头、别的文字列有字的是数据(「累计积分卡」这种商品名),不当成像小计的行。"""
|
||||
rows = [("商品", "门店", "金额"), ("累计积分卡", "门店一", 10), ("普通卡", "门店二", 20)]
|
||||
ex = _run(_book(rows), _list([("商品", "TEXT"), ("门店", "TEXT"), ("金额", "INTEGER")]))
|
||||
assert ex.ok and not [p for p in ex.problems if p.code == "subtotal_suspect"]
|
||||
|
||||
Reference in New Issue
Block a user