diff --git a/apps/food/forms.py b/apps/food/forms.py index fe0775a0..59226a52 100644 --- a/apps/food/forms.py +++ b/apps/food/forms.py @@ -89,7 +89,7 @@ class TransformedFoodForms(forms.ModelForm): class Meta: model = TransformedFood - fields = ('name', 'creation_date', 'owner', 'is_active') + fields = ('name', 'creation_date', 'owner', 'is_active', 'shelf_life') widgets = { "owner": Autocomplete( model=Club, diff --git a/apps/food/migrations/0002_transformedfood_shelf_life.py b/apps/food/migrations/0002_transformedfood_shelf_life.py new file mode 100644 index 00000000..46673643 --- /dev/null +++ b/apps/food/migrations/0002_transformedfood_shelf_life.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.28 on 2024-07-06 20:37 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('food', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='transformedfood', + name='shelf_life', + field=models.DurationField(default=datetime.timedelta(days=3), verbose_name='shelf life'), + ), + ] diff --git a/apps/food/models.py b/apps/food/models.py index e68a5c65..50db24f3 100644 --- a/apps/food/models.py +++ b/apps/food/models.py @@ -165,6 +165,12 @@ class TransformedFood(Food): verbose_name=_('is active'), ) + # Without microbiological analyzes, the storage time is 3 days + shelf_life = models.DurationField( + verbose_name=_("shelf life"), + default=timedelta(days=3), + ) + @transaction.atomic def update_allergens(self): # When allergens are changed, simply update the parents' allergens @@ -185,7 +191,7 @@ class TransformedFood(Food): def update_expiry_date(self): # When expiry_date is changed, simply update the parents' expiry_date old_expiry_date = self.expiry_date - self.expiry_date = self.creation_date + timedelta(days=3) + self.expiry_date = self.creation_date + self.shelf_life for ingredient in self.ingredient.iterator(): self.expiry_date = min(self.expiry_date, ingredient.expiry_date) diff --git a/apps/food/templates/food/transformedfood_list.html b/apps/food/templates/food/transformedfood_list.html index a7b276fc..98d89aa4 100644 --- a/apps/food/templates/food/transformedfood_list.html +++ b/apps/food/templates/food/transformedfood_list.html @@ -7,14 +7,18 @@ SPDX-License-Identifier: GPL-3.0-or-later {% block content %}