Fix inherited contract handling and document smoke test blockers
This commit is contained in:
1 parent
0be2646952
commit
418d8336f5
4 files changed
+258
-210
No files matched your search
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import unicodedata
|
||||
from typing import Any
|
||||
|
||||
from .errors import ValidationError
|
||||
@@ -21,7 +22,30 @@ def calculate_foerderquote_percent(allocation: AllocationRecord, precision: int
|
||||
|
||||
def _normalize_name(name: str) -> str:
|
||||
compact = re.sub(r"\s+", " ", name.strip())
|
||||
return compact.casefold()
|
||||
no_accents = "".join(
|
||||
ch for ch in unicodedata.normalize("NFKD", compact) if not unicodedata.combining(ch)
|
||||
)
|
||||
return no_accents.casefold()
|
||||
|
||||
|
||||
def _name_keys(name: str) -> set[str]:
|
||||
normalized = _normalize_name(name)
|
||||
keys = {normalized}
|
||||
|
||||
if "," in normalized:
|
||||
last_name, first_name = [part.strip() for part in normalized.split(",", 1)]
|
||||
if first_name and last_name:
|
||||
keys.add(f"{first_name} {last_name}")
|
||||
keys.add(f"{last_name}, {first_name}")
|
||||
else:
|
||||
tokens = normalized.split()
|
||||
if len(tokens) >= 2:
|
||||
first_name = tokens[0]
|
||||
last_name = tokens[-1]
|
||||
keys.add(f"{first_name} {last_name}")
|
||||
keys.add(f"{last_name}, {first_name}")
|
||||
|
||||
return {re.sub(r"\s+", " ", key).strip() for key in keys if key.strip()}
|
||||
|
||||
|
||||
def _with_tolerance(
|
||||
@@ -43,14 +67,19 @@ def match_assignments(
|
||||
|
||||
master_by_name: dict[str, list[MasterDataRecord]] = {}
|
||||
for record in masterdata_records:
|
||||
master_by_name.setdefault(_normalize_name(record.name), []).append(record)
|
||||
for key in _name_keys(record.name):
|
||||
master_by_name.setdefault(key, []).append(record)
|
||||
|
||||
matched: list[MatchedAssignment] = []
|
||||
issues: list[ValidationIssue] = []
|
||||
|
||||
for allocation in allocation_records:
|
||||
normalized_name = _normalize_name(allocation.employee_name)
|
||||
candidates = master_by_name.get(normalized_name, [])
|
||||
candidate_map: dict[str, MasterDataRecord] = {}
|
||||
for key in _name_keys(allocation.employee_name):
|
||||
for candidate in master_by_name.get(key, []):
|
||||
candidate_map[candidate.record_id] = candidate
|
||||
|
||||
candidates = list(candidate_map.values())
|
||||
if not candidates:
|
||||
issues.append(
|
||||
ValidationIssue(
|
||||
|
||||
Reference in new issue
Block a user