From d7523393154717c6985bf19ac3e70c9668193d69 Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 18 Nov 2026 04:45:43 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D0=A2=D0=A1=D0=9D):=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BD=D1=83=D0=BB=D0=B5=D0=B2=D0=BE=D0=B9=20=D0=BE=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D0=B5=20=D1=82=D1=80=D1=83=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=A0/=D0=A1=D0=9F=20=D0=BD=D0=B5=20=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B8=D1=81=D0=BB=D1=8F=D1=8E=D1=82=D1=81=D1=8F=20=D0=B8=20?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D1=87=D1=91=D1=82=20=D0=BF=D0=BE=D0=BC=D0=B5?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=20=D0=BD=D0=B5=D0=BF=D0=BE=D0=BB=D0=BD=D1=8B?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit У машинных расценок ОТ=0 (зарплата внутри «Эксплуатации машин»): процент от нуля давал 0,0 как будто норма применена. Теперь это nr_sp_incomplete с прямыми затратами в итоге. Co-Authored-By: Claude Code --- tests/test_tsn_calc.py | 19 +++++++++++++++++++ tsn_calc.py | 19 ++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) 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: