mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-07 15:18:20 -05:00
dont show properties if no reference amout is given
This commit is contained in:
@@ -42,13 +42,17 @@ class FoodPropertyHelper:
|
|||||||
conversions = uch.get_conversions(i)
|
conversions = uch.get_conversions(i)
|
||||||
for pt in property_types:
|
for pt in property_types:
|
||||||
found_property = False
|
found_property = False
|
||||||
for p in i.food.properties.all():
|
if i.food.properties_food_amount == 0 or i.food.properties_food_unit is None:
|
||||||
if p.property_type == pt:
|
computed_properties[pt.id]['missing_value'] = True
|
||||||
for c in conversions:
|
computed_properties[pt.id]['food_values'][i.food.id] = {'id': i.food.id, 'food': i.food.name, 'value': 0}
|
||||||
if c.unit == i.food.properties_food_unit:
|
else:
|
||||||
found_property = True
|
for p in i.food.properties.all():
|
||||||
computed_properties[pt.id]['total_value'] += (c.amount / i.food.properties_food_amount) * p.property_amount
|
if p.property_type == pt:
|
||||||
computed_properties[pt.id]['food_values'] = self.add_or_create(computed_properties[p.property_type.id]['food_values'], c.food.id, (c.amount / i.food.properties_food_amount) * p.property_amount, c.food)
|
for c in conversions:
|
||||||
|
if c.unit == i.food.properties_food_unit:
|
||||||
|
found_property = True
|
||||||
|
computed_properties[pt.id]['total_value'] += (c.amount / i.food.properties_food_amount) * p.property_amount
|
||||||
|
computed_properties[pt.id]['food_values'] = self.add_or_create(computed_properties[p.property_type.id]['food_values'], c.food.id, (c.amount / i.food.properties_food_amount) * p.property_amount, c.food)
|
||||||
if not found_property:
|
if not found_property:
|
||||||
computed_properties[pt.id]['missing_value'] = True
|
computed_properties[pt.id]['missing_value'] = True
|
||||||
computed_properties[pt.id]['food_values'][i.food.id] = {'id': i.food.id, 'food': i.food.name, 'value': 0}
|
computed_properties[pt.id]['food_values'][i.food.id] = {'id': i.food.id, 'food': i.food.name, 'value': 0}
|
||||||
|
|||||||
@@ -104,6 +104,17 @@ def test_food_property(space_1, space_2, u1_s1):
|
|||||||
assert abs(property_values[property_fat.id]['food_values'][food_1.id]['value'] - Decimal(250)) < 0.0001
|
assert abs(property_values[property_fat.id]['food_values'][food_1.id]['value'] - Decimal(250)) < 0.0001
|
||||||
assert abs(property_values[property_fat.id]['food_values'][food_2.id]['value'] - Decimal(250)) < 0.0001
|
assert abs(property_values[property_fat.id]['food_values'][food_2.id]['value'] - Decimal(250)) < 0.0001
|
||||||
|
|
||||||
|
print('\n----------- TEST PROPERTY - MISSING FOOD REFERENCE AMOUNT ---------------')
|
||||||
|
food_1.properties_food_unit = None
|
||||||
|
food_1.save()
|
||||||
|
food_2.properties_food_amount = 0
|
||||||
|
food_2.save()
|
||||||
|
|
||||||
|
property_values = FoodPropertyHelper(space_1).calculate_recipe_properties(recipe_1)
|
||||||
|
|
||||||
|
assert property_values[property_fat.id]['name'] == property_fat.name
|
||||||
|
assert property_values[property_fat.id]['total_value'] == 0
|
||||||
|
|
||||||
print('\n----------- TEST PROPERTY - SPACE SEPARATION ---------------')
|
print('\n----------- TEST PROPERTY - SPACE SEPARATION ---------------')
|
||||||
|
|
||||||
property_fat.space = space_2
|
property_fat.space = space_2
|
||||||
@@ -114,3 +125,5 @@ def test_food_property(space_1, space_2, u1_s1):
|
|||||||
property_values = FoodPropertyHelper(space_1).calculate_recipe_properties(recipe_2)
|
property_values = FoodPropertyHelper(space_1).calculate_recipe_properties(recipe_2)
|
||||||
|
|
||||||
assert property_fat.id not in property_values
|
assert property_fat.id not in property_values
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user