refactor: keep FSSP normalization within lint limits
This commit is contained in:
@@ -42,7 +42,7 @@ def valid_legal_inn(value: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
weights = (2, 4, 10, 3, 5, 9, 4, 6, 8)
|
weights = (2, 4, 10, 3, 5, 9, 4, 6, 8)
|
||||||
return sum(
|
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])
|
) % 11 % 10 == int(value[-1])
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +99,26 @@ def _termination(payload: dict, warnings: set[str]) -> None:
|
|||||||
warnings.add("unparsed_termination")
|
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(
|
def iter_fssp_records(
|
||||||
handle: TextIO,
|
handle: TextIO,
|
||||||
*,
|
*,
|
||||||
@@ -126,24 +146,13 @@ def iter_fssp_records(
|
|||||||
for row_number, values in enumerate(reader, 1):
|
for row_number, values in enumerate(reader, 1):
|
||||||
if len(values) != len(headers):
|
if len(values) != len(headers):
|
||||||
raise SnapshotValidationError("invalid_fssp_csv_row_width")
|
raise SnapshotValidationError("invalid_fssp_csv_row_width")
|
||||||
raw = dict(zip(headers, values))
|
raw = dict(zip(headers, values, strict=True))
|
||||||
payload = {
|
payload = {
|
||||||
field: raw[key].strip() or None for key, field in FSSP_HEADERS.items()
|
field: raw[key].strip() or None for key, field in FSSP_HEADERS.items()
|
||||||
}
|
}
|
||||||
warnings: set[str] = set()
|
warnings: set[str] = set()
|
||||||
for field in ("initiated_on", "document_date"):
|
_dates(payload, comparison_date, warnings)
|
||||||
payload[field] = _date(payload[field], warnings)
|
debt, claim = _balances(raw, 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")
|
|
||||||
payload.update(
|
payload.update(
|
||||||
{
|
{
|
||||||
"origin_kind": "open_data_csv",
|
"origin_kind": "open_data_csv",
|
||||||
|
|||||||
Reference in New Issue
Block a user