diff --git a/apps/food/forms.py b/apps/food/forms.py index e8601306..0b2532aa 100644 --- a/apps/food/forms.py +++ b/apps/food/forms.py @@ -11,7 +11,7 @@ from note_kfet.inputs import Autocomplete, DateTimePickerInput from note_kfet.middlewares import get_current_request from permission.backends import PermissionBackend -from .models import BasicFood, QRCode, TransformedFood, Food +from .models import BasicFood, QRCode, TransformedFood class AddIngredientForms(forms.ModelForm): @@ -20,11 +20,20 @@ class AddIngredientForms(forms.ModelForm): """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields['ingredient'].queryset = self.fields['ingredient'].queryset.filter(is_ready=False, is_active=True, was_eaten=False) + self.fields['ingredient'].queryset = self.fields['ingredient'].queryset.filter( + polymorphic_ctype__model='transformedfood', + owner_id=self.instance.owner_id, + is_ready=False, + is_active=True, + was_eaten=False, + ) + # Caution, the logic is inverted here, we flip the logic on saving in AddIngredientView + self.fields['is_active'].initial = True + self.fields['is_active'].label = _("Fully used") class Meta: model = TransformedFood - fields = ('ingredient',) + fields = ('ingredient', 'is_active') class BasicFoodForms(forms.ModelForm): @@ -38,7 +47,7 @@ class BasicFoodForms(forms.ModelForm): self.fields['owner'].required = True # Some example - self.fields['name'].widget.attrs.update({"placeholder": _("pasta")}) + self.fields['name'].widget.attrs.update({"placeholder": _("Pasta METRO 5kg")}) clubs = list(Club.objects.filter(PermissionBackend.filter_queryset(get_current_request(), Club, "change")).all()) shuffle(clubs) self.fields['owner'].widget.attrs["placeholder"] = ", ".join(club.name for club in clubs[:4]) + ", ..." @@ -84,7 +93,7 @@ class TransformedFoodForms(forms.ModelForm): self.fields['was_eaten'].initial = False # Some example - self.fields['name'].widget.attrs.update({"placeholder": _("lasagna")}) + self.fields['name'].widget.attrs.update({"placeholder": _("Lasagna")}) clubs = list(Club.objects.filter(PermissionBackend.filter_queryset(get_current_request(), Club, "change")).all()) shuffle(clubs) self.fields['owner'].widget.attrs["placeholder"] = ", ".join(club.name for club in clubs[:4]) + ", ..." @@ -99,13 +108,3 @@ class TransformedFoodForms(forms.ModelForm): ), 'creation_date': DateTimePickerInput(), } - -class FoodForms(forms.ModelForm): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.fields['was_eaten'].initial = True - - class Meta: - model = Food - fields = ('was_eaten',) - diff --git a/apps/food/models.py b/apps/food/models.py index 48974e00..97e00ff9 100644 --- a/apps/food/models.py +++ b/apps/food/models.py @@ -94,7 +94,6 @@ class Food(PolymorphicModel): verbose_name=_('is active'), ) - def __str__(self): return self.name @@ -176,6 +175,11 @@ class TransformedFood(Food): default=timedelta(days=3), ) + @transaction.atomic + def archive(self): + # When a meal are archived, if it was eaten, update ingredient fully used for this meal + raise NotImplementedError + @transaction.atomic def update_allergens(self): # When allergens are changed, simply update the parents' allergens diff --git a/apps/food/templates/food/basicfood_detail.html b/apps/food/templates/food/basicfood_detail.html index b890a93d..846fadba 100644 --- a/apps/food/templates/food/basicfood_detail.html +++ b/apps/food/templates/food/basicfood_detail.html @@ -7,21 +7,31 @@ SPDX-License-Identifier: GPL-3.0-or-later {% block content %}
{% trans 'Name' %} : {{ food.name }}
-{% trans 'Owner' %} : {{ food.owner }}
-{% trans 'Arrival date' %} : {{ food.arrival_date }}
-{% trans 'Expiry date' %} : {{ food.expiry_date }}
-{% trans 'Allergens' %} :
{% trans 'Owner' %} : {{ food.owner }}
{% trans 'Arrival date' %} : {{ food.arrival_date }}
{% trans 'Expiry date' %} : {{ food.expiry_date }} ({{ food.date_type }})
+
{% trans 'Active' %} : {{ food.is_active }}
{% trans 'Eaten' %} : {{ food.was_eaten }}
{% trans 'QR-code number' %} : {{ qrcode.qr_code_number }}
-{% trans 'Name' %} : {{ qrcode.food_container.name }}
-{% trans 'Owner' %} : {{ qrcode.food_container.owner }}
-{% trans 'Expiry date' %} : {{ qrcode.food_container.expiry_date }}
+{% trans 'Name' %} : {{ qrcode.food_container.name }}
{% trans 'Owner' %} : {{ qrcode.food_container.owner }}
{% trans 'Expiry date' %} : {{ qrcode.food_container.expiry_date }}
{% trans 'Name' %} : {{ food.name }}
-{% trans 'Owner' %} : {{ food.owner }}
-{% trans 'Creation date' %} : {{ food.creation_date }}
-{% trans 'Expiry date' %} : {{ food.expiry_date }}
-{% trans 'Allergens' %} :
{% trans 'Owner' %} : {{ food.owner }}
{% trans 'Ready' %} : {{ food.is_ready }}
{% trans 'Creation date' %} : {{ food.creation_date }}
{% trans 'Expiry date' %} : {{ food.expiry_date }}
+
+
{% trans 'Shelf life' %} : {{ food.shelf_life }}
{% trans 'Ready' %} : {{ food.is_ready }}
{% trans 'Active' %} : {{ food.is_active }}
{% trans 'Eaten' %} : {{ food.was_eaten }}
{% trans 'Ingredients' %} :
-