From 436158f596dce04bf0c3023956edd65207b04514 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 26 Jun 2023 15:47:44 +0200 Subject: [PATCH] fixed allow decimals in food property amount --- .../0194_alter_food_properties_food_amount.py | 18 ++++++++++++++++++ cookbook/models.py | 2 +- cookbook/serializer.py | 3 ++- vue/src/utils/openapi/api.ts | 8 ++++---- 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 cookbook/migrations/0194_alter_food_properties_food_amount.py diff --git a/cookbook/migrations/0194_alter_food_properties_food_amount.py b/cookbook/migrations/0194_alter_food_properties_food_amount.py new file mode 100644 index 000000000..b1d309590 --- /dev/null +++ b/cookbook/migrations/0194_alter_food_properties_food_amount.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.9 on 2023-06-26 13:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0193_space_internal_note'), + ] + + operations = [ + migrations.AlterField( + model_name='food', + name='properties_food_amount', + field=models.DecimalField(blank=True, decimal_places=2, default=100, max_digits=16), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 46af7e786..65697cf24 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -585,7 +585,7 @@ class Food(ExportModelOperationsMixin('food'), TreeModel, PermissionModelMixin): child_inherit_fields = models.ManyToManyField(FoodInheritField, blank=True, related_name='child_inherit') properties = models.ManyToManyField("Property", blank=True, through='FoodProperty') - properties_food_amount = models.IntegerField(default=100, blank=True) + properties_food_amount = models.DecimalField(default=100, max_digits=16, decimal_places=2, blank=True) properties_food_unit = models.ForeignKey(Unit, on_delete=models.PROTECT, blank=True, null=True) preferred_unit = models.ForeignKey(Unit, on_delete=models.SET_NULL, null=True, blank=True, default=None, related_name='preferred_unit') diff --git a/cookbook/serializer.py b/cookbook/serializer.py index a253617cb..f5a7809cf 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -109,7 +109,7 @@ class CustomDecimalField(serializers.Field): if data == '': return 0 try: - return float(data.replace(',', '')) + return float(data.replace(',', '.')) except ValueError: raise ValidationError('A valid number is required') @@ -582,6 +582,7 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedR properties = PropertySerializer(many=True, allow_null=True, required=False) properties_food_unit = UnitSerializer(allow_null=True, required=False) + properties_food_amount = CustomDecimalField() recipe_filter = 'steps__ingredients__food' images = ['recipe__image'] diff --git a/vue/src/utils/openapi/api.ts b/vue/src/utils/openapi/api.ts index 70d6a625e..65aeb1bb6 100644 --- a/vue/src/utils/openapi/api.ts +++ b/vue/src/utils/openapi/api.ts @@ -471,10 +471,10 @@ export interface Food { properties?: Array | null; /** * - * @type {number} + * @type {string} * @memberof Food */ - properties_food_amount?: number; + properties_food_amount: string; /** * * @type {FoodPropertiesFoodUnit} @@ -1112,10 +1112,10 @@ export interface IngredientFood { properties?: Array | null; /** * - * @type {number} + * @type {string} * @memberof IngredientFood */ - properties_food_amount?: number; + properties_food_amount: string; /** * * @type {FoodPropertiesFoodUnit}