small cleanup

This commit is contained in:
Emi Vasilek 2023-11-06 23:38:52 +01:00
parent 9264bba243
commit 009a556c32

View file

@ -101,7 +101,7 @@ class Units:
for unit in self.units:
if unit["name"] == name or "aliases" in unit and name in unit["aliases"]:
return unit
raise RuntimeError(f"unit {name} not found")
return None
class Ingredient(Element):
@ -133,7 +133,7 @@ class Ingredients:
for ing in self.ingredients:
if ing["name"] == name or "aliases" in ing and name in ing["aliases"]:
return ing
raise RuntimeError(f"ingredient {name} not found")
return None
class PriceDBs:
@ -154,28 +154,28 @@ class PriceDB(Element):
self["amount"] = 1.0
if "unit" in dct:
try:
self["unit"] = self.ctx.units.get(dct["unit"])
except RuntimeError as e:
self.ctx.issues.append(str(e))
unitstr = dct["unit"]
self["unit"] = self.ctx.units.get(unitstr)
if self["unit"] == None:
self.ctx.issues.append(f"unknown unit {unitstr}")
else:
self["unit"] = None
class IngredientInstance(Element):
def load(self, dct: Dict[str, Any]) -> None:
try:
self["ingredient"] = self.ctx.ingredients.get(dct["name"])
except RuntimeError as e:
self.ctx.issues.append(str(e))
self["ingredient"] = self.ctx.ingredients.get(dct["name"])
if self["ingredient"] == None:
self.ctx.issues.append(f"unknown ingredient {dct['name']}")
if "amount" not in dct:
self["amount"] = 1.0
if "unit" in dct:
try:
self["unit"] = self.ctx.units.get(dct["unit"])
except RuntimeError as e:
self.ctx.issues.append(str(e))
unitstr = dct["unit"]
self["unit"] = self.ctx.units.get(unitstr)
if self["unit"] == None:
self.ctx.issues.append("unknown unit {unitstr}")
else:
self["unit"] = None