show full recipe price every time with a clarification if necessary

This commit is contained in:
Emi Vasilek 2024-05-12 22:18:45 +00:00
parent 8046f0d237
commit 88f801cadb
4 changed files with 40 additions and 7 deletions

View file

@ -289,7 +289,7 @@ class Recipe(Element):
source: Optional[SafeHTML],
ingredients: List[IngredientInstance],
subrecipes: List["Recipe"],
price: Optional["PriceDB"],
price: Optional["MultiPriceDB"],
stepsections: List[StepSection],
) -> None:
super().__init__(ctx)
@ -317,7 +317,7 @@ class Recipe(Element):
rp = Recipe.from_dict(ctx, partdct)
subrecipes.append(rp)
price: Optional[PriceDB] = None
price: Optional[MultiPriceDB] = None
pricex: float = 0
ingswithprice = 0
ingswithoutprice = 0
@ -335,16 +335,22 @@ class Recipe(Element):
# we don't know how to convert currencies yet
currency = None
break
if currency is None or ingswithoutprice != 0 or len(ingredients) == 0:
if currency is None or len(ingredients) == 0:
price = None
else:
price = PriceDB(
pricedb = PriceDB(
ctx=ctx,
price=pricex,
amount=1,
unit=ctx.default_unit,
currency=currency,
)
price = MultiPriceDB(
ctx=ctx,
pricedb=pricedb,
item_count=len(ingredients),
item_prices_missing=ingswithoutprice,
)
stepsections: List[StepSection] = []
if "steps" in dct:
@ -594,3 +600,16 @@ class PriceDB(Element):
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)
class MultiPriceDB(Element):
def __init__(
self,
ctx: Context,
pricedb: PriceDB,
item_count: int,
item_prices_missing: int,
) -> None:
super().__init__(ctx)
self.pricedb = pricedb
self.item_count = item_count
self.item_prices_missing = item_prices_missing