statement_money вместо to_money в разборе строк форм, предупреждения о неразобранном формате и об xlsb, сравнение условий формата с точностью Excel (15 значащих цифр), тесты и тексты. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
2.3 KiB
Python
44 lines
2.3 KiB
Python
"""Значение ББ/ОФР из Excel — как его показывает числовой формат ячейки (#42): конкретные ячейки реальных выгрузок."""
|
||
|
||
from decimal import Decimal
|
||
from pathlib import Path
|
||
from typing import cast
|
||
|
||
import pytest
|
||
|
||
from src.contract import FileType, StatementDocument
|
||
from src.parser import get_parser
|
||
|
||
pytestmark = pytest.mark.fixtures
|
||
STATEMENTS = "statements-xlsx"
|
||
NPZ = "npz/2025-Q3/Бухгалтерская отчетность за Январь - Сентябрь 2025 г. (НОВОРОССИЙСКИЙ ПРОКАТНЫЙ ЗАВОД).xlsx"
|
||
UNAGRANDE_INCOME = "unagrande-group/2025-Q3/ОФР. Лист 1 3кв.25.xls"
|
||
MEZHENINOVSKAYA_BALANCE = "mezheninovskaya/2025-Q3/1_Форма1_бух_09.xlsx"
|
||
|
||
|
||
def _amount(fixtures_dir: Path, relative: str, document_type: str, code: str, column: int = 0) -> Decimal | None:
|
||
path = fixtures_dir / STATEMENTS / relative
|
||
outcome = get_parser().parse(path.read_bytes(), cast(FileType, path.suffix.lstrip(".").upper()))
|
||
assert outcome.error is None, outcome.error
|
||
for document in outcome.documents:
|
||
if isinstance(document, StatementDocument) and document.document_type == document_type:
|
||
for line in document.lines:
|
||
if line.line_code == code:
|
||
return line.values[column].amount
|
||
raise AssertionError(f"строка {code} не найдена")
|
||
|
||
|
||
def test_npz_scaling_comma_gives_thousands(fixtures_dir: Path) -> None:
|
||
"""P43: 10741981390 с форматом `#,##0,` показывается как 10 741 981 (тыс. руб.)."""
|
||
assert _amount(fixtures_dir, NPZ, "BALANCE", "1150") == Decimal("10741981")
|
||
|
||
|
||
def test_unagrande_conditional_literal_gives_negative_thousands(fixtures_dir: Path) -> None:
|
||
"""Значение -646532 с форматом `[=-646532]"(647)"` показывается текстом «(647)» -> -647."""
|
||
assert _amount(fixtures_dir, UNAGRANDE_INCOME, "INCOME", "2411") == Decimal("-647")
|
||
|
||
|
||
def test_mezheninovskaya_rounds_kopecks_to_displayed_integer(fixtures_dir: Path) -> None:
|
||
"""M31: 898852.21795 с форматом `#,##0` показывается как 898 852."""
|
||
assert _amount(fixtures_dir, MEZHENINOVSKAYA_BALANCE, "BALANCE", "1150") == Decimal("898852")
|