make pricedb currency mandatory

now, if there is a price entry for an ingredient, it either has to have a currency specified or default_currency has to be set in settings.yaml
This commit is contained in:
Emi Vasilek 2023-11-30 03:05:54 +00:00
parent 70432d867e
commit 7a9a39f2fb

View file

@ -564,7 +564,7 @@ class PriceDB(Element):
price: float, price: float,
amount: float, amount: float,
unit: Unit, unit: Unit,
currency: Optional[str], currency: str,
) -> None: ) -> None:
super().__init__(ctx) super().__init__(ctx)
self.price = price self.price = price
@ -591,4 +591,6 @@ class PriceDB(Element):
currency = ctx.settings.default_currency currency = ctx.settings.default_currency
if "currency" in dct: if "currency" in dct:
currency = dct["currency"] currency = dct["currency"]
if currency is None:
raise RuntimeError("currency not specified and default_currency is also not set")
return cls(ctx=ctx, price=price, amount=amount, unit=unit, currency=currency) return cls(ctx=ctx, price=price, amount=amount, unit=unit, currency=currency)