108 lines
4.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Шапка-ячейки формы на словарях `arm_statements` (план 4, задача 4)."""
import pytest
from gridbuilder import at, sheet_from_rows
from arm_statements import default_rules, parse_header
from src.parser.statements.forms import StatementRules, find_blocks
from src.parser.statements.header_cells import header_cells
@pytest.fixture(scope="module")
def rules() -> StatementRules:
return default_rules()
def _cells(rows: list[list[object]], rules: StatementRules, name: str = "Баланс"): # noqa: ANN202
sheet = sheet_from_rows(rows, name=name)
[block] = find_blocks(sheet, rules)
return header_cells(sheet, rules, block, block.last_row, set())
def test_header_cells_of_1c_block(rules: StatementRules) -> None:
cells, evidence = _cells(
[
[*at({3: "Бухгалтерский баланс"})],
[*at({3: "на 30 сентября 2025 г."})],
[*at({5: "Форма по ОКУД", 6: "0710001"})],
[*at({3: "Организация", 4: "АО «Пример»", 5: "по ОКПО", 6: "12345678"})],
[*at({3: "ИНН", 4: "7700000000"})],
[*at({3: "Организационно-правовая форма", 5: "по ОКОПФ / ОКФС", 6: "12267", 7: "16"})],
[*at({3: "Единица измерения:", 4: "в тыс. рублей", 5: "по ОКЕИ", 6: "384"})],
],
rules,
)
assert cells.organization_name is not None
assert cells.organization_name.text == "АО «Пример»"
assert cells.inn is not None
assert cells.inn.ref == "Баланс!D5"
assert cells.okopf is not None
assert cells.okfs is not None
assert (cells.okopf.text, cells.okfs.text) == ("12267", "16")
assert cells.report_date is not None
assert cells.report_date.text == "на 30 сентября 2025 г."
assert evidence.okud is not None
assert evidence.title is not None
assert (evidence.okud.text, evidence.title.text) == ("0710001", "Бухгалтерский баланс")
head = parse_header(cells, rules)
assert head.units.value == "тыс. руб."
assert str(head.report_date.value) == "2025-09-30"
def test_auditor_inn_is_not_taken(rules: StatementRules) -> None:
cells, _ = _cells(
[
["Бухгалтерский баланс"],
[*at({1: "Организация", 2: "ООО «Пример»"})],
[*at({1: "ИНН", 2: "7700000000"})],
[*at({1: "Аудитор"})],
[*at({1: "ИНН", 2: "7811111111"})],
],
rules,
)
assert cells.inn is not None
assert cells.inn.text == "7700000000"
def test_auditor_inn_alone_gives_none(rules: StatementRules) -> None:
cells, _ = _cells([["Бухгалтерский баланс"], ["Аудитор"], ["ИНН", "7811111111"]], rules)
assert cells.inn is None
def test_organization_by_legal_form_above_label(rules: StatementRules) -> None:
cells, _ = _cells(
[
["Бухгалтерский баланс"],
['ООО "НПЗ"'],
[*at({1: "Организация", 3: "по ОКПО", 4: "16098811"})],
],
rules,
)
assert cells.organization_name is not None
assert cells.organization_name.text == 'ООО "НПЗ"'
def test_report_date_from_triple(rules: StatementRules) -> None:
numeric, _ = _cells(
[["Бухгалтерский баланс"], [*at({1: "Дата (число, месяц, год)", 2: "30", 3: "09", 4: "2025"})]], rules
)
assert numeric.report_date is not None
assert numeric.report_date.text == "30.09.2025"
assert numeric.report_date.ref == "Баланс!B2"
worded, _ = _cells(
[["Бухгалтерский баланс"], [*at({1: "Дата (число, месяц, год)", 2: "30", 3: "сентября", 4: "2025"})]], rules
)
assert worded.report_date is not None
assert worded.report_date.text == "30 сентября 2025"
for cells in (numeric, worded):
assert str(parse_header(cells, rules).report_date.value) == "2025-09-30"
def test_units_only_by_okei(rules: StatementRules) -> None:
cells, _ = _cells([["Бухгалтерский баланс"], [*at({1: "по ОКЕИ", 2: "384"})]], rules)
assert cells.units is None
assert cells.okei is not None
assert cells.okei.text == "384"
head = parse_header(cells, rules)
assert (head.units.value, head.okei.value) == ("тыс. руб.", "384")