|
@@ -290,11 +290,13 @@ class RecipeEditor(FocusWidget):
|
|
|
data = self.data
|
|
|
organic = None if data['organic'] == 'mixed' else data['organic']
|
|
|
sort = 'ts'
|
|
|
+ notice = ''
|
|
|
for r in filter(
|
|
|
lambda x: next(filter(lambda x: x is widget or widget is None, x), None),
|
|
|
self.ingredients
|
|
|
):
|
|
|
product, quantity, unit = map(lambda x: x.get_edit_text(), r)
|
|
|
+ self.found[product] = '='
|
|
|
|
|
|
try:
|
|
|
quantity = Decimal(quantity)
|
|
@@ -304,18 +306,37 @@ class RecipeEditor(FocusWidget):
|
|
|
if (product or None, unit or None, quantity or None) == (None, None, None):
|
|
|
continue
|
|
|
|
|
|
+
|
|
|
if None in (sort or None, product or None, unit or None, quantity or None):
|
|
|
- self.found[None] = '>'
|
|
|
continue
|
|
|
- self.found[product] = '='
|
|
|
|
|
|
df = self.query_manager.get_historic_prices_data(unit, sort=sort, product=product, organic=organic)
|
|
|
- if df.empty:
|
|
|
+ if not df.empty:
|
|
|
+ distinct = df['quantity'].unique()
|
|
|
+ if len(distinct) == 1 and None in distinct:
|
|
|
+ notice += f"Product '{product}' has no conversion to '{unit}'\n"
|
|
|
+ self.found[product] = '>'
|
|
|
+ continue
|
|
|
+ df = df.dropna()
|
|
|
+
|
|
|
+ else:
|
|
|
+ if organic is None:
|
|
|
+ notice += f"Product '{product}' not found in database\n"
|
|
|
+ continue
|
|
|
+
|
|
|
self.found[product] = '~'
|
|
|
+ notice += f"Product '{product} (organic={organic})' not found in database\n"
|
|
|
df = self.query_manager.get_historic_prices_data(unit, sort=sort, product=product, organic=None)
|
|
|
if df.empty:
|
|
|
self.found[product] = '>'
|
|
|
+ notice += f"Product '{product}' not found in database\n"
|
|
|
continue
|
|
|
+ distinct = df['quantity'].unique()
|
|
|
+ if len(distinct) == 1 and None in distinct:
|
|
|
+ notice += f"Product '{product}' has no conversion to '{unit}'\n"
|
|
|
+ self.found[product] = '>'
|
|
|
+ continue
|
|
|
+ df = df.dropna()
|
|
|
|
|
|
assert len(df['avg'].unique()) == 1, f"There should be only one average price: {df['avg'].unique()}"
|
|
|
|
|
@@ -332,7 +353,7 @@ class RecipeEditor(FocusWidget):
|
|
|
for k in list(self.found):
|
|
|
if k not in [
|
|
|
*map(lambda x: x[0].get_edit_text(), self.ingredients),
|
|
|
- None
|
|
|
+ ''
|
|
|
]:
|
|
|
del self.found[k]
|
|
|
|
|
@@ -346,7 +367,8 @@ class RecipeEditor(FocusWidget):
|
|
|
not_found = next(
|
|
|
filter(lambda x: x == '>', self.found.values()), next(
|
|
|
filter(lambda x: x == '~', self.found.values()), next(
|
|
|
- filter(lambda x: x == '=', self.found.values())
|
|
|
+ filter(lambda x: x == '=', self.found.values()),
|
|
|
+ None,
|
|
|
)
|
|
|
)
|
|
|
)
|
|
@@ -354,7 +376,6 @@ class RecipeEditor(FocusWidget):
|
|
|
f'Cost: {not_found}{price[price_as]}'
|
|
|
f', Per Serve: {not_found}{price[price_as]/self.feeds}'
|
|
|
)
|
|
|
- notice = ''
|
|
|
ingredients = list(filter(lambda x: x, map(lambda x: x[0].get_edit_text(), self.ingredients)))
|
|
|
parsed_products = list(get_products_from_xhtml(markdown(self.instructions.get_edit_text())))
|
|
|
fname = self.fname.get_edit_text()
|
|
@@ -366,9 +387,9 @@ class RecipeEditor(FocusWidget):
|
|
|
return self
|
|
|
products = set(parsed_products)
|
|
|
for product in products - set(ingredients):
|
|
|
- notice += f"Product '{product}' not found in list of ingredients\n";
|
|
|
+ notice += f"Product '{product}' not found in list of ingredients\n"
|
|
|
for ingredient in set(ingredients) - products:
|
|
|
- notice += f"Ingredient '{ingredient}' is not used\n";
|
|
|
+ notice += f"Ingredient '{ingredient}' is not used\n"
|
|
|
if len(set(ingredients)) != len(ingredients):
|
|
|
notice += f"Some ingredients listed more than once\n"
|
|
|
|