Skip to content

Commit

Permalink
feat: add category price per unit toggle (#266)
Browse files Browse the repository at this point in the history
* feat: add category price per unit toggle

* feat: category price per unit price card update

* fix: category price per unit first letter

---------

Co-authored-by: dq18 <>
  • Loading branch information
dq18 authored Jan 31, 2024
1 parent 0d0368d commit 02c97c0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/components/PricePrice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default {
priceCurrency() {
return this.price.currency
},
pricePricePer() {
return this.price.price_per
},
},
methods: {
getPriceValue(priceValue, priceCurrency) {
Expand All @@ -59,9 +62,10 @@ export default {
},
getPriceValueDisplay(price) {
if (this.hasCategoryTag) {
return this.$t('PriceCard.PriceValueDisplay', [this.getPriceValue(price, this.priceCurrency)])
const translationKey = this.pricePricePer === 'UNIT' ? 'PriceCard.PriceValueDisplayUnit' : 'PriceCard.PriceValueDisplay';
return this.$t(translationKey, [this.getPriceValue(price, this.priceCurrency)]);
}
return this.getPriceValue(price, this.priceCurrency)
return this.getPriceValue(price, this.priceCurrency);
},
getPricePerKilo() {
const productQuantity = this.productQuantity
Expand Down
7 changes: 5 additions & 2 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"LabelFull": "Full price",
"Proof": "Proof",
"ProofUploaded": "Proof uploaded!",
"Text": "Price {perKg}",
"TextPerKg": "per kg",
"Title": "Price details",
"UploadProof": "Upload a proof",
"TakePicture": "Take a picture",
Expand All @@ -64,6 +62,10 @@
"Barcode": "Barcode",
"Category": "Category"
},
"CategoryPricePer": {
"PerKg": "Price per kg",
"PerUnit": "Price per unit"
},
"Title": "Add a single price",
"WhereWhen": {
"Date": "Date",
Expand Down Expand Up @@ -148,6 +150,7 @@
"Discount": "Discount",
"PriceDate": "on {date}",
"PriceValueDisplay": "{0} / kg",
"PriceValueDisplayUnit": "{0} / unit",
"Proof": "Proof",
"ProductQuantity": "{0} g",
"FullPrice": "Full price",
Expand Down
21 changes: 16 additions & 5 deletions src/views/AddPriceMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@
<i>{{ $t('AddPriceSingle.ProductInfo.SetProduct') }}</i>
</p>
<h3 class="mb-1">
<i18n-t keypath="AddPriceSingle.PriceDetails.Text" tag="span">
<template #perKg>
<span v-if="productMode === 'category'">{{ $t('AddPriceSingle.PriceDetails.TextPerKg') }}</span>
</template>
</i18n-t>
<v-item-group v-if="productMode === 'category'" v-model="productPriceForm.price_per" class="d-inline" mandatory>
<v-item v-for="cpp in categoryPricePerList" :key="cpp.key" :value="cpp.key" v-slot="{ isSelected, toggle }">
<v-chip class="mr-1" @click="toggle" :style="isSelected ? 'border: 1px solid #9E9E9E' : 'border: 1px solid transparent'">
<v-icon start :icon="isSelected ? 'mdi-checkbox-marked-circle' : 'mdi-circle-outline'"></v-icon>
{{ cpp.value }}
</v-chip>
</v-item>
</v-item-group>
</h3>
<v-row>
<v-col :cols="productPriceForm.price_is_discounted ? '6' : '12'" sm="6">
Expand Down Expand Up @@ -359,6 +362,7 @@ export default {
origins_tags: '',
labels_tags: [],
price: null,
price_per: null, // see initPriceSingleForm
price_is_discounted: false,
price_without_discount: null,
currency: null, // see initPriceMultipleForm
Expand All @@ -375,6 +379,10 @@ export default {
labelsTags: LabelsTags,
barcodeScanner: false,
barcodeManualInput: false,
categoryPricePerList: [
{key: 'KILOGRAM', value: this.$t('AddPriceSingle.CategoryPricePer.PerKg'), icon: 'mdi-weight-kilogram'},
{key: 'UNIT', value: this.$t('AddPriceSingle.CategoryPricePer.PerUnit'), icon: 'mdi-numeric-1-circle'}
],
}
},
computed: {
Expand Down Expand Up @@ -525,12 +533,15 @@ export default {
this.productPriceForm = JSON.parse(JSON.stringify(this.productPriceNew))
this.productPriceForm.currency = this.appStore.user.last_currency_used
this.productMode = this.appStore.user.last_product_mode_used
this.productPriceForm.price_per = this.categoryPricePerList[0].key // init to 'KILOGRAM' because it's the most common use-case
},
createPrice() {
this.createPriceLoading = true
// cleanup form
if (!this.productPriceForm.product_code) {
this.productPriceForm.product_code = null
} else {
this.productPriceForm.price_per = null
}
if ((typeof this.productPriceForm.origins_tags === 'string') && (this.productPriceForm.origins_tags.length)) {
this.productPriceForm.origins_tags = [this.productPriceForm.origins_tags]
Expand Down
23 changes: 17 additions & 6 deletions src/views/AddPriceSingle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@
<v-divider></v-divider>
<v-card-text>
<h3 class="mb-1">
<i18n-t keypath="AddPriceSingle.PriceDetails.Text" tag="span">
<template #perKg>
<span v-if="productMode === 'category'">{{ $t('AddPriceSingle.PriceDetails.TextPerKg') }}</span>
</template>
</i18n-t>
<v-item-group v-if="productMode === 'category'" v-model="addPriceSingleForm.price_per" class="d-inline" mandatory>
<v-item v-for="cpp in categoryPricePerList" :key="cpp.key" :value="cpp.key" v-slot="{ isSelected, toggle }">
<v-chip class="mr-1" @click="toggle" :style="isSelected ? 'border: 1px solid #9E9E9E' : 'border: 1px solid transparent'">
<v-icon start :icon="isSelected ? 'mdi-checkbox-marked-circle' : 'mdi-circle-outline'"></v-icon>
{{ cpp.value }}
</v-chip>
</v-item>
</v-item-group>
</h3>
<v-row>
<v-col :cols="addPriceSingleForm.price_is_discounted ? '6' : '12'" sm="6">
Expand Down Expand Up @@ -284,6 +287,7 @@ export default {
origins_tags: '',
labels_tags: [],
price: null,
price_per: null, // see initPriceSingleForm
price_is_discounted: false,
price_without_discount: null,
currency: null, // see initPriceSingleForm
Expand Down Expand Up @@ -313,6 +317,10 @@ export default {
proofImagePreview: null,
createProofLoading: false,
proofSuccessMessage: false,
categoryPricePerList: [
{key: 'KILOGRAM', value: this.$t('AddPriceSingle.CategoryPricePer.PerKg'), icon: 'mdi-weight-kilogram'},
{key: 'UNIT', value: this.$t('AddPriceSingle.CategoryPricePer.PerUnit'), icon: 'mdi-numeric-1-circle'}
],
}
},
computed: {
Expand All @@ -329,7 +337,7 @@ export default {
return this.productBarcodeFormFilled || this.productCategoryFormFilled
},
priceFormFilled() {
let keys = ['price', 'currency']
let keys = ['price', 'currency', 'price_per']
return Object.keys(this.addPriceSingleForm).filter(k => keys.includes(k)).every(k => !!this.addPriceSingleForm[k])
},
proofFormFilled() {
Expand Down Expand Up @@ -369,6 +377,7 @@ export default {
* init product mode, currency & last location
*/
this.productMode = this.addPriceSingleForm.product_code ? 'barcode' : this.appStore.user.last_product_mode_used
this.addPriceSingleForm.price_per = this.categoryPricePerList[0].key // init to 'KILOGRAM' because it's the most common use-case
this.addPriceSingleForm.currency = this.appStore.user.last_currency_used
if (this.recentLocations.length) {
this.setLocationData(this.recentLocations[0])
Expand Down Expand Up @@ -458,6 +467,8 @@ export default {
// cleanup form
if (!this.addPriceSingleForm.product_code) {
this.addPriceSingleForm.product_code = null
} else {
this.addPriceSingleForm.price_per = null
}
if ((typeof this.addPriceSingleForm.origins_tags === 'string') && (this.addPriceSingleForm.origins_tags.length)) {
this.addPriceSingleForm.origins_tags = [this.addPriceSingleForm.origins_tags]
Expand Down

0 comments on commit 02c97c0

Please sign in to comment.