0
0
Fork 0

Merge pull request '#7671 - Fix minor bugs ItemFixedPrices' (!692) from 7671_dense_itemFixedPrices into dev

Reviewed-on: verdnatura/salix-front#692
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Javier Segarra 2024-09-10 05:19:47 +00:00
commit f4f8e83fea
2 changed files with 101 additions and 114 deletions

View File

@ -296,6 +296,7 @@ defineExpose({
reload, reload,
redirect: redirectFn, redirect: redirectFn,
selected, selected,
CrudModelRef,
}); });
function handleOnDataSaved(_, res) { function handleOnDataSaved(_, res) {

View File

@ -212,15 +212,6 @@ const editTableFieldsOptions = [
type: 'number', type: 'number',
}, },
}, },
{
field: 'hasMinPrice',
label: t('item.fixedPrice.hasMinPrice'),
component: 'checkbox',
attrs: {
'false-value': 0,
'true-value': 1,
},
},
{ {
field: 'started', field: 'started',
label: t('item.fixedPrice.started'), label: t('item.fixedPrice.started'),
@ -262,10 +253,13 @@ const updateMinPrice = async (value, props) => {
}); });
}; };
const upsertPrice = async ({ row }, resetMinPrice = false) => { const upsertPrice = async (props, resetMinPrice = false) => {
try { try {
if (resetMinPrice) row.hasMinPrice = 0; const { row } = props;
row = await upsertFixedPrice(row); if (tableRef.value.CrudModelRef.getChanges().updates.length > 0) {
if (resetMinPrice) row.hasMinPrice = 0;
await upsertFixedPrice(row);
}
} catch (err) { } catch (err) {
console.error('Error editing price', err); console.error('Error editing price', err);
} }
@ -283,8 +277,7 @@ async function upsertFixedPrice(row) {
async function saveOnRowChange(row) { async function saveOnRowChange(row) {
if (rowsSelected.value.length > 1) return; if (rowsSelected.value.length > 1) return;
if (rowsSelected.value[0]?.id === row.id) return; if (rowsSelected.value[0]?.id === row.id) return;
else if (rowsSelected.value.length === 1) else if (rowsSelected.value.length === 1) await upsertPrice(rowsSelected.value[0]);
await upsertFixedPrice(rowsSelected.value[0]);
rowsSelected.value = [row]; rowsSelected.value = [row];
} }
@ -454,12 +447,18 @@ function handleOnDataSave({ CrudModelRef }) {
</VnSubToolbar> </VnSubToolbar>
<QPage> <QPage>
<VnTable <VnTable
@on-fetch="
(data) =>
data.forEach((item) => {
item.hasMinPrice = `${item.hasMinPrice !== 0}`;
})
"
:default-remove="false" :default-remove="false"
:default-reset="false" :default-reset="false"
:default-save="false" :default-save="false"
data-key="ItemFixedPrices" data-key="ItemFixedPrices"
url="FixedPrices/filter" url="FixedPrices/filter"
:order="['name ASC', 'itemFk DESC']" :order="['itemFk ASC']"
save-url="FixedPrices/crud" save-url="FixedPrices/crud"
:user-params="{ warehouseFk: user.warehouseFk }" :user-params="{ warehouseFk: user.warehouseFk }"
ref="tableRef" ref="tableRef"
@ -494,60 +493,50 @@ function handleOnDataSave({ CrudModelRef }) {
</template> </template>
<template #column-itemId="props"> <template #column-itemId="props">
<QTd> <VnSelect
<VnSelect style="max-width: 100px"
style="max-width: 100px" url="Items/withName"
url="Items/withName" hide-selected
hide-selected option-label="id"
option-label="id" option-value="id"
option-value="id" v-model="props.row.itemFk"
v-model="props.row.itemFk" v-on="getRowUpdateInputEvents(props, true, 'select')"
v-on="getRowUpdateInputEvents(props, true, 'select')" >
> <template #option="scope">
<template #option="scope"> <QItem v-bind="scope.itemProps">
<QItem v-bind="scope.itemProps"> <QItemSection>
<QItemSection> <QItemLabel> #{{ scope.opt?.id }} </QItemLabel>
<QItemLabel> #{{ scope.opt?.id }} </QItemLabel> <QItemLabel caption>{{ scope.opt?.name }}</QItemLabel>
<QItemLabel caption>{{ scope.opt?.name }}</QItemLabel> </QItemSection>
</QItemSection> </QItem>
</QItem> </template>
</template> </VnSelect>
</VnSelect>
</QTd>
</template> </template>
<template #column-description="{ row }"> <template #column-description="{ row }">
<QTd class="col"> <span class="link">
<span class="link"> {{ row.name }}
{{ row.name }} </span>
</span> <span class="subName">{{ row.subName }}</span>
<ItemDescriptorProxy :id="row.itemFk" /> <ItemDescriptorProxy :id="row.itemFk" />
<FetchedTags <FetchedTags style="width: max-content; max-width: 220px" :item="row" />
style="width: max-content; max-width: 220px"
:item="row"
/>
</QTd>
</template> </template>
<template #column-rate2="props"> <template #column-rate2="props">
<QTd class="col"> <VnInput
<VnInput mask="###.##"
mask="###.##" v-model.number="props.row.rate2"
v-model.number="props.row.rate2" v-on="getRowUpdateInputEvents(props)"
v-on="getRowUpdateInputEvents(props)" >
> <template #append></template>
<template #append></template> </VnInput>
</VnInput>
</QTd>
</template> </template>
<template #column-rate3="props"> <template #column-rate3="props">
<QTd class="col"> <VnInput
<VnInput mask="###.##"
mask="###.##" v-model.number="props.row.rate3"
v-model.number="props.row.rate3" v-on="getRowUpdateInputEvents(props)"
v-on="getRowUpdateInputEvents(props)" >
> <template #append></template>
<template #append></template> </VnInput>
</VnInput>
</QTd>
</template> </template>
<template #column-minPrice="props"> <template #column-minPrice="props">
<QTd class="col"> <QTd class="col">
@ -555,12 +544,11 @@ function handleOnDataSave({ CrudModelRef }) {
<QCheckbox <QCheckbox
:model-value="props.row.hasMinPrice" :model-value="props.row.hasMinPrice"
@update:model-value="updateMinPrice($event, props)" @update:model-value="updateMinPrice($event, props)"
:false-value="0" :false-value="'false'"
:true-value="1" :true-value="'true'"
/> />
<VnInput <VnInput
class="col" class="col"
mask="###.##"
:disable="props.row.hasMinPrice === 1" :disable="props.row.hasMinPrice === 1"
v-model.number="props.row.minPrice" v-model.number="props.row.minPrice"
v-on="getRowUpdateInputEvents(props)" v-on="getRowUpdateInputEvents(props)"
@ -571,60 +559,52 @@ function handleOnDataSave({ CrudModelRef }) {
</QTd> </QTd>
</template> </template>
<template #column-started="props"> <template #column-started="props">
<QTd class="col"> <VnInputDate
<VnInputDate class="vnInputDate"
class="vnInputDate" :show-event="true"
:show-event="true" v-model="props.row.started"
v-model="props.row.started" v-on="getRowUpdateInputEvents(props, false, 'date')"
v-on="getRowUpdateInputEvents(props, false, 'date')" v-bind="dateStyle(isBigger(props.row.started))"
v-bind="dateStyle(isBigger(props.row.started))" />
/>
</QTd>
</template> </template>
<template #column-ended="props"> <template #column-ended="props">
<QTd class="col"> <VnInputDate
<VnInputDate class="vnInputDate"
class="vnInputDate" :show-event="true"
:show-event="true" v-model="props.row.ended"
v-model="props.row.ended" v-on="getRowUpdateInputEvents(props, false, 'date')"
v-on="getRowUpdateInputEvents(props, false, 'date')" v-bind="dateStyle(isLower(props.row.ended))"
v-bind="dateStyle(isLower(props.row.started))" />
/>
</QTd>
</template> </template>
<template #column-warehouseFk="props"> <template #column-warehouseFk="props">
<QTd class="col"> <VnSelect
<VnSelect style="max-width: 150px"
style="max-width: 150px" :options="warehousesOptions"
:options="warehousesOptions" hide-selected
hide-selected option-label="name"
option-label="name" option-value="id"
option-value="id" v-model="props.row.warehouseFk"
v-model="props.row.warehouseFk" v-on="getRowUpdateInputEvents(props, false, 'select')"
v-on="getRowUpdateInputEvents(props, false, 'select')" />
/>
</QTd>
</template> </template>
<template #column-deleteAction="{ row, rowIndex }"> <template #column-deleteAction="{ row, rowIndex }">
<QTd class="col"> <QIcon
<QIcon name="delete"
name="delete" size="sm"
size="sm" class="cursor-pointer fill-icon-on-hover"
class="cursor-pointer fill-icon-on-hover" color="primary"
color="primary" @click.stop="
@click.stop=" openConfirmationModal(
openConfirmationModal( t('globals.rowWillBeRemoved'),
t('globals.rowWillBeRemoved'), t('Do you want to clone this item?'),
t('Do you want to clone this item?'), () => removePrice(row.id, rowIndex)
() => removePrice(row.id, rowIndex) )
) "
" >
> <QTooltip class="text-no-wrap">
<QTooltip class="text-no-wrap"> {{ t('globals.delete') }}
{{ t('globals.delete') }} </QTooltip>
</QTooltip> </QIcon>
</QIcon>
</QTd>
</template> </template>
</VnTable> </VnTable>
@ -679,6 +659,12 @@ tbody tr.highlight .q-td {
background-color: transparent; background-color: transparent;
} }
} }
.subName {
margin-left: 5%;
font-size: 0.75rem;
text-transform: uppercase;
color: var(--vn-label-color);
}
</style> </style>
<i18n> <i18n>
es: es: