Full sutartis port works
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from datetime import date
|
||||
from datetime import date, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Dict, Iterable, Optional
|
||||
|
||||
@@ -274,21 +274,17 @@ def _is_desired_state(
|
||||
) -> bool:
|
||||
if len(existing) != len(periods):
|
||||
return False
|
||||
existing_by_k0 = {str(r.get("N52_KODAS_K0") or "").strip(): r for r in existing}
|
||||
for idx, period in enumerate(periods, start=1):
|
||||
expected_k0 = f"{SERVICE_CODE}-{idx}"
|
||||
row = existing_by_k0.get(expected_k0)
|
||||
if not row:
|
||||
existing_keys = []
|
||||
for row in existing:
|
||||
start = row.get("N52_BEG_DATE")
|
||||
end = row.get("N52_END_DATE")
|
||||
if not start or not end:
|
||||
return False
|
||||
if str(row.get("N52_DOK_NR") or "").strip() != str(idx):
|
||||
return False
|
||||
if row.get("N52_BEG_DATE") != period["start"]:
|
||||
return False
|
||||
if row.get("N52_END_DATE") != period["end"]:
|
||||
return False
|
||||
if bool(row.get("N52_VISKAS")) != period["active"]:
|
||||
return False
|
||||
return True
|
||||
existing_keys.append((start, end))
|
||||
desired_keys = [(p["start"], p["end"]) for p in periods]
|
||||
existing_keys.sort()
|
||||
desired_keys.sort()
|
||||
return existing_keys == desired_keys
|
||||
|
||||
|
||||
def _normalize_date(value: Optional[date]) -> date:
|
||||
@@ -317,7 +313,7 @@ def _build_periods(rows: list[dict[str, object]]) -> list[dict[str, object]]:
|
||||
end_date = OPEN_END_DATE
|
||||
else:
|
||||
next_start = normalized[idx + 1]["start"]
|
||||
end_date = next_start - date.resolution
|
||||
end_date = next_start - timedelta(days=1)
|
||||
bukle = item["bukle"]
|
||||
active = bukle in {2, 3}
|
||||
periods.append(
|
||||
|
||||
Reference in New Issue
Block a user