From e1029cdca30e943e63b708b2c9497557469c5f4a Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 18 Nov 2026 04:40:20 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D0=A2=D0=A1=D0=9D):=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B1=D0=B0=D0=B7=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D0=B2=20=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BE=D1=87=D0=BD=D0=B8=D0=BA=D0=B5=20=D0=BC=D0=B0=D1=88=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=BE=D0=B1=D1=8A=D1=8F=D1=81=D0=BD=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D1=87=D0=B8=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Тридцать из тридцати девяти карантинных строк .2 — раздел «Стоимость перебазировки»: там рубли за перевозку машины, а не цена машино-часа. Брать их за цену ресурса нельзя, и теперь причина карантина это говорит, а не «цена не найдена». Co-Authored-By: Claude Code --- tests/test_tsn_price_book.py | 8 ++++++++ tsn_parse.py | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/test_tsn_price_book.py b/tests/test_tsn_price_book.py index 3e6ad22..7370ce3 100644 --- a/tests/test_tsn_price_book.py +++ b/tests/test_tsn_price_book.py @@ -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("Сметные цены эксплуатации машин") == "цена не найдена" diff --git a/tsn_parse.py b/tsn_parse.py index 000964a..50902cf 100644 --- a/tsn_parse.py +++ b/tsn_parse.py @@ -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()