test rest food inheritance
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -84,4 +84,3 @@ cookbook/static/vue
|
|||||||
vue/webpack-stats.json
|
vue/webpack-stats.json
|
||||||
cookbook/templates/sw.js
|
cookbook/templates/sw.js
|
||||||
.prettierignore
|
.prettierignore
|
||||||
vue/tsconfig.json
|
|
||||||
|
@ -85,12 +85,12 @@ def list_from_recipe(list_recipe=None, recipe=None, mealplan=None, servings=None
|
|||||||
ingredients = ingredients.exclude(food__on_hand=True)
|
ingredients = ingredients.exclude(food__on_hand=True)
|
||||||
|
|
||||||
if related := created_by.userpreference.mealplan_autoinclude_related:
|
if related := created_by.userpreference.mealplan_autoinclude_related:
|
||||||
# TODO: add levels of related recipes to use when auto-adding mealplans
|
# TODO: add levels of related recipes (related recipes of related recipes) to use when auto-adding mealplans
|
||||||
related_recipes = r.get_related_recipes()
|
related_recipes = r.get_related_recipes()
|
||||||
|
|
||||||
for x in related_recipes:
|
for x in related_recipes:
|
||||||
# related recipe is a Step serving size is driven by recipe serving size
|
# related recipe is a Step serving size is driven by recipe serving size
|
||||||
# TODO once Steps can have a serving size this needs to be refactored
|
# TODO once/if Steps can have a serving size this needs to be refactored
|
||||||
if exclude_onhand:
|
if exclude_onhand:
|
||||||
# if steps are used more than once in a recipe or subrecipe - I don' think this results in the desired behavior
|
# if steps are used more than once in a recipe or subrecipe - I don' think this results in the desired behavior
|
||||||
related_step_ing += Ingredient.objects.filter(step__recipe=x, food__on_hand=False, space=space).values_list('id', flat=True)
|
related_step_ing += Ingredient.objects.filter(step__recipe=x, food__on_hand=False, space=space).values_list('id', flat=True)
|
||||||
|
@ -491,11 +491,11 @@ class Food(ExportModelOperationsMixin('food'), TreeModel, PermissionModelMixin):
|
|||||||
name = models.CharField(max_length=128, validators=[MinLengthValidator(1)])
|
name = models.CharField(max_length=128, validators=[MinLengthValidator(1)])
|
||||||
recipe = models.ForeignKey('Recipe', null=True, blank=True, on_delete=models.SET_NULL)
|
recipe = models.ForeignKey('Recipe', null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
supermarket_category = models.ForeignKey(SupermarketCategory, null=True, blank=True, on_delete=models.SET_NULL)
|
supermarket_category = models.ForeignKey(SupermarketCategory, null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
ignore_shopping = models.BooleanField(default=False)
|
ignore_shopping = models.BooleanField(default=False) # inherited field
|
||||||
description = models.TextField(default='', blank=True)
|
description = models.TextField(default='', blank=True)
|
||||||
on_hand = models.BooleanField(default=False)
|
on_hand = models.BooleanField(default=False)
|
||||||
inherit = models.BooleanField(default=False)
|
inherit = models.BooleanField(default=False)
|
||||||
ignore_inherit = models.ManyToManyField(FoodInheritField, blank=True) # is this better as inherit instead of ignore inherit? which is more intuitive?
|
ignore_inherit = models.ManyToManyField(FoodInheritField, blank=True) # inherited field: is this name better as inherit instead of ignore inherit? which is more intuitive?
|
||||||
|
|
||||||
space = models.ForeignKey(Space, on_delete=models.CASCADE)
|
space = models.ForeignKey(Space, on_delete=models.CASCADE)
|
||||||
objects = ScopedManager(space='space', _manager_class=TreeManager)
|
objects = ScopedManager(space='space', _manager_class=TreeManager)
|
||||||
@ -511,6 +511,7 @@ class Food(ExportModelOperationsMixin('food'), TreeModel, PermissionModelMixin):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reset_inheritance(space=None):
|
def reset_inheritance(space=None):
|
||||||
|
# resets inheritted fields to the space defaults and updates all inheritted fields to root object values
|
||||||
inherit = space.food_inherit.all()
|
inherit = space.food_inherit.all()
|
||||||
ignore_inherit = Food.inherit_fields.difference(inherit)
|
ignore_inherit = Food.inherit_fields.difference(inherit)
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
edit_mode: false,
|
edit_mode: false,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
export_text_prefix: '', //TODO add userpreference
|
export_text_prefix: '',
|
||||||
recipe_query: '',
|
recipe_query: '',
|
||||||
recipes: [],
|
recipes: [],
|
||||||
shopping_list: undefined,
|
shopping_list: undefined,
|
||||||
|
@ -526,4 +526,24 @@ def test_ignoreinherit_field(request, obj_tree_1, field, inherit, new_val, u1_s1
|
|||||||
assert getattr(child, field) == new_val
|
assert getattr(child, field) == new_val
|
||||||
|
|
||||||
|
|
||||||
# TODO test reset_inheritance
|
@pytest.mark.parametrize("obj_tree_1", [
|
||||||
|
({'has_category': True, 'inherit': False, 'ignore_shopping': True}),
|
||||||
|
], indirect=['obj_tree_1'])
|
||||||
|
def test_reset_inherit(obj_tree_1, space_1):
|
||||||
|
with scope(space=space_1):
|
||||||
|
space_1.food_inherit.add(*Food.inherit_fields.values_list('id', flat=True)) # set default inherit fields
|
||||||
|
parent = obj_tree_1.get_parent()
|
||||||
|
child = obj_tree_1.get_descendants()[0]
|
||||||
|
obj_tree_1.ignore_shopping = False
|
||||||
|
assert parent.ignore_shopping == child.ignore_shopping
|
||||||
|
assert parent.ignore_shopping != obj_tree_1.ignore_shopping
|
||||||
|
assert parent.supermarket_category != child.supermarket_category
|
||||||
|
assert parent.supermarket_category != obj_tree_1.supermarket_category
|
||||||
|
|
||||||
|
parent.reset_inheritance(space=space_1)
|
||||||
|
# djangotree bypasses ORM and need to be retrieved again
|
||||||
|
obj_tree_1 = Food.objects.get(id=obj_tree_1.id)
|
||||||
|
parent = obj_tree_1.get_parent()
|
||||||
|
child = obj_tree_1.get_descendants()[0]
|
||||||
|
assert parent.ignore_shopping == obj_tree_1.ignore_shopping == child.ignore_shopping
|
||||||
|
assert parent.supermarket_category == obj_tree_1.supermarket_category == child.supermarket_category
|
||||||
|
@ -222,7 +222,3 @@ def test_shopping_recipe_mixed_authors(u1_s1, u2_s1):
|
|||||||
u1_s1.put(reverse(SHOPPING_RECIPE_URL, args={recipe1.id}))
|
u1_s1.put(reverse(SHOPPING_RECIPE_URL, args={recipe1.id}))
|
||||||
assert len(json.loads(u1_s1.get(reverse(SHOPPING_LIST_URL)).content)) == 29
|
assert len(json.loads(u1_s1.get(reverse(SHOPPING_LIST_URL)).content)) == 29
|
||||||
assert len(json.loads(u2_s1.get(reverse(SHOPPING_LIST_URL)).content)) == 0
|
assert len(json.loads(u2_s1.get(reverse(SHOPPING_LIST_URL)).content)) == 0
|
||||||
|
|
||||||
|
|
||||||
# TODO test creating shopping list from recipe that includes recipes from multiple users
|
|
||||||
# TODO meal plan recipe with all the user preferences tested
|
|
||||||
|
Reference in New Issue
Block a user