Show norm cost breakdown and reference rates in finder
This commit is contained in:
@@ -12,8 +12,10 @@ def test_browse_keeps_sections_and_base_types_separate(tmp_path, monkeypatch):
|
||||
with sqlite3.connect(db) as con:
|
||||
con.execute("CREATE TABLE sources (source_id INTEGER)")
|
||||
con.execute("CREATE TABLE works (base TEXT, base_type TEXT, code TEXT, name TEXT, "
|
||||
"unit TEXT, cost REAL, price_level TEXT, section_path TEXT)")
|
||||
con.executemany("INSERT INTO works VALUES (?,?,?,?,?,?,?,?)", [
|
||||
"unit TEXT, cost REAL, price_level TEXT, section_path TEXT, "
|
||||
"salary REAL, machines REAL, salary_mach REAL, materials REAL)")
|
||||
con.executemany("INSERT INTO works (base,base_type,code,name,unit,cost,price_level,section_path) "
|
||||
"VALUES (?,?,?,?,?,?,?,?)", [
|
||||
("ГЭСН-2022", "ГЭСН", "01-01-001-01", "Разработка грунта", "1000 м3", None,
|
||||
"норма", "Земляные работы > Раздел 1 > Таблица 1"),
|
||||
("ГЭСН-2022", "ГЭСН", "01-01-001-02", "Разработка грунта 2", "1000 м3", None,
|
||||
@@ -43,8 +45,10 @@ def test_browse_orders_collections_and_sections_by_norm_code(tmp_path, monkeypat
|
||||
with sqlite3.connect(db) as con:
|
||||
con.execute("CREATE TABLE sources (source_id INTEGER)")
|
||||
con.execute("CREATE TABLE works (base TEXT, base_type TEXT, code TEXT, name TEXT, "
|
||||
"unit TEXT, cost REAL, price_level TEXT, section_path TEXT)")
|
||||
con.executemany("INSERT INTO works VALUES (?,?,?,?,?,?,?,?)", [
|
||||
"unit TEXT, cost REAL, price_level TEXT, section_path TEXT, "
|
||||
"salary REAL, machines REAL, salary_mach REAL, materials REAL)")
|
||||
con.executemany("INSERT INTO works (base,base_type,code,name,unit,cost,price_level,section_path) "
|
||||
"VALUES (?,?,?,?,?,?,?,?)", [
|
||||
("ГЭСН-2022", "ГЭСН", "06-01-001-01", "Бетон", "м3", None,
|
||||
"норма", "Бетонные работы > Раздел 1"),
|
||||
("ГЭСН-2022", "ГЭСН", "02-01-001-01", "Горные работы", "м3", None,
|
||||
@@ -62,6 +66,42 @@ def test_browse_orders_collections_and_sections_by_norm_code(tmp_path, monkeypat
|
||||
assert [row["name"] for row in sections["children"]] == ["Раздел 2", "Раздел 10"]
|
||||
|
||||
|
||||
def test_browse_exposes_only_its_own_base_cost_components(tmp_path, monkeypatch):
|
||||
import norm_finder
|
||||
import fsnb_ref
|
||||
db = tmp_path / "costs.sqlite"
|
||||
with sqlite3.connect(db) as con:
|
||||
con.execute("CREATE TABLE sources (source_id INTEGER)")
|
||||
con.execute("CREATE TABLE works (base TEXT, base_type TEXT, code TEXT, name TEXT, "
|
||||
"unit TEXT, cost REAL, price_level TEXT, section_path TEXT, "
|
||||
"salary REAL, machines REAL, salary_mach REAL, materials REAL)")
|
||||
con.executemany("INSERT INTO works VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", [
|
||||
("ГЭСН-2022", "ГЭСН", "01-01-001-01", "Земляные работы", "1000 м3", None,
|
||||
"01.01.2022", "Земляные работы", None, None, None, None),
|
||||
("ФЕР-2020", "ФЕР", "01-01-001-01", "Земляные работы", "1000 м3", 2968.03,
|
||||
"01.01.2000", "Земляные работы", 14.48, 2953.55, 87.84, 0.0),
|
||||
])
|
||||
monkeypatch.setattr(fsnb_ref, "db_path", lambda: db)
|
||||
fer = norm_finder.browse("2020", "ФЕР")["items"][0]
|
||||
assert {field: fer[field] for field in ("cost", "salary", "machines", "salary_mach", "materials")} == {
|
||||
"cost": 2968.03, "salary": 14.48, "machines": 2953.55,
|
||||
"salary_mach": 87.84, "materials": 0.0}
|
||||
gesn = norm_finder.browse("2022", "ГЭСН")["items"][0]
|
||||
assert all(gesn[field] is None for field in
|
||||
("cost", "salary", "machines", "salary_mach", "materials"))
|
||||
|
||||
|
||||
def test_rate_catalog_uses_source_table_item_without_assigning_it_to_norm():
|
||||
import norm_finder
|
||||
rows = norm_finder.rate_catalog()
|
||||
earthwork = next(row for row in rows if row["id"] == "1.1")
|
||||
assert earthwork["nr_pct"] == 92
|
||||
assert earthwork["sp_pct"] == 46
|
||||
assert earthwork["nr_code"] == "812/пр, п.1.1"
|
||||
assert earthwork["sp_code"] == "774/пр, п.1.1"
|
||||
assert all("code" not in row for row in rows)
|
||||
|
||||
|
||||
def test_search_rejects_empty_query_and_uses_existing_fsnb(monkeypatch):
|
||||
import fsnb_ref
|
||||
import norm_finder
|
||||
@@ -253,6 +293,20 @@ def test_finder_requires_login(api, method, path):
|
||||
assert getattr(client, method)(path).status_code == 401
|
||||
|
||||
|
||||
def test_catalog_exposes_rate_choices_without_automatic_norm_assignment(api, monkeypatch):
|
||||
import norm_finder
|
||||
client, headers, _ = api
|
||||
monkeypatch.setattr(norm_finder, "catalog", lambda: [])
|
||||
for path, auth_headers in (("/api/public/norm-finder/catalog", {}),
|
||||
("/api/norm-finder/catalog", headers)):
|
||||
response = client.get(path, headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
rates = response.json()["rates"]
|
||||
selected = next(row for row in rates if row["id"] == "1.1")
|
||||
assert selected["nr_pct"] == 92 and selected["sp_pct"] == 46
|
||||
assert "norm_code" not in selected
|
||||
|
||||
|
||||
def test_finder_api_search_detail_and_catalog(api, monkeypatch):
|
||||
import norm_finder
|
||||
client, headers, _ = api
|
||||
|
||||
Reference in New Issue
Block a user