Files
smeta-railway/tests/test_zone_prices.py
T
anorandClaude Opus 5 d9fae4dee3 fix(движок): материалы по сметной цене; ресурс без цены в форме зоны — «не оценён», а не базис без индекса
Разбор формы брал отпускную цену материала раньше сметной. В строгом режиме ресурс, которого нет
в форме ценовой зоны, молча считался по базисной цене ресурсного состава — и «голой», и умноженной на
индекс зоны; теперь цена ноль и запись в result.unpriced, итог помечается неполным.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADvViaqN9hgCWVNH3HVQ6r
2026-09-14 18:50:09 +10:00

112 lines
6.1 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.
"""Цены движка по форме ценовой зоны: сметная цена материала и честный «не оценён».
Разбор 14.09.2026 (smeta-web docs/TASK_2026-09-14_engine_zones.md):
- разбор формы брал базисную цену материала из колонки 3 (отпускная) раньше колонки 4 (сметная),
хотя смета считается по сметной цене; справочные инструменты сервиса (rim_calc, fgis_ref) берут её;
- в строгом режиме ресурс, которого нет в форме зоны (ни индекса, ни текущей цены), молча
считался по базисной цене 2022 года без индекса — занижение итога без пометки. Решение
владельца: итог считается, но помечается неполным со списком неоценённых ресурсов.
"""
import openpyxl
from smeta_railway.calc.estimate import EstimateCalculator
from smeta_railway.config import Section, Subsection, WorkItem
from smeta_railway.data.fgis import FGISLookup, build_fgis_lookup
from smeta_railway.models import (
LaborResource,
MachineResource,
MaterialResource,
NormResources,
)
def _form(tmp_path, rows):
"""Сплит-форма с раскладкой ФГИС: 0 код, 3 отпускная, 4 сметная, 7 текущая, 8 индекс."""
wb = openpyxl.Workbook()
ws = wb.active
for r in rows:
ws.append(r)
path = tmp_path / "form.xlsx"
wb.save(path)
return str(path)
def test_базисная_цена_материала_сметная_а_не_отпускная(tmp_path):
path = _form(tmp_path, [
["01.7.15.03-0042", "Болты", "т", 100.0, 110.0, None, None, 520.0, 4.2],
])
lookup = build_fgis_lookup(path)
assert lookup.base_price_map["01.7.15.03-0042"] == 110.0
def test_без_сметной_берётся_отпускная(tmp_path):
"""Ограждение: в форме бывают строки только с одной ценой."""
path = _form(tmp_path, [
["01.7.15.03-0043", "Шайбы", "т", 100.0, None, None, None, None, None],
])
assert build_fgis_lookup(path).base_price_map["01.7.15.03-0043"] == 100.0
def _position(materials=(), machines=()):
return {"01-01-001-01": NormResources(
norm_code="01-01-001-01", norm_name="Проба", unit="м3",
ozp=LaborResource(razryad=3.0, chel_hours=1.0),
machines=list(machines), materials=list(materials))}
def _calc(resources, strict=True):
fgis = FGISLookup(labor_price_map={"1-100-30": 600.0, "4-100-030": 700.0})
calc = EstimateCalculator(fgis=fgis, resources=resources, strict=strict)
section = Section(name="С", subsections=[Subsection(name="", items=[
WorkItem(code="01-01-001-01", name="Проба", unit="м3", qty=2.0)])])
return calc.calculate([section])
def test_материал_без_цены_в_форме_не_оценён_и_назван():
res = _calc(_position(materials=[MaterialResource(
code="02.2.05.04-2090", name="Щебень", unit="м3", qty=1.5, cost_base=900.0)]))
assert res.positions[0].mat_cost == 0.0
assert [u["code"] for u in res.unpriced] == ["02.2.05.04-2090"], res.unpriced
assert "конъюнктур" in res.unpriced[0]["reason"]
assert res.ok is True, "неоценённый ресурс — неполный итог, а не отказ от всей сметы"
def test_машина_без_цены_в_форме_не_оценена_и_названа():
res = _calc(_position(machines=[MachineResource(
code="91.05.05-015", name="Кран", unit="маш.-ч", qty=0.5, cost_base=1200.0)]))
assert res.positions[0].em_cost == 0.0
assert [u["code"] for u in res.unpriced] == ["91.05.05-015"], res.unpriced
def test_нестрогий_режим_как_раньше():
"""Ограждение: мастер ССР и нестрогие вызовы пока считают по базисной цене."""
res = _calc(_position(materials=[MaterialResource(
code="02.2.05.04-2090", name="Щебень", unit="м3", qty=1.5, cost_base=900.0)]), strict=False)
assert res.positions[0].mat_cost == round(1.5 * 2.0 * 900.0, 2)
assert not res.unpriced
def test_повторный_расчёт_не_копит_список():
"""Калькулятор переиспользуется для пересчёта: второй расчёт не наследует первый."""
fgis = FGISLookup(labor_price_map={"1-100-30": 600.0})
calc = EstimateCalculator(fgis=fgis, strict=True, resources=_position(materials=[
MaterialResource(code="02.2.05.04-2090", name="Щебень", unit="м3", qty=1.5,
cost_base=900.0)]))
section = Section(name="С", subsections=[Subsection(name="", items=[
WorkItem(code="01-01-001-01", name="Проба", unit="м3", qty=1.0)])])
calc.calculate([section])
assert len(calc.calculate([section]).unpriced) == 1
def test_индекс_зоны_без_базисной_цены_формы_не_умножается_на_чужую_базу():
"""Индекс в форме есть, базисной цены нет: умножать индекс зоны на базисную цену из ресурсных
составов нельзя — это другая база (разбор 14.09.2026, нашла зайка)."""
fgis = FGISLookup(labor_price_map={"1-100-30": 600.0}, index_map={"02.2.05.04-2090": 3.0})
calc = EstimateCalculator(fgis=fgis, strict=True, resources=_position(materials=[
MaterialResource(code="02.2.05.04-2090", name="Щебень", unit="м3", qty=1.0, cost_base=500.0)]))
section = Section(name="С", subsections=[Subsection(name="", items=[
WorkItem(code="01-01-001-01", name="Проба", unit="м3", qty=1.0)])])
res = calc.calculate([section])
assert res.positions[0].mat_cost == 0.0
assert [u["code"] for u in res.unpriced] == ["02.2.05.04-2090"]