Skip to content

Commit

Permalink
fix(Price validation): fix origin & category display for raw products (
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Jan 22, 2025
1 parent 6830855 commit 7e3ef43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
10 changes: 6 additions & 4 deletions src/components/PriceCategoryChip.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<v-chip class="mr-1" label size="small" density="comfortable">
{{ getPriceCategoryTagName(priceCategory) }}
</v-chip>
<span v-if="priceCategory">
<v-chip class="mr-1" label size="small" density="comfortable">
{{ getPriceCategoryTagName(priceCategory) }}
</v-chip>
</span>
</template>

<script>
Expand Down Expand Up @@ -32,7 +34,7 @@ export default {
methods: {
getPriceCategoryTagName(categoryId) {
if (!categoryId || this.categoryTags.length === 0) return ''
return this.categoryTags.find(lt => lt.id === categoryId).name
return this.categoryTags.find(ct => ct.id === categoryId).name
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ function extraPriceCreateOrUpdateFiltering(data) {
else if (filteredData.type == constants.PRICE_TYPE_CATEGORY) {
delete filteredData.product_code
delete filteredData.product
if ((typeof filteredData.origins_tags === 'string') && (filteredData.origins_tags.length)) {
filteredData.origins_tags = [filteredData.origins_tags]
if (filteredData.origins_tags.length) {
if (typeof filteredData.origins_tags === 'string') {
filteredData.origins_tags = [filteredData.origins_tags]
}
} else {
filteredData.origins_tags = ['en:unknown']
}
Expand Down
13 changes: 3 additions & 10 deletions src/views/ContributionAssistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ export default {
const productPriceForm = {
id: priceTag.id,
type: priceType,
category_tag: priceType === constants.PRICE_TYPE_CATEGORY ? label.product : null, // also set to null if product is 'other' ?
origins_tags: [label.origin],
category_tag: (priceType === constants.PRICE_TYPE_CATEGORY && ![null, '', 'unknown', 'other'].includes(label.product)) ? label.product : null,
origins_tags: ![null, '', 'unknown', 'other'].includes(label.origin) ? [label.origin] : [],
labels_tags: label.organic ? [constants.PRODUCT_CATEGORY_LABEL_ORGANIC] : [],
price: label.price.toString(),
price_per: label.unit,
Expand Down Expand Up @@ -438,16 +438,9 @@ export default {
for (let i = 0; i < this.productPriceFormsWithoutPriceId.length; i++) {
const productPriceForm = this.productPriceFormsWithoutPriceId[i]
let origins_tags = productPriceForm.origins_tags
if (!Array.isArray(origins_tags)) {
origins_tags = [origins_tags]
}
if (origins_tags[0] == null || origins_tags[0] == 'unknown' || origins_tags[0] == 'other' || origins_tags[0] == '') {
origins_tags = []
}
const priceData = {
...productPriceForm,
origins_tags: origins_tags,
origins_tags: productPriceForm.origins_tags,
date: this.proofObject.date,
location_id: this.proofObject.location_id,
location_osm_id: this.proofObject.location_osm_id,
Expand Down
13 changes: 3 additions & 10 deletions src/views/PriceValidationAssistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ export default {
const productPriceForm = {
id: data.items[i].id,
type: barcodeString.length >= 8 ? constants.PRICE_TYPE_PRODUCT : constants.PRICE_TYPE_CATEGORY,
category_tag: priceType === constants.PRICE_TYPE_CATEGORY ? label.product : null, // also set to null if product is 'other' ?
origins_tags: [label.origin],
category_tag: (priceType === constants.PRICE_TYPE_CATEGORY && ![null, '', 'unknown', 'other'].includes(label.product)) ? label.product : null,
origins_tags: ![null, '', 'unknown', 'other'].includes(label.origin) ? [label.origin] : [],
labels_tags: label.organic ? [constants.PRODUCT_CATEGORY_LABEL_ORGANIC] : [],
price: label.price.toString(),
price_per: label.unit,
Expand Down Expand Up @@ -203,16 +203,9 @@ export default {
})
},
createPrice(productPriceData) {
let origins_tags = productPriceData.origins_tags
if (!Array.isArray(origins_tags)) {
origins_tags = [origins_tags]
}
if (origins_tags[0] == null || origins_tags[0] == 'unknown' || origins_tags[0] == 'other' || origins_tags[0] == '') {
origins_tags = []
}
const priceData = {
...productPriceData,
origins_tags: origins_tags,
origins_tags: productPriceData.origins_tags,
date: productPriceData.proof.date,
location_id: productPriceData.proof.location_id,
location_osm_id: productPriceData.proof.location_osm_id,
Expand Down

0 comments on commit 7e3ef43

Please sign in to comment.