Refactor transport calculation into shared domain
This commit is contained in:
@@ -301,6 +301,28 @@ class ArticleRepository:
|
||||
}
|
||||
|
||||
|
||||
def get_article(
|
||||
article_number: str | None = None,
|
||||
article_name_hint: str | None = None,
|
||||
*,
|
||||
article_repository: ArticleRepository | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Resolve one article through the canonical article repository."""
|
||||
for field, value in (
|
||||
("article_number", article_number),
|
||||
("article_name_hint", article_name_hint),
|
||||
):
|
||||
if value is not None and not isinstance(value, str):
|
||||
return {
|
||||
"status": "invalid_parameter",
|
||||
"invalid": [{"field": field, "message": f"{field} must be text"}],
|
||||
}
|
||||
article_number = article_number.strip() if article_number else None
|
||||
article_name_hint = article_name_hint.strip() if article_name_hint else None
|
||||
repository = article_repository or ArticleRepository.load()
|
||||
return repository.resolve(article_number, article_name_hint)
|
||||
|
||||
|
||||
def _canonical_name(value: str) -> str:
|
||||
value = value.casefold().replace("×", " x ")
|
||||
tokens = re.findall(r"\d+(?:[.,]\d+)?|[^\W\d_]+", value)
|
||||
|
||||
Reference in New Issue
Block a user