Skip to content

Commit

Permalink
PriceEditDialog: allow editing price category, origin & label fields
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jan 8, 2025
1 parent 9426bc8 commit 4db3c15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
30 changes: 11 additions & 19 deletions src/components/PriceEditDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,17 @@
<v-card-text>
<v-row>
<v-col cols="12">
<PriceCard v-if="price" :price="price" :product="price.product" :hidePriceFooterRow="true" :readonly="true" />
<PriceCard v-if="price" :price="price" :product="price.product" :hidePriceFooterRow="false" :readonly="true" />
</v-col>
</v-row>
</v-card-text>

<v-divider />

<v-card-text>
<h3 class="mb-1">
{{ $t('PriceForm.Label') }}
</h3>
{{ updatePriceForm }}
<ProductInputRow :productForm="updatePriceForm" />
<PriceInputRow :priceForm="updatePriceForm" :product="price.product" :hideCurrencyChoice="true" />

<h3 class="mt-4 mb-1">
{{ $t('Common.Date') }}
</h3>
<v-row>
<v-col cols="12">
<v-text-field
v-model="updatePriceForm.date"
:label="$t('Common.Date')"
type="date"
disabled
/>
</v-col>
</v-row>
</v-card-text>

<v-divider />
Expand Down Expand Up @@ -63,6 +48,7 @@ import api from '../services/api'
export default {
components: {
PriceCard: defineAsyncComponent(() => import('../components/PriceCard.vue')),
ProductInputRow: defineAsyncComponent(() => import('../components/ProductInputRow.vue')),
PriceInputRow: defineAsyncComponent(() => import('../components/PriceInputRow.vue')),
},
props: {
Expand All @@ -75,12 +61,18 @@ export default {
data() {
return {
updatePriceForm: {
product: null,
product_code: '',
category_tag: null,
origins_tags: '',
labels_tags: [],
price: null,
price_per: null,
price_is_discounted: false,
price_without_discount: null,
currency: null,
date: null,
receipt_quantity: null,
// date: null,
},
productMode: null,
loading: false
Expand Down
15 changes: 12 additions & 3 deletions src/components/ProductInputRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<v-row>
<v-col>
<v-item-group v-model="productForm.type" class="d-inline" mandatory @update:modelValue="setType($event)">
<v-item v-for="pt in productTypeList" :key="pt.key" v-slot="{ isSelected, toggle }" :value="pt.key">
<v-item v-for="pt in productTypeDisplayList" :key="pt.key" v-slot="{ isSelected, toggle }" :value="pt.key">
<v-chip class="mr-1" :class="isSelected ? 'border-success' : ''" variant="outlined" density="comfortable" @click="toggle">
<v-icon start :icon="pt.icon" />
{{ $t('Common.' + pt.value) }}
Expand All @@ -14,7 +14,7 @@
</v-item-group>
</v-col>
</v-row>
<v-row v-if="productIsTypeProduct" class="mt-0">
<v-row v-if="!hideBarcodeMode && productIsTypeProduct" class="mt-0">
<v-col>
<v-btn class="mb-2" size="small" prepend-icon="mdi-barcode-scan" :class="productForm.product ? 'border-success' : 'border-error'" @click="showBarcodeScannerDialog">
{{ $t('Common.ProductFind') }}
Expand Down Expand Up @@ -100,6 +100,10 @@ export default {
type: Boolean,
default: () => false
},
hideBarcodeMode: {
type: Boolean,
default: false
},
hideProductBarcode: {
type: Boolean,
default: true
Expand All @@ -112,7 +116,6 @@ export default {
emits: ['filled'],
data() {
return {
productTypeList: constants.PRICE_TYPE_LIST,
categoryTags: [], // list of category tags for autocomplete // see initPriceMultipleForm
originTags: [], // list of origins tags for autocomplete // see initPriceMultipleForm
labelTags: [], // list of labels tags for checkboxes // see initPriceMultipleForm
Expand All @@ -127,6 +130,12 @@ export default {
productIsTypeCategory() {
return this.productForm && this.productForm.type === constants.PRICE_TYPE_CATEGORY
},
productTypeDisplayList() {
if (this.hideBarcodeMode) {
return constants.PRICE_TYPE_LIST.filter(pt => pt.key !== constants.PRICE_TYPE_PRODUCT)
}
return constants.PRICE_TYPE_LIST
},
productBarcodeFormFilled() {
let keys = ['product_code']
return Object.keys(this.productForm).filter(k => keys.includes(k)).every(k => !!this.productForm[k])
Expand Down
10 changes: 8 additions & 2 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAppStore } from '../store'
import constants from '../constants'


const PRICE_UPDATE_FIELDS = ['price', 'price_is_discounted', 'price_without_discount', 'price_per', 'currency', 'receipt_quantity', 'date']
const PRICE_UPDATE_FIELDS = ['category_tag', 'labels_tags', 'origins_tags', 'price', 'price_is_discounted', 'price_without_discount', 'price_per', 'currency', 'receipt_quantity', 'date']
const PRICE_CREATE_FIELDS = PRICE_UPDATE_FIELDS.concat(['type', 'product_code', 'product_name', 'category_tag', 'labels_tags', 'origins_tags', 'location_id', 'location_osm_id', 'location_osm_type', 'proof_id'])
const PROOF_UPDATE_FIELDS = ['type', 'date', 'currency', 'receipt_price_count', 'receipt_price_total']
const PROOF_CREATE_FIELDS = PROOF_UPDATE_FIELDS.concat(['location_id', 'location_osm_id', 'location_osm_type']) // 'file'
Expand Down Expand Up @@ -44,6 +44,11 @@ function extraPriceCreateFiltering(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]
} else {
filteredData.origins_tags = null
}
}
return filteredData
}
Expand Down Expand Up @@ -208,7 +213,8 @@ export default {
},

updatePrice(priceId, inputData = {}) {
const data = filterBodyWithAllowedKeys(inputData, PRICE_UPDATE_FIELDS)
let data = filterBodyWithAllowedKeys(inputData, PRICE_UPDATE_FIELDS)
data = extraPriceCreateFiltering(data)
const store = useAppStore()
const url = `${import.meta.env.VITE_OPEN_PRICES_API_URL}/prices/${priceId}?${buildURLParams()}`
return fetch(url, {
Expand Down

0 comments on commit 4db3c15

Please sign in to comment.