Fix stove material matching for site bill

This commit is contained in:
anor
2026-11-26 21:23:03 +10:00
parent 68f9a77c03
commit dd93361276
3 changed files with 62 additions and 5 deletions
+10 -2
View File
@@ -68,6 +68,10 @@ def _reserve(key_id: int, budget: float, profile) -> int:
def _candidates(name: str, unit: str, region: str, zone: str | None) -> list[dict]:
found = fgis_ref.find_resource_price(query=name, region=region, zone=zone, limit=12)
return _candidate_rows(found, unit)
def _candidate_rows(found: dict, unit: str) -> list[dict]:
if found.get("status") == "db_unavailable":
raise MatchingUnavailable(30)
if found.get("status") != "ok" or found.get("multiple_zones"):
@@ -184,8 +188,12 @@ async def fill(prices: dict, *, key_id: int, budget: float, deadline: float, req
await asyncio.to_thread(stove_cache.match_delete, ck)
else:
continue
candidates = await asyncio.to_thread(_candidates, line["name"], line["unit"],
prices["region"], prices.get("zone"))
found = prices.get("search_results", {}).get(index)
if found is not None:
candidates = _candidate_rows(found, line["unit"])
else:
candidates = await asyncio.to_thread(_candidates, line["name"], line["unit"],
prices["region"], prices.get("zone"))
if candidates:
todo.append({"index": index, "line": line, "candidates": candidates, "cache_key": ck})
else: