fix(ТСН): при нулевой оплате труда НР/СП не начисляются и расчёт помечен неполным

У машинных расценок ОТ=0 (зарплата внутри «Эксплуатации машин»): процент от нуля давал
0,0 как будто норма применена. Теперь это nr_sp_incomplete с прямыми затратами в итоге.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
anor
2026-11-18 04:45:43 +10:00
co-authored by Claude Code
parent 016a5ea9a5
commit d752339315
2 changed files with 31 additions and 7 deletions
+19
View File
@@ -121,3 +121,22 @@ def test_missing_profit_rate_marks_incomplete(monkeypatch):
res = tsn_calc.calc_position("1-5-1", work_type="Земляные работы") 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["nr_sp_incomplete"] is True and res["nr_sp"] is None
assert res["total"] == 6022.5, res # 5500 + 522,5 без прибыли 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"]
+12 -7
View File
@@ -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"]: if got.get("status") == "ok" and got["items"]:
rate = got["items"][0] rate = got["items"][0]
ot = current.get("ot") or 0 ot = current.get("ot") or 0
if rate.get("overhead") is not None: if ot:
nr = _money(ot * rate["overhead"] / 100.0) if rate.get("overhead") is not None:
if rate.get("profit") is not None: nr = _money(ot * rate["overhead"] / 100.0)
sp = _money(ot * rate["profit"] / 100.0) if rate.get("profit") is not None:
incomplete = nr is None or sp is 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)) total = _money((current.get("pz") or 0) + (nr or 0) + (sp or 0))
return {"status": "ok", "code": code, "base": base, "current": current, return {"status": "ok", "code": code, "base": base, "current": current,
"method": "rate_index", "index": idx, "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, "nr_sp_incomplete": incomplete, "total": total,
"message": (f"текущая цена = база 2000 × {k} (выпуск {idx.get('issue_no')})" "message": (f"текущая цена = база 2000 × {k} (выпуск {idx.get('issue_no')})"
+ ("" if not incomplete else + ("" if not incomplete else
"; НР/СП не начислены: вид работ не назван или норма не найдена — " "; НР/СП не начислены: вид работ не назван, норма не найдена "
"итог без них, расчёт неполный"))} "или в расценке нет ОТ — итог без них, расчёт неполный"))}
def calc_estimate(positions: list[dict], *, as_of: str | None = None) -> dict: def calc_estimate(positions: list[dict], *, as_of: str | None = None) -> dict: