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

55 lines
2.8 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 -*-
"""2026-11-04 主人定(合并工料机口径):
① 现算数量为 0 的品种也要显示、也要能参与合并(取代决策 244「0 量码不进弹框」);
② 合并弹框的数量与项目级/单位级工料机汇总页同源(dyn_lme 现算),组头按码去重相加。
"""
import os
import sqlite3
import sys
_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():
sc = sqlite3.connect(":memory:")
sc.row_factory = sqlite3.Row
c = sc.cursor()
c.execute("""CREATE TABLE s_lme_proj(id INTEGER PRIMARY KEY, session_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_merged_hide INT DEFAULT 0)""")
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_lme_res(id INTEGER PRIMARY KEY, session_id INT, p_code TEXT,
res_code TEXT, qty REAL, seq INT, name TEXT)""")
# 同组两个码:A 有现算量、B 现算 0(旧口径会被排除)
c.execute("""INSERT INTO s_lme_uw(session_id, uw_id, code, name, spec, unit, kind, qty, ntp, taxp)
VALUES(1, 101, 'A1', '折旧费', '', '元', 3, 10.0, 1.0, 1.0)""")
c.execute("""INSERT INTO s_lme_uw(session_id, uw_id, code, name, spec, unit, kind, qty, ntp, taxp)
VALUES(1, 101, 'B1', '折旧费', '', '元', 3, 5.0, 1.0, 1.0)""")
sc.commit()
return sc
def test_merge_groups_keep_zero_qty(monkeypatch):
sc = _mk()
# 链可用(dyn_rows 非 None);成员级数量走 qty_map_uw:A1=12.5、B1=0(0 量品种必须仍显示)
monkeypatch.setattr(srv.dyn_lme, "dyn_rows",
lambda *a, **k: [[None, "A1", "折旧费", "", "元", 12.5],
[None, "B1", "折旧费", "", "元", 0.0]])
monkeypatch.setattr(srv.dyn_lme, "qty_map_uw", lambda *a, **k: {"A1": 12.5, "B1": 0.0})
d = srv._lme_merge_groups(sc, 1)
g = [x for x in d["groups"] if x["name"] == "折旧费"]
assert g, "折旧费组没出现"
g = g[0]
codes = {r["code"]: r["qty"] for r in g["rows"]}
assert codes.get("B1") == 0.0, "0 量品种被排除了:%s" % codes
assert codes.get("A1") == 12.5
assert g["qty"] == 12.5 # 组头按码去重相加