fixed property editor fdc import
This commit is contained in:
parent
21094eecc6
commit
b8cadf1faa
@ -644,25 +644,22 @@ class FoodViewSet(viewsets.ModelViewSet, TreeMixin):
|
||||
food_property_list.append(Property(
|
||||
property_type_id=pt.id,
|
||||
property_amount=max(0, round(fn['amount'], 2)), # sometimes FDC might return negative values which make no sense, set to 0
|
||||
import_food_id=food.id,
|
||||
space=self.request.space,
|
||||
))
|
||||
if not property_found:
|
||||
food_property_list.append(Property(
|
||||
property_type_id=pt.id,
|
||||
property_amount=0, # if field not in FDC data the food does not have that property
|
||||
import_food_id=food.id,
|
||||
space=self.request.space,
|
||||
))
|
||||
|
||||
Property.objects.bulk_create(food_property_list, ignore_conflicts=True, unique_fields=('space', 'import_food_id', 'property_type',))
|
||||
properties = Property.objects.bulk_create(food_property_list, unique_fields=('space', 'property_type',))
|
||||
|
||||
property_food_relation_list = []
|
||||
for p in Property.objects.filter(space=self.request.space, import_food_id=food.id).values_list('import_food_id', 'id', ):
|
||||
property_food_relation_list.append(Food.properties.through(food_id=p[0], property_id=p[1]))
|
||||
for p in properties:
|
||||
property_food_relation_list.append(Food.properties.through(food_id=food.id, property_id=p.pk))
|
||||
|
||||
FoodProperty.objects.bulk_create(property_food_relation_list, ignore_conflicts=True, unique_fields=('food_id', 'property_id',))
|
||||
Property.objects.filter(space=self.request.space, import_food_id=food.id).update(import_food_id=None)
|
||||
|
||||
return self.retrieve(request, pk)
|
||||
except Exception:
|
||||
|
@ -69,7 +69,7 @@
|
||||
<td v-for="p in f.properties" v-bind:key="`${f.id}_${p.property_type.id}`">
|
||||
<b-input-group>
|
||||
<template v-if="p.property_amount == null">
|
||||
<b-btn class="btn-sm btn-block btn-success" @click="p.property_amount = 0; updateFood(f)">Add</b-btn>
|
||||
<b-btn class="btn-sm btn-block btn-success" :id="`id_add_btn_${f.id}_${p.property_type.id}`" @click="enableProperty(p,f)">Add</b-btn>
|
||||
</template>
|
||||
<template v-else>
|
||||
<b-form-input v-model="p.property_amount" type="number" :disabled="f.loading" v-b-tooltip.focus :title="p.property_type.name" @change="updateFood(f)"></b-form-input>
|
||||
@ -95,7 +95,7 @@
|
||||
<b-input type="number" v-model="calculator_from_per"></b-input>
|
||||
<i class="fas fa-equals fa-fw mr-1 ml-1"></i>
|
||||
|
||||
<b-input-group >
|
||||
<b-input-group>
|
||||
<b-input v-model="calculator_to_amount" disabled></b-input>
|
||||
<b-input-group-append>
|
||||
<b-btn variant="success" @click="copyCalculatedResult()"><i class="far fa-copy"></i></b-btn>
|
||||
@ -103,7 +103,6 @@
|
||||
</b-input-group>
|
||||
|
||||
|
||||
|
||||
<i class="fas fa-divide fa-fw mr-1 ml-1"></i>
|
||||
<b-input type="number" v-model="calculator_to_per"></b-input>
|
||||
</b-form>
|
||||
@ -150,6 +149,7 @@ import GenericMultiselect from "@/components/GenericMultiselect.vue";
|
||||
import GenericModalForm from "@/components/Modals/GenericModalForm.vue";
|
||||
import KeywordsComponent from "@/components/KeywordsComponent.vue";
|
||||
import VueClipboard from 'vue-clipboard2'
|
||||
|
||||
Vue.use(VueClipboard)
|
||||
Vue.use(BootstrapVue)
|
||||
|
||||
@ -197,7 +197,7 @@ export default {
|
||||
|
||||
this.recipe.steps.forEach(s => {
|
||||
s.ingredients.forEach(i => {
|
||||
if (this.foods.filter(x => (x.id === i.food.id)).length === 0) {
|
||||
if (i.food != null && this.foods.filter(x => (x.id === i.food.id)).length === 0) {
|
||||
this.foods.push(this.buildFood(i.food))
|
||||
}
|
||||
})
|
||||
@ -266,9 +266,14 @@ export default {
|
||||
food.loading = false;
|
||||
})
|
||||
},
|
||||
copyCalculatedResult: function(){
|
||||
copyCalculatedResult: function () {
|
||||
this.$copyText(this.calculator_to_amount)
|
||||
}
|
||||
},
|
||||
enableProperty: function (property, food) {
|
||||
property.property_amount = 0;
|
||||
this.updateFood(food)
|
||||
document.getElementById(`id_add_btn_${food.id}_${property.property_type.id}`).focus()
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user