8713-testToMaster #1539
|
@ -184,8 +184,11 @@ async function saveChanges(data) {
|
||||||
if ($props.beforeSaveFn) {
|
if ($props.beforeSaveFn) {
|
||||||
changes = await $props.beforeSaveFn(changes, getChanges);
|
changes = await $props.beforeSaveFn(changes, getChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (changes?.creates?.length === 0 && changes?.updates?.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await axios.post($props.saveUrl || $props.url + '/crud', changes);
|
await axios.post($props.saveUrl || $props.url + '/crud', changes);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
|
|
|
@ -30,8 +30,8 @@ describe('CrudModel', () => {
|
||||||
saveFn: '',
|
saveFn: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
wrapper=wrapper.wrapper;
|
wrapper = wrapper.wrapper;
|
||||||
vm=wrapper.vm;
|
vm = wrapper.vm;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -143,14 +143,14 @@ describe('CrudModel', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if object is empty', async () => {
|
it('should return true if object is empty', async () => {
|
||||||
dummyObj ={};
|
dummyObj = {};
|
||||||
result = vm.isEmpty(dummyObj);
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if object is not empty', async () => {
|
it('should return false if object is not empty', async () => {
|
||||||
dummyObj = {a:1, b:2, c:3};
|
dummyObj = { a: 1, b: 2, c: 3 };
|
||||||
result = vm.isEmpty(dummyObj);
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
|
@ -158,29 +158,31 @@ describe('CrudModel', () => {
|
||||||
|
|
||||||
it('should return true if array is empty', async () => {
|
it('should return true if array is empty', async () => {
|
||||||
dummyArray = [];
|
dummyArray = [];
|
||||||
result = vm.isEmpty(dummyArray);
|
result = vm.isEmpty(dummyArray);
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if array is not empty', async () => {
|
it('should return false if array is not empty', async () => {
|
||||||
dummyArray = [1,2,3];
|
dummyArray = [1, 2, 3];
|
||||||
result = vm.isEmpty(dummyArray);
|
result = vm.isEmpty(dummyArray);
|
||||||
|
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('resetData()', () => {
|
describe('resetData()', () => {
|
||||||
it('should add $index to elements in data[] and sets originalData and formData with data', async () => {
|
it('should add $index to elements in data[] and sets originalData and formData with data', async () => {
|
||||||
data = [{
|
data = [
|
||||||
name: 'Tony',
|
{
|
||||||
lastName: 'Stark',
|
name: 'Tony',
|
||||||
age: 42,
|
lastName: 'Stark',
|
||||||
}];
|
age: 42,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
vm.resetData(data);
|
vm.resetData(data);
|
||||||
|
|
||||||
expect(vm.originalData).toEqual(data);
|
expect(vm.originalData).toEqual(data);
|
||||||
expect(vm.originalData[0].$index).toEqual(0);
|
expect(vm.originalData[0].$index).toEqual(0);
|
||||||
expect(vm.formData).toEqual(data);
|
expect(vm.formData).toEqual(data);
|
||||||
|
@ -200,7 +202,7 @@ describe('CrudModel', () => {
|
||||||
lastName: 'Stark',
|
lastName: 'Stark',
|
||||||
age: 42,
|
age: 42,
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.resetData(data);
|
vm.resetData(data);
|
||||||
|
|
||||||
expect(vm.originalData).toEqual(data);
|
expect(vm.originalData).toEqual(data);
|
||||||
|
@ -210,17 +212,19 @@ describe('CrudModel', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('saveChanges()', () => {
|
describe('saveChanges()', () => {
|
||||||
data = [{
|
data = [
|
||||||
name: 'Tony',
|
{
|
||||||
lastName: 'Stark',
|
name: 'Tony',
|
||||||
age: 42,
|
lastName: 'Stark',
|
||||||
}];
|
age: 42,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
it('should call saveFn if exists', async () => {
|
it('should call saveFn if exists', async () => {
|
||||||
await wrapper.setProps({ saveFn: vi.fn() });
|
await wrapper.setProps({ saveFn: vi.fn() });
|
||||||
|
|
||||||
vm.saveChanges(data);
|
vm.saveChanges(data);
|
||||||
|
|
||||||
expect(vm.saveFn).toHaveBeenCalledOnce();
|
expect(vm.saveFn).toHaveBeenCalledOnce();
|
||||||
expect(vm.isLoading).toBe(false);
|
expect(vm.isLoading).toBe(false);
|
||||||
expect(vm.hasChanges).toBe(false);
|
expect(vm.hasChanges).toBe(false);
|
||||||
|
@ -229,13 +233,15 @@ describe('CrudModel', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use default url if there's not saveFn", async () => {
|
it("should use default url if there's not saveFn", async () => {
|
||||||
const postMock =vi.spyOn(axios, 'post');
|
const postMock = vi.spyOn(axios, 'post');
|
||||||
|
|
||||||
vm.formData = [{
|
vm.formData = [
|
||||||
name: 'Bruce',
|
{
|
||||||
lastName: 'Wayne',
|
name: 'Bruce',
|
||||||
age: 45,
|
lastName: 'Wayne',
|
||||||
}]
|
age: 45,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
await vm.saveChanges(data);
|
await vm.saveChanges(data);
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ const sumRisk = ({ clientRisks }) => {
|
||||||
</QCard>
|
</QCard>
|
||||||
<QCard class="vn-max">
|
<QCard class="vn-max">
|
||||||
<VnTitle :text="t('Latest tickets')" />
|
<VnTitle :text="t('Latest tickets')" />
|
||||||
<CustomerSummaryTable />
|
<CustomerSummaryTable :id="entityId" />
|
||||||
</QCard>
|
</QCard>
|
||||||
</template>
|
</template>
|
||||||
</CardSummary>
|
</CardSummary>
|
||||||
|
|
|
@ -20,7 +20,12 @@ const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { viewSummary } = useSummaryDialog();
|
const { viewSummary } = useSummaryDialog();
|
||||||
|
const $props = defineProps({
|
||||||
|
id: {
|
||||||
|
type: Number,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
const filter = {
|
const filter = {
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
|
@ -43,7 +48,7 @@ const filter = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
where: { clientFk: route.params.id },
|
where: { clientFk: $props.id ?? route.params.id },
|
||||||
order: ['shipped DESC', 'id'],
|
order: ['shipped DESC', 'id'],
|
||||||
limit: 30,
|
limit: 30,
|
||||||
};
|
};
|
||||||
|
|
|
@ -158,15 +158,10 @@ const getBadgeAttrs = (_date) => {
|
||||||
|
|
||||||
const scrollToToday = async () => {
|
const scrollToToday = async () => {
|
||||||
await nextTick();
|
await nextTick();
|
||||||
const todayCell = document.querySelector(`td[data-date="${today.toISOString()}"]`);
|
const todayCell = document.querySelector(
|
||||||
if (todayCell) {
|
`td[data-date="${date.formatDate(today, 'YYYY-MM-DD')}"]`,
|
||||||
todayCell.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
);
|
||||||
}
|
if (todayCell) todayCell.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
};
|
|
||||||
|
|
||||||
const formatDateForAttribute = (dateValue) => {
|
|
||||||
if (dateValue instanceof Date) return date.formatDate(dateValue, 'YYYY-MM-DD');
|
|
||||||
return dateValue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function updateWarehouse(warehouseFk) {
|
async function updateWarehouse(warehouseFk) {
|
||||||
|
@ -242,7 +237,7 @@ async function updateWarehouse(warehouseFk) {
|
||||||
</QTd>
|
</QTd>
|
||||||
</template>
|
</template>
|
||||||
<template #body-cell-date="{ row }">
|
<template #body-cell-date="{ row }">
|
||||||
<QTd @click.stop :data-date="formatDateForAttribute(row.shipped)">
|
<QTd @click.stop :data-date="row?.shipped.substring(0, 10)">
|
||||||
<QBadge
|
<QBadge
|
||||||
v-bind="getBadgeAttrs(row.shipped)"
|
v-bind="getBadgeAttrs(row.shipped)"
|
||||||
class="q-ma-none"
|
class="q-ma-none"
|
||||||
|
|
|
@ -10,6 +10,7 @@ import OrderCatalogFilter from 'src/pages/Order/Card/OrderCatalogFilter.vue';
|
||||||
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
|
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
|
||||||
import { useArrayData } from 'src/composables/useArrayData';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
import RightMenu from 'src/components/common/RightMenu.vue';
|
import RightMenu from 'src/components/common/RightMenu.vue';
|
||||||
|
import { onUnmounted } from 'vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
@ -23,16 +24,40 @@ const catalogParams = {
|
||||||
const arrayData = useArrayData(dataKey, {
|
const arrayData = useArrayData(dataKey, {
|
||||||
url: 'Orders/CatalogFilter',
|
url: 'Orders/CatalogFilter',
|
||||||
userParams: catalogParams,
|
userParams: catalogParams,
|
||||||
|
exprBuilder,
|
||||||
|
searchUrl: 'table',
|
||||||
});
|
});
|
||||||
const store = arrayData.store;
|
const store = arrayData.store;
|
||||||
const tags = ref([]);
|
const tags = ref([]);
|
||||||
const itemRefs = ref({});
|
const itemRefs = ref({});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
stateStore.rightDrawer = true;
|
stateStore.rightDrawer = true;
|
||||||
checkOrderConfirmation();
|
checkOrderConfirmation();
|
||||||
|
|
||||||
|
if (
|
||||||
|
arrayData.store.userParams &&
|
||||||
|
Object.keys(arrayData.store.userParams).some((key) => !key.startsWith('order'))
|
||||||
|
) {
|
||||||
|
await arrayData.fetch({});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
arrayData.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
function exprBuilder(param, value) {
|
||||||
|
switch (param) {
|
||||||
|
case 'categoryFk':
|
||||||
|
case 'typeFk':
|
||||||
|
return { [param]: value };
|
||||||
|
case 'search':
|
||||||
|
if (/^\d+$/.test(value)) return { 'i.id': value };
|
||||||
|
else return { 'i.name': { like: `%${value}%` } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function checkOrderConfirmation() {
|
async function checkOrderConfirmation() {
|
||||||
const response = await axios.get(`Orders/${route.params.id}`);
|
const response = await axios.get(`Orders/${route.params.id}`);
|
||||||
if (response.data.isConfirmed === 1) {
|
if (response.data.isConfirmed === 1) {
|
||||||
|
@ -96,6 +121,7 @@ watch(
|
||||||
:tag-value="tagValue"
|
:tag-value="tagValue"
|
||||||
:tags="tags"
|
:tags="tags"
|
||||||
:initial-catalog-params="catalogParams"
|
:initial-catalog-params="catalogParams"
|
||||||
|
:arrayData
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</RightMenu>
|
</RightMenu>
|
||||||
|
|
|
@ -24,6 +24,10 @@ const props = defineProps({
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
arrayData: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
@ -74,17 +78,6 @@ const loadTypes = async (id) => {
|
||||||
typeList.value = data;
|
typeList.value = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
function exprBuilder(param, value) {
|
|
||||||
switch (param) {
|
|
||||||
case 'categoryFk':
|
|
||||||
case 'typeFk':
|
|
||||||
return { [param]: value };
|
|
||||||
case 'search':
|
|
||||||
if (/^\d+$/.test(value)) return { 'i.id': value };
|
|
||||||
else return { 'i.name': { like: `%${value}%` } };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const applyTags = (tagInfo, params, search) => {
|
const applyTags = (tagInfo, params, search) => {
|
||||||
if (!tagInfo || !tagInfo.values.length) {
|
if (!tagInfo || !tagInfo.values.length) {
|
||||||
params.tagGroups = null;
|
params.tagGroups = null;
|
||||||
|
@ -152,9 +145,8 @@ function addOrder(value, field, params) {
|
||||||
:data-key="props.dataKey"
|
:data-key="props.dataKey"
|
||||||
:hidden-tags="['filter', 'orderFk', 'orderBy']"
|
:hidden-tags="['filter', 'orderFk', 'orderBy']"
|
||||||
:unremovable-params="['orderFk', 'orderBy']"
|
:unremovable-params="['orderFk', 'orderBy']"
|
||||||
:expr-builder="exprBuilder"
|
|
||||||
:custom-tags="['tagGroups', 'categoryFk']"
|
:custom-tags="['tagGroups', 'categoryFk']"
|
||||||
:redirect="false"
|
:arrayData
|
||||||
>
|
>
|
||||||
<template #tags="{ tag, formatFn }">
|
<template #tags="{ tag, formatFn }">
|
||||||
<strong v-if="tag.label === 'typeFk' && typeList">
|
<strong v-if="tag.label === 'typeFk' && typeList">
|
||||||
|
|
|
@ -121,6 +121,50 @@ async function handleSave() {
|
||||||
isSaving.value = false;
|
isSaving.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function validateFields(item) {
|
||||||
|
// Only validate fields that are being updated
|
||||||
|
const shouldExist = (field) => !isUpdate || field in item;
|
||||||
|
|
||||||
|
if (!shouldExist('ticketServiceTypeFk') && !item.ticketServiceTypeFk) {
|
||||||
|
notify('Description is required', 'negative');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldExist('quantity') && (!item.quantity || item.quantity <= 0)) {
|
||||||
|
notify('Quantity must be greater than 0', 'negative');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldExist('price') && (!item.price || item.price < 0)) {
|
||||||
|
notify('Price must be valid', 'negative');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function beforeSave(data) {
|
||||||
|
const { creates = [], updates = [] } = data;
|
||||||
|
const validData = { creates: [], updates: [] };
|
||||||
|
|
||||||
|
// Validate creates
|
||||||
|
if (creates.length) {
|
||||||
|
for (const create of creates) {
|
||||||
|
create.ticketFk = route.params.id;
|
||||||
|
if (validateFields(create)) {
|
||||||
|
validData.creates.push(create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate updates
|
||||||
|
if (updates.length) {
|
||||||
|
for (const update of updates) {
|
||||||
|
validData.updates.push(update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validData;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -141,6 +185,7 @@ async function handleSave() {
|
||||||
v-model:selected="selected"
|
v-model:selected="selected"
|
||||||
:order="['description ASC']"
|
:order="['description ASC']"
|
||||||
:default-remove="false"
|
:default-remove="false"
|
||||||
|
:beforeSaveFn="beforeSave"
|
||||||
>
|
>
|
||||||
<template #moreBeforeActions>
|
<template #moreBeforeActions>
|
||||||
<QBtn
|
<QBtn
|
||||||
|
@ -170,6 +215,7 @@ async function handleSave() {
|
||||||
option-value="id"
|
option-value="id"
|
||||||
hide-selected
|
hide-selected
|
||||||
sort-by="name ASC"
|
sort-by="name ASC"
|
||||||
|
:required="true"
|
||||||
>
|
>
|
||||||
<template #form>
|
<template #form>
|
||||||
<TicketCreateServiceType
|
<TicketCreateServiceType
|
||||||
|
@ -185,6 +231,7 @@ async function handleSave() {
|
||||||
:label="col.label"
|
:label="col.label"
|
||||||
v-model.number="row.quantity"
|
v-model.number="row.quantity"
|
||||||
type="number"
|
type="number"
|
||||||
|
:required="true"
|
||||||
min="0"
|
min="0"
|
||||||
:info="t('service.quantityInfo')"
|
:info="t('service.quantityInfo')"
|
||||||
/>
|
/>
|
||||||
|
@ -196,6 +243,7 @@ async function handleSave() {
|
||||||
:label="col.label"
|
:label="col.label"
|
||||||
v-model.number="row.price"
|
v-model.number="row.price"
|
||||||
type="number"
|
type="number"
|
||||||
|
:required="true"
|
||||||
min="0"
|
min="0"
|
||||||
@keyup.enter="handleSave"
|
@keyup.enter="handleSave"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref, nextTick } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import VnInputDate from 'src/components/common/VnInputDate.vue';
|
import VnInputDate from 'src/components/common/VnInputDate.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
|
|
|
@ -79,7 +79,7 @@ const editEvent = async (event) => {
|
||||||
};
|
};
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`Workers/${route.params.id}/updateAbsence`,
|
`Workers/${route.params.id}/updateAbsence`,
|
||||||
params
|
params,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (data) emit('refresh');
|
if (data) emit('refresh');
|
||||||
|
@ -108,14 +108,14 @@ const handleDateSelected = (date) => {
|
||||||
if (!event) createEvent(_date);
|
if (!event) createEvent(_date);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEventSelected = (event, { year, month, day }) => {
|
const handleEventSelected = async (event, { year, month, day }) => {
|
||||||
if (!props.absenceType) {
|
if (!props.absenceType) {
|
||||||
notify(t('Choose an absence type from the right menu'), 'warning');
|
notify(t('Choose an absence type from the right menu'), 'warning');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const date = new Date(year, month - 1, day);
|
const date = new Date(year, month - 1, day);
|
||||||
if (!event?.absenceId) createEvent(date);
|
if (!event?.absenceId) await createEvent(date);
|
||||||
else if (event.type == props.absenceType.code) deleteEvent(event, date);
|
else if (event.type == props.absenceType.code) deleteEvent(event, date);
|
||||||
else editEvent(event);
|
else editEvent(event);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue