0
0
Fork 0

Merge branch 'dev' into 6943_fix_customer_module

This commit is contained in:
Javier Segarra 2024-09-17 12:12:41 +02:00
commit 29e4c723c9
20 changed files with 351 additions and 177 deletions

View File

@ -67,9 +67,13 @@ const mixinRules = [
requiredFieldRule,
...($attrs.rules ?? []),
(val) => {
const { min } = vnInputRef.value.$attrs;
const { min, max } = vnInputRef.value.$attrs;
if (!min) return null;
if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min });
if (!max) return null;
if (max > 0) {
if (Math.floor(val) > max) return t('inputMax', { value: max });
}
},
];
</script>
@ -116,8 +120,10 @@ const mixinRules = [
<i18n>
en:
inputMin: Must be more than {value}
inputMax: Must be less than {value}
es:
inputMin: Debe ser mayor a {value}
inputMax: Debe ser menor a {value}
</i18n>
<style lang="scss">
.q-field__append {

View File

@ -2,6 +2,7 @@
import { onMounted, watch, computed, ref } from 'vue';
import { date } from 'quasar';
import { useI18n } from 'vue-i18n';
import { useAttrs } from 'vue';
const model = defineModel({ type: [String, Date] });
const $props = defineProps({
@ -14,29 +15,19 @@ const $props = defineProps({
default: true,
},
});
import { useValidator } from 'src/composables/useValidator';
const { validations } = useValidator();
const { t } = useI18n();
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
const requiredFieldRule = (val) => validations().required($attrs.required, val);
const dateFormat = 'DD/MM/YYYY';
const isPopupOpen = ref();
const hover = ref();
const mask = ref();
const $attrs = useAttrs();
onMounted(() => {
// fix quasar bug
mask.value = '##/##/####';
});
const styleAttrs = computed(() => {
return $props.isOutlined
? {
dense: true,
outlined: true,
rounded: true,
}
: {};
});
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
const formattedDate = computed({
get() {
@ -48,16 +39,13 @@ const formattedDate = computed({
let newDate;
if (value) {
// parse input
if (value.includes('/')) {
if (value.length == 6) value = value + new Date().getFullYear();
if (value.length >= 10) {
if (value.includes('/') && value.length >= 10) {
if (value.at(2) == '/') value = value.split('/').reverse().join('/');
value = date.formatDate(
new Date(value).toISOString(),
'YYYY-MM-DDTHH:mm:ss.SSSZ'
);
}
}
const [year, month, day] = value.split('-').map((e) => parseInt(e));
newDate = new Date(year, month - 1, day);
if (model.value) {
@ -79,12 +67,25 @@ const formattedDate = computed({
const popupDate = computed(() =>
model.value ? date.formatDate(new Date(model.value), 'YYYY/MM/DD') : model.value
);
onMounted(() => {
// fix quasar bug
mask.value = '##/##/####';
});
watch(
() => model.value,
(val) => (formattedDate.value = val),
{ immediate: true }
);
const styleAttrs = computed(() => {
return $props.isOutlined
? {
dense: true,
outlined: true,
rounded: true,
}
: {};
});
</script>
<template>
@ -96,9 +97,10 @@ watch(
placeholder="dd/mm/aaaa"
v-bind="{ ...$attrs, ...styleAttrs }"
:class="{ required: $attrs.required }"
:rules="$attrs.required ? [requiredFieldRule] : null"
:rules="mixinRules"
:clearable="false"
@click="isPopupOpen = true"
hide-bottom-space
>
<template #append>
<QIcon

View File

@ -1,8 +1,10 @@
<script setup>
import { computed, ref } from 'vue';
import { computed, ref, useAttrs } from 'vue';
import { useI18n } from 'vue-i18n';
import { date } from 'quasar';
import { useValidator } from 'src/composables/useValidator';
const { validations } = useValidator();
const $attrs = useAttrs();
const model = defineModel({ type: String });
const props = defineProps({
timeOnly: {
@ -16,8 +18,8 @@ const props = defineProps({
});
const initialDate = ref(model.value ?? Date.vnNew());
const { t } = useI18n();
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
const requiredFieldRule = (val) => validations().required($attrs.required, val);
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
const dateFormat = 'HH:mm';
const isPopupOpen = ref();
const hover = ref();
@ -74,9 +76,10 @@ function dateToTime(newDate) {
v-bind="{ ...$attrs, ...styleAttrs }"
:class="{ required: $attrs.required }"
style="min-width: 100px"
:rules="$attrs.required ? [requiredFieldRule] : null"
:rules="mixinRules"
@click="isPopupOpen = false"
type="time"
hide-bottom-space
>
<template #append>
<QIcon

View File

@ -2,21 +2,37 @@
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
import { useI18n } from 'vue-i18n';
import { ref } from 'vue';
const { t } = useI18n();
const value = defineModel({ type: [String, Number, Object] });
const emit = defineEmits(['update:model-value', 'update:options']);
const props = defineProps({
location: {
type: Object,
default: null,
},
});
const modelValue = ref(
props.location
? `${props.location?.postcode} - ${props.location?.city}(${props.location?.province?.name}), ${props.location?.country?.name}`
: null
);
function showLabel(data) {
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
}
const handleModelValue = (data) => {
emit('update:model-value', data);
};
</script>
<template>
<VnSelectDialog
v-model="value"
option-value="code"
v-model="modelValue"
option-filter-value="search"
:option-label="(opt) => showLabel(opt)"
:option-label="
(opt) => (typeof modelValue === 'string' ? modelValue : showLabel(opt))
"
url="Postcodes/filter"
@update:model-value="handleModelValue"
:use-like="false"
:label="t('Location')"
:placeholder="t('search_by_postalcode')"
@ -27,7 +43,14 @@ function showLabel(data) {
:emit-value="false"
>
<template #form>
<CreateNewPostcode @on-data-saved="(newValue) => (value = newValue)" />
<CreateNewPostcode
@on-data-saved="
(newValue) => {
modelValue = newValue;
emit('update:model-value', newValue);
}
"
/>
</template>
<template #option="{ itemProps, opt }">
<QItem v-bind="itemProps">

View File

@ -20,6 +20,8 @@ onMounted(() => (stateStore.leftDrawer = $props.leftDrawer));
</QScrollArea>
</QDrawer>
<QPageContainer>
<RouterView></RouterView>
<QPage>
<RouterView />
</QPage>
</QPageContainer>
</template>

View File

@ -1,7 +1,8 @@
<script setup>
import { ref, toRefs, computed, watch, onMounted } from 'vue';
import { ref, toRefs, computed, watch, onMounted, useAttrs } from 'vue';
import { useI18n } from 'vue-i18n';
import FetchData from 'src/components/FetchData.vue';
import { useValidator } from 'src/composables/useValidator';
const emit = defineEmits(['update:modelValue', 'update:options', 'remove']);
const $props = defineProps({
@ -82,10 +83,11 @@ const $props = defineProps({
default: false,
},
});
const { validations } = useValidator();
const requiredFieldRule = (val) => validations().required($attrs.required, val);
const $attrs = useAttrs();
const { t } = useI18n();
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
const { optionLabel, optionValue, optionFilter, optionFilterValue, options, modelValue } =
toRefs($props);
const myOptions = ref([]);
@ -248,8 +250,9 @@ const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
ref="vnSelectRef"
lazy-rules
:class="{ required: $attrs.required }"
:rules="$attrs.required ? [requiredFieldRule] : null"
:rules="mixinRules"
virtual-scroll-slice-size="options.length"
hide-bottom-space
>
<template v-if="isClearable" #append>
<QIcon

View File

@ -105,6 +105,7 @@ globals:
weight: Weight
pageTitles:
logIn: Login
addressEdit: Update address
summary: Summary
basicData: Basic data
log: Logs

View File

@ -107,6 +107,7 @@ globals:
weight: Peso
pageTitles:
logIn: Inicio de sesión
addressEdit: Modificar consignatario
summary: Resumen
basicData: Datos básicos
log: Historial

View File

@ -5,15 +5,12 @@ import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
import FetchData from 'components/FetchData.vue';
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const addresses = ref([]);
const client = ref(null);
const provincesLocation = ref([]);
const addressFilter = {
fields: [
@ -41,7 +38,13 @@ const addressFilter = {
{
relation: 'province',
scope: {
fields: ['id', 'name'],
fields: ['id', 'name', 'countryFk'],
include: [
{
relation: 'country',
scope: { fields: ['id', 'name'] },
},
],
},
},
],
@ -83,13 +86,6 @@ const getClientData = async (id) => {
}
};
const setProvince = (provinceFk) => {
const result = provincesLocation.value.filter(
(province) => province.id === provinceFk
);
return result[0]?.name || '';
};
const isDefaultAddress = (address) => {
return client?.value?.defaultAddressFk === address.id ? 1 : 0;
};
@ -128,12 +124,6 @@ const toCustomerAddressEdit = (addressId) => {
</script>
<template>
<FetchData
@on-fetch="(data) => (provincesLocation = data)"
auto-load
url="Provinces/location"
/>
<div class="full-width flex justify-center">
<QCard class="card-width q-pa-lg" v-if="addresses.length">
<QCardSection>
@ -177,7 +167,7 @@ const toCustomerAddressEdit = (addressId) => {
<div>{{ item.street }}</div>
<div>
{{ item.postalCode }} - {{ item.city }},
{{ setProvince(item.provinceFk) }}
{{ item.province.name }}
</div>
<div>
{{ item.phone }}

View File

@ -94,7 +94,7 @@ function handleLocation(data, location) {
<VnLocation
:rules="validate('Worker.postcode')"
:acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]"
v-model="data.postcode"
:location="data"
@update:model-value="(location) => handleLocation(data, location)"
/>
</VnRow>

View File

@ -177,7 +177,12 @@ function handleLocation(data, location) {
<VnLocation
:rules="validate('Worker.postcode')"
:acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]"
v-model="data.postalCode"
:location="{
postcode: data.postalCode,
city: data.city,
province: data.province,
country: data.province.country,
}"
@update:model-value="(location) => handleLocation(data, location)"
></VnLocation>
</div>

View File

@ -26,7 +26,13 @@ const addressesFilter = {
{
relation: 'province',
scope: {
fields: ['id', 'name'],
fields: ['id', 'name', 'countryFk'],
include: [
{
relation: 'country',
scope: { fields: ['id', 'name'] },
},
],
},
},
],

View File

@ -21,6 +21,7 @@ const newAddressForm = reactive({
provinceFk: null,
phone: null,
mobile: null,
province: null,
});
const onDataSaved = () => {
@ -84,7 +85,16 @@ function handleLocation(data, location) {
<VnLocation
:rules="validate('Worker.postcode')"
:acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]"
v-model="data.location"
:location="
data.postalCode
? {
postcode: data.postalCode,
city: data.city,
province: data.province,
country: data.province.country,
}
: null
"
@update:model-value="(location) => handleLocation(data, location)"
>
</VnLocation>

View File

@ -19,8 +19,8 @@ const sageTransactionTypesOptions = ref([]);
const supplierActivitiesOptions = ref([]);
function handleLocation(data, location) {
const { town, code, provinceFk, countryFk } = location ?? {};
data.postCode = code;
const { town, label, provinceFk, countryFk } = location ?? {};
data.postCode = label;
data.city = town;
data.provinceFk = provinceFk;
data.countryFk = countryFk;
@ -51,6 +51,23 @@ function handleLocation(data, location) {
:url="`Suppliers/${route.params.id}`"
:url-update="`Suppliers/${route.params.id}/updateFiscalData`"
model="supplier"
:filter="{
fields: ['id', 'name', 'city', 'postCode', 'countryFk', 'provinceFk'],
include: [
{
relation: 'province',
scope: {
fields: ['id', 'name'],
},
},
{
relation: 'country',
scope: {
fields: ['id', 'name'],
},
},
],
}"
auto-load
:clear-store-on-unmount="false"
>
@ -130,7 +147,12 @@ function handleLocation(data, location) {
<VnLocation
:rules="validate('Worker.postcode')"
:acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]"
v-model="data.postCode"
:location="{
postcode: data.postCode,
city: data.city,
province: data.province,
country: data.country,
}"
@update:model-value="(location) => handleLocation(data, location)"
>
</VnLocation>

View File

@ -2,14 +2,13 @@
import { ref, computed } from 'vue';
import axios from 'axios';
import { useQuasar } from 'quasar';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import { useArrayData } from 'src/composables/useArrayData';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import CardList from 'components/ui/CardList.vue';
import FormModelPopup from 'src/components/FormModelPopup.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnRow from 'src/components/ui/VnRow.vue';
import VnTable from 'src/components/VnTable/VnTable.vue';
const quasar = useQuasar();
const arrayData = useArrayData('WagonTypeList');
@ -17,7 +16,7 @@ const store = arrayData.store;
const dialog = ref();
const { push } = useRouter();
const { t } = useI18n();
const paginate = ref();
const tableRef = ref();
const initialData = computed(() => {
return {
@ -25,10 +24,46 @@ const initialData = computed(() => {
};
});
function reloadData() {
initialData.value.name = null;
paginate.value.fetch();
}
const columns = computed(() => [
{
align: 'left',
name: 'id',
label: t('ID'),
isId: true,
cardVisible: true,
},
{
align: 'left',
name: 'name',
label: t('Name'),
isTitle: true,
},
{
align: 'left',
name: 'divisible',
label: t('Divisible'),
cardVisible: true,
component: 'checkbox',
},
{
align: 'right',
name: 'tableActions',
actions: [
{
title: t('components.smartCard.openCard'),
icon: 'arrow_forward',
isPrimary: true,
action: (row) => navigate(row.id, row.name),
},
{
title: t('wagon.list.remove'),
icon: 'delete',
isPrimary: true,
action: (row) => remove(row),
},
],
},
]);
function navigate(id, name) {
push({ path: `/wagon/type/${id}/edit`, query: { name } });
@ -41,51 +76,25 @@ async function remove(row) {
type: 'positive',
});
store.data.splice(store.data.indexOf(row), 1);
window.location.reload();
}
</script>
<template>
<QPage class="column items-center q-pa-md">
<div class="vn-card-list">
<VnPaginate
ref="paginate"
<VnTable
ref="tableRef"
data-key="WagonTypeList"
url="WagonTypes"
order="id DESC"
:columns="columns"
auto-load
order="id DESC"
:right-search="false"
:column-search="false"
:default-mode="'card'"
:disable-option="{ table: true }"
>
<template #body="{ rows }">
<CardList
v-for="row of rows"
:key="row.id"
:title="(row.name || '').toString()"
:id="row.id"
@click="navigate(row.id, row.name)"
>
<template #list-items>
<QCheckbox
:label="t('Divisble')"
:model-value="row.divisible"
disable
/>
</template>
<template #actions>
<QBtn
:label="t('components.smartCard.openCard')"
@click.stop="navigate(row.id, row.name)"
outline
/>
<QBtn
:label="t('wagon.list.remove')"
@click.stop="remove(row)"
color="primary"
style="margin-top: 15px"
/>
</template>
</CardList>
</template>
</VnPaginate>
</div>
</VnTable>
<QPageSticky :offset="[18, 18]">
<QBtn @click.stop="dialog.show()" color="primary" fab icon="add" shortcut="+">
<QDialog ref="dialog">
@ -94,7 +103,7 @@ async function remove(row) {
url-create="WagonTypes"
model="WagonType"
:form-initial-data="initialData"
@on-data-saved="reloadData()"
@on-data-saved="window.location.reload()"
auto-load
>
<template #form-inputs="{ data }">

View File

@ -1,12 +1,13 @@
<script setup>
import axios from 'axios';
import { useQuasar } from 'quasar';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import { useArrayData } from 'src/composables/useArrayData';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import CardList from 'components/ui/CardList.vue';
import VnLv from 'components/ui/VnLv.vue';
import VnTable from 'src/components/VnTable/VnTable.vue';
import { computed } from 'vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import VnInput from 'src/components/common/VnInput.vue';
const quasar = useQuasar();
const arrayData = useArrayData('WagonList');
@ -23,14 +24,56 @@ const filter = {
},
};
const columns = computed(() => [
{
align: 'left',
name: 'label',
label: t('Label'),
isTitle: true,
},
{
align: 'left',
name: 'plate',
label: t('wagon.list.plate'),
cardVisible: true,
},
{
align: 'left',
name: 'volume',
label: t('wagon.list.volume'),
cardVisible: true,
},
{
align: 'left',
name: 'name',
label: t('wagon.list.type'),
cardVisible: true,
format: (row) => row?.type?.name,
},
{
align: 'right',
name: 'tableActions',
actions: [
{
title: t('components.smartCard.openCard'),
icon: 'arrow_forward',
isPrimary: true,
action: (row) => navigate(row.id),
},
{
title: t('wagon.list.remove'),
icon: 'delete',
isPrimary: true,
action: (row) => remove(row),
},
],
},
]);
function navigate(id) {
router.push({ path: `/wagon/${id}/edit` });
}
function create() {
router.push({ path: `/wagon/create` });
}
async function remove(row) {
try {
await axios.delete(`Wagons/${row.id}`).then(async () => {
@ -39,6 +82,7 @@ async function remove(row) {
type: 'positive',
});
store.data.splice(store.data.indexOf(row), 1);
window.location.reload();
});
} catch (error) {
//
@ -48,53 +92,83 @@ async function remove(row) {
<template>
<QPage class="column items-center q-pa-md">
<div class="vn-card-list">
<VnPaginate
<VnTable
ref="tableRef"
data-key="WagonList"
url="/Wagons"
order="id DESC"
url="Wagons"
:filter="filter"
:columns="columns"
auto-load
order="id DESC"
:right-search="false"
:column-search="false"
:default-mode="'card'"
:disable-option="{ table: true }"
:create="{
urlCreate: 'Wagons',
title: t('Create new wagon'),
onDataSaved: () => {
window.location.reload();
},
formInitialData: {},
}"
>
<template #body="{ rows }">
<CardList
v-for="row of rows"
:key="row.id"
:title="(row.label || '').toString()"
:id="row.id"
@click="navigate(row.id)"
<template #more-create-dialog="{ data }">
<VnInput
filled
v-model="data.label"
:label="t('wagon.create.label')"
type="number"
min="0"
:rules="[(val) => !!val || t('wagon.warnings.labelNotEmpty')]"
/>
<VnInput
filled
v-model="data.plate"
:label="t('wagon.create.plate')"
:rules="[(val) => !!val || t('wagon.warnings.plateNotEmpty')]"
/>
<VnInput
filled
v-model="data.volume"
:label="t('wagon.create.volume')"
type="number"
min="0"
:rules="[(val) => !!val || t('wagon.warnings.volumeNotEmpty')]"
/>
<VnSelect
url="WagonTypes"
filled
v-model="data.typeFk"
use-input
fill-input
hide-selected
input-debounce="0"
option-label="name"
option-value="id"
emit-value
map-options
:label="t('wagon.create.type')"
:options="filteredWagonTypes"
:rules="[(val) => !!val || t('wagon.warnings.typeNotEmpty')]"
@filter="filterType"
>
<template #list-items>
<VnLv
:label="t('wagon.list.plate')"
:title-label="t('wagon.list.plate')"
:value="row.plate"
/>
<VnLv :label="t('wagon.list.volume')" :value="row?.volume" />
<VnLv
:label="t('wagon.list.type')"
:value="row?.type?.name"
<template v-if="data.typeFk" #append>
<QIcon
name="cancel"
@click.stop.prevent="data.typeFk = null"
class="cursor-pointer"
/>
</template>
<template #actions>
<QBtn
:label="t('components.smartCard.openCard')"
@click.stop="navigate(row.id)"
outline
/>
<QBtn
:label="t('wagon.list.remove')"
@click.stop="remove(row)"
color="primary"
style="margin-top: 15px"
/>
<template #no-option>
<QItem>
<QItemSection class="text-grey">
{{ t('wagon.warnings.noData') }}
</QItemSection>
</QItem>
</template>
</CardList>
</VnSelect>
</template>
</VnPaginate>
</div>
<QPageSticky position="bottom-right" :offset="[18, 18]">
<QBtn @click="create" fab icon="add" color="primary" shortcut="+" />
</QPageSticky>
</VnTable>
</QPage>
</template>

View File

@ -194,7 +194,6 @@ async function autofillBic(worker) {
<VnLocation
:rules="validate('Worker.postcode')"
:roles-allowed-to-create="['deliveryAssistant']"
v-model="data.location"
@update:model-value="(location) => handleLocation(data, location)"
:disable="formData.isFreelance"
>

View File

@ -264,7 +264,6 @@ async function autofillBic(worker) {
<VnLocation
:acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]"
:options="postcodesOptions"
v-model="data.location"
@update:model-value="(location) => handleLocation(data, location)"
:disable="data.isFreelance"
>

View File

@ -175,7 +175,7 @@ export default {
path: 'edit',
name: 'CustomerAddressEdit',
meta: {
title: 'address-edit',
title: 'addressEdit',
},
component: () =>
import(

View File

@ -18,7 +18,7 @@ describe('VnLocation', () => {
cy.get(inputLocation).click();
cy.get(inputLocation).clear();
cy.get(inputLocation).type('al');
cy.get(locationOptions).should('have.length.at.least', 3);
cy.get(locationOptions).should('have.length.at.least', 4);
});
it('input filter location as "ecuador"', function () {
cy.get(inputLocation).click();
@ -33,11 +33,29 @@ describe('VnLocation', () => {
cy.login('developer');
cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 });
cy.waitForElement('.q-form');
cy.get(createLocationButton).click();
});
it('Fin by postalCode', () => {
const postCode = '46600';
const firstOption = '[role="listbox"] .q-item:nth-child(1)';
cy.get(inputLocation).click();
cy.get(inputLocation).clear();
cy.get(inputLocation).type(postCode);
cy.get(locationOptions).should('have.length.at.least', 2);
cy.get(firstOption).click();
cy.get('.q-btn-group > .q-btn--standard > .q-btn__content > .q-icon').click();
cy.reload();
cy.waitForElement('.q-form');
cy.get(inputLocation).should(
'have.value',
'46600 - Valencia(Province one), España'
);
});
it('Create postCode', () => {
const postCode = '1234475';
const province = 'Valencia';
cy.get(createLocationButton).click();
cy.get('.q-card > h1').should('have.text', 'New postcode');
cy.get(dialogInputs).eq(0).clear();
cy.get(dialogInputs).eq(0).type(postCode);
@ -54,6 +72,7 @@ describe('VnLocation', () => {
it('Create city', () => {
const postCode = '9011';
const province = 'Saskatchew';
cy.get(createLocationButton).click();
cy.get(dialogInputs).eq(0).type(postCode);
// city create button
cy.get(