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()