Files
pricing_review/CostReview/app/tests/test_lme_uw_card.py

68 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""原数据·单位工程级工料机汇总防回归(决策 41,2026-10-11 主人定)。
口径:优先直读本单位工程自己的工料机汇总节点(s_lme_uw / lme_uw,解析时按 uw 归属
原样入库)——名称/规格/总数量/单价=源文件原样,返回 src='summary';老会话/老批次没有
这张表的数据 → 回退"清单→定额→消耗量"归集口径(src='agg'),行为与从前一致。
"""
import sqlite3
import sys, os
_HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(_HERE), "core"))
sys.path.insert(0, os.path.join(os.path.dirname(_HERE), "server"))
import api_server as srv # noqa: E402
def _mk_sess(with_summary):
sc = sqlite3.connect(":memory:")
sc.row_factory = sqlite3.Row
c = sc.cursor()
c.execute("CREATE TABLE sessions(id INTEGER PRIMARY KEY, name TEXT, src_name TEXT)")
c.execute("""CREATE TABLE s_unit_works(id INTEGER PRIMARY KEY, session_id INT,
section_id INT, Number TEXT, Name TEXT, Total REAL, Specialty TEXT)""")
c.execute("""CREATE TABLE s_lme_uw(id INTEGER PRIMARY KEY, session_id INT, uw_id INT,
code TEXT, name TEXT, spec TEXT, unit TEXT, kind INT,
qty REAL, ntp REAL, taxrate REAL, taxp REAL,
ntp_org REAL, ntp_expr REAL, taxp_org REAL, taxp_expr REAL, x_flags TEXT)""")
c.execute("""CREATE TABLE s_lmes(id INTEGER PRIMARY KEY, session_id INT,
Number TEXT, Name TEXT, Specification TEXT, Unit TEXT, Kind INT,
NoTaxPrice REAL, TaxPrice REAL)""")
c.execute("""CREATE TABLE s_bills(id INTEGER PRIMARY KEY, session_id INT, uw_id INT,
Number TEXT)""")
c.execute("""CREATE TABLE s_norms(id INTEGER PRIMARY KEY, session_id INT, bill_id INT, x_side TEXT)""")
c.execute("""CREATE TABLE s_norm_res(id INTEGER PRIMARY KEY, norm_id INT,
res_code TEXT, qty REAL)""")
c.execute("INSERT INTO sessions VALUES(1,'工程甲','H_甲.cos4')")
c.execute("INSERT INTO s_unit_works VALUES(10, 1, NULL, 'UW-1', '土建单位工程', 100, '建筑')")
if with_summary:
# 源文件汇总节点原样:总数量 50.5825(归集 SUM 只会算出别的数)
c.execute("""INSERT INTO s_lme_uw(session_id, uw_id, code, name, spec, unit, kind,
qty, ntp, taxrate, taxp)
VALUES(1, 10, '05010002', '普通硅酸盐水泥', 'P.O42.5', 'kg', 2,
50.5825, 0.38, NULL, 0.4104)""")
else:
c.execute("INSERT INTO s_lmes VALUES(1, 1, '05010002', '普通硅酸盐水泥', '', 'kg', 2, 0.38, 0.4104)")
c.execute("INSERT INTO s_bills VALUES(1, 1, 10, 'B1')")
c.execute("INSERT INTO s_norms VALUES(1, 1, 1, NULL)")
c.execute("INSERT INTO s_norm_res VALUES(1, 1, '05010002', 33.5)")
sc.commit()
return sc
def test_summary_source_preferred():
sc = _mk_sess(with_summary=True)
d = srv._raw_uw(sc, srv.TBL["session"], 10, "lme")
assert d["src"] == "summary"
r = d["rows"][0]
assert r[0] == "05010002" and r[1] == "普通硅酸盐水泥" and r[5] == 50.5825 # 总数量=源文件原样
assert d["uw"]["Name"] == "土建单位工程"
def test_agg_fallback_without_summary():
sc = _mk_sess(with_summary=False)
d = srv._raw_uw(sc, srv.TBL["session"], 10, "lme")
assert d["src"] == "agg"
assert d["rows"][0][0] == "05010002" and d["rows"][0][5] == 33.5 # 归集 SUM(qty)