fix(ТСН): строки раздела перебазировки в справочнике машин объяснены причиной

Тридцать из тридцати девяти карантинных строк .2 — раздел «Стоимость перебазировки»:
там рубли за перевозку машины, а не цена машино-часа. Брать их за цену ресурса нельзя,
и теперь причина карантина это говорит, а не «цена не найдена».

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
anor
2026-11-18 04:40:20 +10:00
co-authored by Claude Code
parent 3764b67064
commit e1029cdca3
2 changed files with 21 additions and 2 deletions
+8
View File
@@ -148,3 +148,11 @@ def test_name_keeps_numbers(tmp_path):
])
got = tsn_parse.parse_price_book(path, {"book": "ТСН-2001.1"})
assert got["items"][0]["name"] == "Pipe 100 mm", got["items"][0]["name"]
def test_relocation_section_rows_get_honest_reason():
"""Таблица «Стоимость перебазировки» — это не цена за маш.-ч: строка в карантин
с причиной, объясняющей отказ, а не «цена не найдена»."""
assert tsn_parse._price_missing_reason("Раздел 2. Стоимость перебазировки машин") \
== "раздел перебазировки: это стоимость перебазировки, не цена за маш.-ч"
assert tsn_parse._price_missing_reason("Сметные цены эксплуатации машин") == "цена не найдена"
+13 -2
View File
@@ -457,6 +457,7 @@ def parse_price_book(path: str, meta: dict | None = None) -> dict:
pages_total = doc.page_count
pending: dict | None = None # строка, у которой цена ещё не встретилась
for pno in range(pages_total):
page_text = doc[pno].get_text("text")
for line in _lines(doc[pno].get_text("words")):
if not line:
continue
@@ -465,7 +466,8 @@ def parse_price_book(path: str, meta: dict | None = None) -> dict:
and PB_CODE_MIN <= line[1][0] < PB_CODE_MAX
and len(line[1][2]) == code_len and line[1][2].isdigit()):
if pending:
quarantine.append(_pb_quarantine(pending, "цена не найдена"))
quarantine.append(_pb_quarantine(
pending, _price_missing_reason(page_text)))
rows_seen += 1
pending = {"pos": first[2], "code": line[1][2], "page": pno + 1,
"name": _words_in(line, PB_NAME_MIN, name_max),
@@ -489,7 +491,7 @@ def parse_price_book(path: str, meta: dict | None = None) -> dict:
(quarantine.append(why) if item is None else items.append(item))
pending = None
if pending:
quarantine.append(_pb_quarantine(pending, "цена не найдена"))
quarantine.append(_pb_quarantine(pending, _price_missing_reason(page_text)))
stats = {
"pages_total": pages_total,
"rows_seen": rows_seen,
@@ -501,6 +503,15 @@ def parse_price_book(path: str, meta: dict | None = None) -> dict:
"book": book, "file": meta.get("file")}
def _price_missing_reason(page_text: str) -> str:
"""Почему у строки нет цены. В справочнике машин есть раздел «Стоимость
перебазировки»: там рубли за перевозку машины, а не цена машино-часа, —
подставлять их в цену ресурса нельзя, и причина должна это говорить."""
if "перебазиров" in (page_text or "").lower():
return "раздел перебазировки: это стоимость перебазировки, не цена за маш.-ч"
return "цена не найдена"
def _pb_item(row: dict, price: float, unit: str, material: bool) -> tuple[dict | None, dict | None]:
code = f"{'1' if material else '2'}.{row['pos']}"
name = " ".join(row["name"]).strip()