Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto planner bug fix #2853

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cookbook/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ class AutoMealPlanSerializer(serializers.Serializer):
start_date = serializers.DateField()
end_date = serializers.DateField()
meal_type_id = serializers.IntegerField()
keywords = KeywordSerializer(many=True)
keyword_ids = serializers.ListField()
servings = CustomDecimalField()
shared = UserSerializer(many=True, required=False, allow_null=True)
addshopping = serializers.BooleanField()
Expand Down
6 changes: 3 additions & 3 deletions cookbook/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def create(self, request):
serializer = AutoMealPlanSerializer(data=request.data)

if serializer.is_valid():
keywords = serializer.validated_data['keywords']
keyword_ids = serializer.validated_data['keyword_ids']
start_date = serializer.validated_data['start_date']
end_date = serializer.validated_data['end_date']
servings = serializer.validated_data['servings']
Expand All @@ -753,8 +753,8 @@ def create(self, request):
recipes = Recipe.objects.values('id', 'name')
meal_plans = list()

for keyword in keywords:
recipes = recipes.filter(keywords__name=keyword['name'])
for keyword_id in keyword_ids:
recipes = recipes.filter(keywords__id=keyword_id)

if len(recipes) == 0:
return Response(serializer.data)
Expand Down
9 changes: 8 additions & 1 deletion vue/src/components/AutoMealPlanModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,18 @@ export default {

async autoPlanThread(autoPlan, mealTypeIndex) {
let apiClient = new ApiApiFactory()

let keyword_ids = []
for (const index in autoPlan.keywords[mealTypeIndex]){
let keyword = autoPlan.keywords[mealTypeIndex][index]
keyword_ids.push(keyword.id)
}

let data = {
"start_date": moment(autoPlan.startDay).format("YYYY-MM-DD"),
"end_date": moment(autoPlan.endDay).format("YYYY-MM-DD"),
"meal_type_id": autoPlan.meal_types[mealTypeIndex].id,
"keywords": autoPlan.keywords[mealTypeIndex],
"keyword_ids": keyword_ids,
"servings": autoPlan.servings,
"shared": autoPlan.shared,
"addshopping": autoPlan.addshopping
Expand Down
Loading