feat(statements): парсер ББ и ОФР из Excel, контракт v1.2 (Срез 2b) #16

Merged
aep merged 43 commits from feat/14-slice-2b-statement-parser into main 2026-10-06 21:38:00 +03:00
2 changed files with 63 additions and 3 deletions
Showing only changes of commit b50ac38a73 - Show all commits

View File

@ -114,7 +114,7 @@ def _units(sheet: Sheet, rules: Rules, first_row: int, last_row: int) -> str | N
def _report_date(
sheet: Sheet, rules: Rules, block: FormBlock, first_row: int, last_row: int
) -> tuple[str | None, "datetime.date | None"]:
) -> tuple[str | None, datetime.date | None]:
periods = rules.statement_periods
if block.title_row is not None and block.title_row + 1 <= last_row:
# Подзаголовок — только следующая строка за заголовком формы

View File

@ -7,7 +7,7 @@ from gridbuilder import at, sheet_from_rows
from src.parser.rules import Rules, load_rules
from src.parser.statements.detect import find_forms
from src.parser.statements.header import _FULL_CONFIDENCE, parse_header
from src.parser.statements.header import parse_header
@pytest.fixture(scope="module")
@ -63,7 +63,7 @@ def test_one_c_header(rules: Rules) -> None:
assert header.units == "в тыс. рублей"
assert header.report_date_text == "на 31 декабря 2024 г." and header.report_date == datetime.date(2024, 12, 31)
assert header.address == "242440, Брянская обл, г Севск, ул Ленина, д. 130"
assert header.organization_name_confidence == _FULL_CONFIDENCE and header.inn_confidence == _FULL_CONFIDENCE
assert header.organization_name_confidence == 100 and header.inn_confidence == 100 # noqa: PLR2004
assert warnings == []
@ -163,3 +163,63 @@ def test_inn_skips_auditor_block(rules: Rules) -> None:
header, _ = parse_header(sheet, rules, 1, 16, _block(sheet, rules))
assert header.inn == "3249004697", f"Expected organization INN 3249004697, got {header.inn}"
assert header.inn != "7716021332", "Auditor INN 7716021332 should not be included"
def test_inn_from_auditor_block_only_is_none(rules: Rules) -> None:
"""Guard test (a): without org INN, only auditor block ИНН — should be None."""
sheet = sheet_from_rows(
[
[*at({3: "Отчет о финансовых результатах"})],
[*at({3: "за январь - сентябрь 2025 г."})],
[*at({13: "Форма по ОКУД", 14: "0710002"})],
[*at({7: 'ООО "ПРОКАТНЫЙ ЗАВОД"'})],
[*at({3: "Организация:", 13: "по ОКПО", 14: "16098811"})],
[*at({3: "Единица измерения", 8: "тыс. руб.", 13: "по ОКЕИ", 14: "384"})],
[*at({2: "Наименование аудиторской организации"})],
[*at({2: 'АО "АУДИТ-КОМПАНИЯ"'})],
[
*at({
2: "Идентификационный номер налогоплательщика аудиторской организации",
33: "ИНН",
34: "9999999999",
})
],
]
)
header, _ = parse_header(sheet, rules, 1, 9, _block(sheet, rules))
assert header.inn is None, f"Should not pick up auditor INN 9999999999, got {header.inn}"
def test_inn_from_auditor_above_organization_inn_line(rules: Rules) -> None:
"""Guard test (b): org INN before auditor block; guard excludes auditor INN.
Organization section (rows 1-4) has INN 1234567890.
Auditor block starts at row 5 and has INN 7716021332.
Guard searches up to row 4, finds org INN.
"""
sheet = sheet_from_rows(
[
[*at({3: "Бухгалтерский баланс"})],
[*at({3: "на 31 декабря 2024 г."})],
[*at({7: 'ООО "ЗАВОД"'})],
[*at({2: "Идентификационный номер налогоплательщика", 33: "ИНН", 34: "1234567890"})],
[*at({2: "Наименование аудиторской организации"})],
[*at({2: 'АО "ЮНИКОН"'})],
[
*at({
2: "Идентификационный номер налогоплательщика аудиторской организации",
33: "ИНН",
34: "7716021332",
})
],
[*at({2: "Единица измерения", 7: "в тыс. рублей", 33: "по ОКЕИ", 34: "384"})],
]
)
header, _ = parse_header(sheet, rules, 1, 8, _block(sheet, rules))
assert (
header.inn == "1234567890"
), f"Should pick organization INN 1234567890, not auditor INN 7716021332, got {header.inn}"