Skip to content

Commit

Permalink
fixed allow decimals in food property amount
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Jun 26, 2023
1 parent dcc56fc commit 436158f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
18 changes: 18 additions & 0 deletions cookbook/migrations/0194_alter_food_properties_food_amount.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 1 addition & 1 deletion cookbook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion cookbook/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def to_internal_value(self, data):
if data == '':
return 0
try:
return float(data.replace(',', ''))
return float(data.replace(',', '.'))
except ValueError:
raise ValidationError('A valid number is required')

Expand Down Expand Up @@ -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']
Expand Down
8 changes: 4 additions & 4 deletions vue/src/utils/openapi/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ export interface Food {
properties?: Array<FoodProperties> | null;
/**
*
* @type {number}
* @type {string}
* @memberof Food
*/
properties_food_amount?: number;
properties_food_amount: string;
/**
*
* @type {FoodPropertiesFoodUnit}
Expand Down Expand Up @@ -1112,10 +1112,10 @@ export interface IngredientFood {
properties?: Array<FoodProperties> | null;
/**
*
* @type {number}
* @type {string}
* @memberof IngredientFood
*/
properties_food_amount?: number;
properties_food_amount: string;
/**
*
* @type {FoodPropertiesFoodUnit}
Expand Down

0 comments on commit 436158f

Please sign in to comment.