支持供应商简称与企业全称双向匹配
This commit is contained in:
parent
b7a79f1791
commit
a7f4fef025
@ -142,8 +142,6 @@ class SupplierProfileService:
|
||||
)
|
||||
.group_by(AnomalyCase.supplier, AnomalyCase.defect_level)
|
||||
)
|
||||
if keyword and keyword.strip():
|
||||
statement = statement.where(AnomalyCase.supplier.ilike(f"%{keyword.strip()}%"))
|
||||
grouped: dict[str, dict[str, int]] = defaultdict(
|
||||
lambda: {"total": 0, "a": 0, "b": 0}
|
||||
)
|
||||
@ -151,6 +149,8 @@ class SupplierProfileService:
|
||||
name = (supplier or "").strip()
|
||||
if not name:
|
||||
continue
|
||||
if keyword and not self.matches(name, keyword):
|
||||
continue
|
||||
value = grouped[name]
|
||||
amount = int(count or 0)
|
||||
value["total"] += amount
|
||||
@ -184,7 +184,11 @@ class SupplierProfileService:
|
||||
|
||||
@staticmethod
|
||||
def matches(value: str | None, target: str) -> bool:
|
||||
return bool(value and target.strip().lower() in value.lower())
|
||||
if not value:
|
||||
return False
|
||||
source = "".join(value.casefold().split())
|
||||
query = "".join(target.casefold().split())
|
||||
return bool(query and (query in source or source in query))
|
||||
|
||||
@classmethod
|
||||
def _group_suppliers(cls, rows: list[dict], keyword: str | None) -> dict[str, list[dict]]:
|
||||
|
||||
@ -14,6 +14,11 @@ def test_supplier_tier_rules_follow_prd() -> None:
|
||||
assert SupplierProfileService.tier_for(121, 0, 0) == "C级"
|
||||
|
||||
|
||||
def test_supplier_name_matching_supports_full_name_and_short_name() -> None:
|
||||
assert SupplierProfileService.matches("佳亿", "佛山市佳亿包装有限公司")
|
||||
assert SupplierProfileService.matches("佛山市佳亿包装有限公司", "佳亿")
|
||||
|
||||
|
||||
def test_supplier_alpha_is_capped_and_rounded() -> None:
|
||||
assert SupplierProfileService.alpha(0) == 1.0
|
||||
assert SupplierProfileService.alpha(42) == 1.13
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user