refactor: keep FSSP normalization within lint limits

This commit is contained in:
Aleksandr Meshchryakov
2026-10-05 15:22:14 +02:00
parent 92290511c2
commit b3b4e7691b

View File

@@ -42,7 +42,7 @@ def valid_legal_inn(value: str) -> bool:
return False
weights = (2, 4, 10, 3, 5, 9, 4, 6, 8)
return sum(
int(digit) * weight for digit, weight in zip(value, weights)
int(digit) * weight for digit, weight in zip(value, weights, strict=False)
) % 11 % 10 == int(value[-1])
@@ -99,6 +99,26 @@ def _termination(payload: dict, warnings: set[str]) -> None:
warnings.add("unparsed_termination")
def _balances(raw: dict, warnings: set[str]) -> tuple[Decimal | None, Decimal | None]:
debt = _money(raw.get("Debt remaining balance"), warnings, signed=True)
claim = _money(raw.get("Amount due"), warnings, signed=False)
if debt is not None and debt < 0:
warnings.add("negative_debt_balance")
if debt is not None and claim is not None and debt > claim:
warnings.add("debt_exceeds_claim_amount")
return debt, claim
def _dates(payload: dict, comparison_date: date, warnings: set[str]) -> None:
for field in ("initiated_on", "document_date"):
payload[field] = _date(payload[field], warnings)
if (
payload["document_date"]
and date.fromisoformat(payload["document_date"]) > comparison_date
):
warnings.add("future_document_date")
def iter_fssp_records(
handle: TextIO,
*,
@@ -126,24 +146,13 @@ def iter_fssp_records(
for row_number, values in enumerate(reader, 1):
if len(values) != len(headers):
raise SnapshotValidationError("invalid_fssp_csv_row_width")
raw = dict(zip(headers, values))
raw = dict(zip(headers, values, strict=True))
payload = {
field: raw[key].strip() or None for key, field in FSSP_HEADERS.items()
}
warnings: set[str] = set()
for field in ("initiated_on", "document_date"):
payload[field] = _date(payload[field], warnings)
if (
payload["document_date"]
and date.fromisoformat(payload["document_date"]) > comparison_date
):
warnings.add("future_document_date")
debt = _money(raw.get("Debt remaining balance"), warnings, signed=True)
claim = _money(raw.get("Amount due"), warnings, signed=False)
if debt is not None and debt < 0:
warnings.add("negative_debt_balance")
if debt is not None and claim is not None and debt > claim:
warnings.add("debt_exceeds_claim_amount")
_dates(payload, comparison_date, warnings)
debt, claim = _balances(raw, warnings)
payload.update(
{
"origin_kind": "open_data_csv",