Added food api endpoints prep for mcp

This commit is contained in:
Joren de Graaf
2026-10-07 14:56:24 +02:00
parent 98f76918dc
commit 4f8c3272aa
22 changed files with 1093 additions and 115 deletions
+2 -13
View File
@@ -21,6 +21,7 @@ from .models import FoodFavourite, FoodLogEntry, FoodPortion, FoodProduct, MealT
from .services.diary import diary_context, selected_date
from .services.openfoodfacts import OpenFoodFactsError, cached_product, cached_search
from .services.products import local_products
from .services.logging import apply_product_snapshot
from planner.timezones import localdate_for_user
@@ -120,19 +121,7 @@ def _save_entry(form, user, day, product):
entry = form.save(commit=False)
entry.user = user
entry.date = day
entry.product = product
entry.product_name_snapshot = product.product_name
entry.brand_snapshot = product.brand
entry.barcode_snapshot = product.barcode
entry.source = product.source
factor = entry.amount / Decimal('100')
for source, target in (
('energy_kcal_100', 'calories_kcal'), ('carbohydrates_100', 'carbohydrates_g'),
('protein_100', 'protein_g'), ('fat_100', 'fat_g'), ('fibre_100', 'fibre_g'),
('sugars_100', 'sugars_g'), ('salt_100', 'salt_g'),
):
value = getattr(product, source)
setattr(entry, target, (value * factor).quantize(Decimal('0.001')) if value is not None else None)
apply_product_snapshot(entry, product)
entry.full_clean()
entry.save()
_save_custom_portion(form, user, product, entry)