diff --git a/tests/test_tsn_calc.py b/tests/test_tsn_calc.py index 1955235..c61b950 100644 --- a/tests/test_tsn_calc.py +++ b/tests/test_tsn_calc.py @@ -121,3 +121,22 @@ def test_missing_profit_rate_marks_incomplete(monkeypatch): res = tsn_calc.calc_position("1-5-1", work_type="Земляные работы") assert res["nr_sp_incomplete"] is True and res["nr_sp"] is None assert res["total"] == 6022.5, res # 5500 + 522,5 без прибыли + + +def test_zero_labour_marks_nr_sp_incomplete(monkeypatch): + """ОТ=0 (вся зарплата внутри ЭМ) — НР/СП от ФОТ не начислить: помечаем неполноту, + а не показываем ноль как норму.""" + import tsn_calc, tsn_ref + monkeypatch.setattr(tsn_ref, "find_work", lambda q, as_of=None, limit=5: { + "status": "ok", "items": [{"code": "1-14-1", "book": "ТСН-2001.3", "chapter": "3-1", + "pz": 84.89, "ot": 0.0, "em": 84.89, "mat": 0.0, + "unit": "1000 м3", "addendum_no": "", "edition": ""}]}) + monkeypatch.setattr(tsn_calc, "find_rate_index", lambda w, as_of=None: { + "status": "ok", "value": 73.0, "issue_no": "222", "quarter": 4, "year": 2026}) + monkeypatch.setattr(tsn_ref, "find_nr_sp", lambda q: { + "status": "ok", "items": [{"work_type": "Земляные работы", "overhead": 98.0, + "profit": 77.0}]}) + res = tsn_calc.calc_position("1-14-1", work_type="Земляные работы") + assert res["nr_sp_incomplete"] is True and res["nr_sp"] is None + assert res["total"] == 6196.97 + assert "ОТ" in res["message"] diff --git a/tsn_calc.py b/tsn_calc.py index 20482f2..6eaafb3 100644 --- a/tsn_calc.py +++ b/tsn_calc.py @@ -83,11 +83,16 @@ def calc_position(code: str, qty: float = 1.0, *, as_of: str | None = None, if got.get("status") == "ok" and got["items"]: rate = got["items"][0] ot = current.get("ot") or 0 - if rate.get("overhead") is not None: - nr = _money(ot * rate["overhead"] / 100.0) - if rate.get("profit") is not None: - sp = _money(ot * rate["profit"] / 100.0) - incomplete = nr is None or sp is None + if ot: + if rate.get("overhead") is not None: + nr = _money(ot * rate["overhead"] / 100.0) + if rate.get("profit") is not None: + sp = _money(ot * rate["profit"] / 100.0) + incomplete = nr is None or sp is None + else: + # зарплата рабочих в расценке нулевая (она внутри «Эксплуатации машин»): + # начислять НР/СП от ФОТ не от чего — честно помечаем неполноту + incomplete = True total = _money((current.get("pz") or 0) + (nr or 0) + (sp or 0)) return {"status": "ok", "code": code, "base": base, "current": current, "method": "rate_index", "index": idx, @@ -95,8 +100,8 @@ def calc_position(code: str, qty: float = 1.0, *, as_of: str | None = None, "nr_sp_incomplete": incomplete, "total": total, "message": (f"текущая цена = база 2000 × {k} (выпуск {idx.get('issue_no')})" + ("" if not incomplete else - "; НР/СП не начислены: вид работ не назван или норма не найдена — " - "итог без них, расчёт неполный"))} + "; НР/СП не начислены: вид работ не назван, норма не найдена " + "или в расценке нет ОТ — итог без них, расчёт неполный"))} def calc_estimate(positions: list[dict], *, as_of: str | None = None) -> dict: