diff --git a/src/boot/axios.js b/src/boot/axios.js
index fa8a08003..9b32275bd 100644
--- a/src/boot/axios.js
+++ b/src/boot/axios.js
@@ -43,6 +43,15 @@ const onResponseError = (error) => {
}
switch (response?.status) {
+ case 422:
+ if (error.name == 'ValidationError')
+ message +=
+ ' "' +
+ responseError.details.context +
+ '.' +
+ Object.keys(responseError.details.codes).join(',') +
+ '"';
+ break;
case 500:
message = 'errors.statusInternalServerError';
break;
diff --git a/src/components/CreateNewCityForm.vue b/src/components/CreateNewCityForm.vue
index 45fa61dff..3861e3253 100644
--- a/src/components/CreateNewCityForm.vue
+++ b/src/components/CreateNewCityForm.vue
@@ -4,8 +4,8 @@ import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue';
import VnRow from 'components/ui/VnRow.vue';
-import VnSelect from 'src/components/common/VnSelect.vue';
-import VnInput from 'src/components/common/VnInput.vue';
+import VnSelectProvince from 'components/VnSelectProvince.vue';
+import VnInput from 'components/common/VnInput.vue';
import FormModelPopup from './FormModelPopup.vue';
const emit = defineEmits(['onDataSaved']);
@@ -45,15 +45,7 @@ const onDataSaved = (dataSaved) => {
v-model="data.name"
:rules="validate('city.name')"
/>
-
+
diff --git a/src/components/CreateNewPostcodeForm.vue b/src/components/CreateNewPostcodeForm.vue
index 25a61a0ca..b1b8852d3 100644
--- a/src/components/CreateNewPostcodeForm.vue
+++ b/src/components/CreateNewPostcodeForm.vue
@@ -5,9 +5,9 @@ import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
+import VnSelectProvince from 'src/components/VnSelectProvince.vue';
import VnInput from 'src/components/common/VnInput.vue';
import CreateNewCityForm from './CreateNewCityForm.vue';
-import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
import FormModelPopup from './FormModelPopup.vue';
@@ -28,7 +28,7 @@ const countriesOptions = ref([]);
const provincesOptions = ref([]);
const townsLocationOptions = ref([]);
-const onDataSaved = (formData) => {
+function onDataSaved(formData) {
const newPostcode = {
...formData,
};
@@ -43,25 +43,34 @@ const onDataSaved = (formData) => {
const countryObject = countriesOptions.value.find(
({ id }) => id === formData.countryFk
);
- newPostcode.country = countryObject?.country;
+ newPostcode.country = countryObject?.name;
emit('onDataSaved', newPostcode);
-};
+}
-const onCityCreated = async ({ name, provinceFk }, formData) => {
+async function onCityCreated({ name, provinceFk }, formData) {
await townsFetchDataRef.value.fetch();
+ await provincesFetchDataRef.value.fetch();
formData.townFk = townsLocationOptions.value.find((town) => town.name === name).id;
formData.provinceFk = provinceFk;
formData.countryFk = provincesOptions.value.find(
(province) => province.id === provinceFk
).countryFk;
-};
+}
-const onProvinceCreated = async ({ name }, formData) => {
- await provincesFetchDataRef.value.fetch();
- formData.provinceFk = provincesOptions.value.find(
- (province) => province.name === name
- ).id;
-};
+function setTown(id, data) {
+ const newTown = townsLocationOptions.value.find((town) => town.id == id);
+ if (!newTown) return;
+
+ data.provinceFk = newTown.provinceFk;
+ data.countryFk = newTown.province.countryFk;
+}
+
+function setProvince(id, data) {
+ const newProvince = provincesOptions.value.find((province) => province.id == id);
+ if (!newProvince) return;
+
+ data.countryFk = newProvince.countryFk;
+}
@@ -73,6 +82,7 @@ const onProvinceCreated = async ({ name }, formData) => {
/>
(provincesOptions = data)"
auto-load
url="Provinces"
@@ -91,7 +101,7 @@ const onProvinceCreated = async ({ name }, formData) => {
@on-data-saved="onDataSaved"
>
-
+
{
setTown(value, data)"
v-model="data.townFk"
hide-selected
option-label="name"
@@ -107,30 +118,28 @@ const onProvinceCreated = async ({ name }, formData) => {
:rules="validate('postcode.city')"
:roles-allowed-to-create="['deliveryAssistant']"
>
+
+
+
+ {{ opt.name }}
+
+ {{ opt.province.name }},
+ {{ opt.province.country.name }}
+
+
+
+
-
-
+ setProvince(value, data)"
v-model="data.provinceFk"
- :rules="validate('postcode.provinceFk')"
- :roles-allowed-to-create="['deliveryAssistant']"
- >
-
-
-
-
+ {
- emit('onDataSaved', dataSaved);
+const onDataSaved = (dataSaved, requestResponse) => {
+ emit('onDataSaved', dataSaved, requestResponse);
};
@@ -36,7 +36,7 @@ const onDataSaved = (dataSaved) => {
url-create="provinces"
model="province"
:form-initial-data="provinceFormData"
- @on-data-saved="onDataSaved($event)"
+ @on-data-saved="onDataSaved"
>
diff --git a/src/components/VnSelectProvince.vue b/src/components/VnSelectProvince.vue
new file mode 100644
index 000000000..88d372038
--- /dev/null
+++ b/src/components/VnSelectProvince.vue
@@ -0,0 +1,57 @@
+
+
+
+ (provincesOptions = data)"
+ auto-load
+ url="Provinces"
+ />
+
+
+
+
+ {{ opt.name }}
+ {{ opt.country.name }}
+
+
+
+
+
+
+
+
+
+ es:
+ Province: Provincia
+
diff --git a/src/components/common/VnLocation.vue b/src/components/common/VnLocation.vue
index 9ed48ca15..00bda48cc 100644
--- a/src/components/common/VnLocation.vue
+++ b/src/components/common/VnLocation.vue
@@ -1,123 +1,33 @@
- handleFetch(data)"
- />
(value = object)"
clearable
>
-
+ (value = newValue)" />
diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue
index 3cba466a3..9a1a3602f 100644
--- a/src/components/common/VnSelect.vue
+++ b/src/components/common/VnSelect.vue
@@ -25,6 +25,10 @@ const $props = defineProps({
type: String,
default: null,
},
+ optionFilterValue: {
+ type: String,
+ default: null,
+ },
url: {
type: String,
default: '',
@@ -70,7 +74,8 @@ const $props = defineProps({
const { t } = useI18n();
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
-const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props);
+const { optionLabel, optionValue, optionFilter, optionFilterValue, options, modelValue } =
+ toRefs($props);
const myOptions = ref([]);
const myOptionsOriginal = ref([]);
const vnSelectRef = ref();
@@ -82,7 +87,12 @@ const value = computed({
return $props.modelValue;
},
set(value) {
- emit('update:modelValue', value);
+ setOptions(myOptionsOriginal.value);
+ emit(
+ 'update:modelValue',
+ value,
+ value && myOptions.value.find((o) => o[optionValue.value] == value)
+ );
},
});
@@ -137,16 +147,19 @@ async function fetchFilter(val) {
if (!$props.url || !dataRef.value) return;
const { fields, sortBy, limit } = $props;
- let key = optionFilter.value ?? optionLabel.value;
-
- if (new RegExp(/\d/g).test(val)) key = optionValue.value;
+ const key =
+ optionFilterValue.value ??
+ (new RegExp(/\d/g).test(val)
+ ? optionValue.value
+ : optionFilter.value ?? optionLabel.value);
const defaultWhere = $props.useLike
? { [key]: { like: `%${val}%` } }
: { [key]: val };
const where = { ...(val ? defaultWhere : {}), ...$props.where };
- const fetchOptions = { where, order: sortBy, limit };
+ const fetchOptions = { where, limit };
if (fields) fetchOptions.fields = fields;
+ if (sortBy) fetchOptions.order = sortBy;
return dataRef.value.fetch(fetchOptions);
}
diff --git a/src/components/common/VnSelectDialog.vue b/src/components/common/VnSelectDialog.vue
index 3726691af..7f7c29f5d 100644
--- a/src/components/common/VnSelectDialog.vue
+++ b/src/components/common/VnSelectDialog.vue
@@ -1,21 +1,12 @@
-
+ emit('update:modelValue', ...args)"
+ >
handleLocation(data, location)"
>
diff --git a/src/pages/Customer/CustomerCreate.vue b/src/pages/Customer/CustomerCreate.vue
index 80bfd1efe..ca543583a 100644
--- a/src/pages/Customer/CustomerCreate.vue
+++ b/src/pages/Customer/CustomerCreate.vue
@@ -18,7 +18,6 @@ const initialData = reactive({
const workersOptions = ref([]);
const businessTypesOptions = ref([]);
-const postcodesOptions = ref([]);
function handleLocation(data, location) {
const { town, code, provinceFk, countryFk } = location ?? {};
@@ -88,7 +87,6 @@ function handleLocation(data, location) {
handleLocation(data, location)"
>
diff --git a/src/pages/Customer/CustomerList.vue b/src/pages/Customer/CustomerList.vue
index a9e4d978e..f26eb1889 100644
--- a/src/pages/Customer/CustomerList.vue
+++ b/src/pages/Customer/CustomerList.vue
@@ -15,7 +15,6 @@ import { toDate } from 'src/filters';
const { t } = useI18n();
const router = useRouter();
-const postcodesOptions = ref([]);
const tableRef = ref();
const columns = computed(() => [
@@ -420,7 +419,6 @@ function handleLocation(data, location) {
handleLocation(data, location)"
/>
diff --git a/src/pages/Customer/components/CustomerAddressCreate.vue b/src/pages/Customer/components/CustomerAddressCreate.vue
index 57997fb01..0f8baec8c 100644
--- a/src/pages/Customer/components/CustomerAddressCreate.vue
+++ b/src/pages/Customer/components/CustomerAddressCreate.vue
@@ -21,7 +21,6 @@ const formInitialData = reactive({ isDefaultAddress: false });
const urlCreate = ref('');
-const postcodesOptions = ref([]);
const agencyModes = ref([]);
const incoterms = ref([]);
const customsAgents = ref([]);
@@ -94,7 +93,6 @@ function handleLocation(data, location) {
handleLocation(data, location)"
/>
diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue
index 2d14b571e..26c7d0621 100644
--- a/src/pages/Customer/components/CustomerAddressEdit.vue
+++ b/src/pages/Customer/components/CustomerAddressEdit.vue
@@ -18,7 +18,6 @@ const route = useRoute();
const router = useRouter();
const urlUpdate = ref('');
-const postcodesOptions = ref([]);
const agencyModes = ref([]);
const incoterms = ref([]);
const customsAgents = ref([]);
@@ -178,7 +177,6 @@ function handleLocation(data, location) {
handleLocation(data, location)"
>
diff --git a/src/pages/Supplier/Card/SupplierAddressesCreate.vue b/src/pages/Supplier/Card/SupplierAddressesCreate.vue
index eccf06204..ab887e186 100644
--- a/src/pages/Supplier/Card/SupplierAddressesCreate.vue
+++ b/src/pages/Supplier/Card/SupplierAddressesCreate.vue
@@ -11,7 +11,6 @@ const { t } = useI18n();
const route = useRoute();
const router = useRouter();
-const postcodesOptions = ref([]);
const viewAction = ref();
const updateAddressId = ref(null);
const newAddressForm = reactive({
@@ -85,7 +84,6 @@ function handleLocation(data, location) {
handleLocation(data, location)"
>
diff --git a/src/pages/Supplier/Card/SupplierFiscalData.vue b/src/pages/Supplier/Card/SupplierFiscalData.vue
index 179c6f5e6..47f82e904 100644
--- a/src/pages/Supplier/Card/SupplierFiscalData.vue
+++ b/src/pages/Supplier/Card/SupplierFiscalData.vue
@@ -17,7 +17,6 @@ const sageTaxTypesOptions = ref([]);
const sageWithholdingsOptions = ref([]);
const sageTransactionTypesOptions = ref([]);
const supplierActivitiesOptions = ref([]);
-const postcodesOptions = ref([]);
function handleLocation(data, location) {
const { town, code, provinceFk, countryFk } = location ?? {};
@@ -131,7 +130,6 @@ function handleLocation(data, location) {
handleLocation(data, location)"
>
diff --git a/src/pages/Worker/WorkerCreate.vue b/src/pages/Worker/WorkerCreate.vue
index 5e81a3070..a1ded2bfd 100644
--- a/src/pages/Worker/WorkerCreate.vue
+++ b/src/pages/Worker/WorkerCreate.vue
@@ -21,7 +21,6 @@ const companiesOptions = ref([]);
const workersOptions = ref([]);
const payMethodsOptions = ref([]);
const bankEntitiesOptions = ref([]);
-const postcodesOptions = ref([]);
const formData = ref({ isFreelance: false });
const defaultPayMethod = ref(0);
@@ -173,7 +172,6 @@ onBeforeMount(async () => {
handleLocation(data, location)"
:disable="formData.isFreelance"
diff --git a/test/cypress/integration/vnComponent/vnLocation.spec.js b/test/cypress/integration/vnComponent/vnLocation.spec.js
index 6719d8391..30c1d6df2 100644
--- a/test/cypress/integration/vnComponent/vnLocation.spec.js
+++ b/test/cypress/integration/vnComponent/vnLocation.spec.js
@@ -1,8 +1,9 @@
-const locationOptions = '[role="listbox"] > div.q-virtual-scroll__content > .q-item';
describe('VnLocation', () => {
+ const locationOptions = '[role="listbox"] > div.q-virtual-scroll__content > .q-item';
const dialogInputs = '.q-dialog label input';
+ const createLocationButton = '.q-form > .q-card > .vn-row:nth-child(6) .--add-icon';
+ const inputLocation = '.q-form input[aria-label="Location"]';
describe('Worker Create', () => {
- const inputLocation = '.q-form input[aria-label="Location"]';
beforeEach(() => {
cy.viewport(1280, 720);
cy.login('developer');
@@ -32,25 +33,50 @@ describe('VnLocation', () => {
cy.login('developer');
cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 });
cy.waitForElement('.q-form');
+ cy.get(createLocationButton).click();
});
- it('Create postCode', function () {
- cy.get('.q-form > .q-card > .vn-row:nth-child(6) .--add-icon').click();
+ it('Create postCode', () => {
+ const postCode = '1234475';
+ const province = 'Valencia';
cy.get('.q-card > h1').should('have.text', 'New postcode');
- cy.get(dialogInputs).eq(0).clear('12');
- cy.get(dialogInputs).eq(0).type('1234453');
+ cy.get(dialogInputs).eq(0).clear();
+ cy.get(dialogInputs).eq(0).type(postCode);
cy.selectOption(
- '.q-dialog__inner > .column > #formModel > .q-card > :nth-child(4) > .q-select > .q-field__inner > .q-field__control ',
- 'Valencia'
- );
- cy.selectOption(
- '.q-dialog__inner > .column > #formModel > .q-card > :nth-child(5) > .q-select > .q-field__inner > .q-field__control ',
- 'Province one'
- );
- cy.selectOption(
- '.q-dialog__inner > .column > #formModel > .q-card > :nth-child(6) > .q-select > .q-field__inner > .q-field__control ',
- 'EspaƱa'
+ '.q-dialog__inner > .column > #formModel > .q-card > :nth-child(4) > .q-select > .q-field__inner > .q-field__control ',
+ province
);
cy.get('.q-mt-lg > .q-btn--standard').click();
+ cy.get('.q-dialog__inner > .column > #formModel > .q-card').should(
+ 'not.exist'
+ );
+ checkVnLocation(postCode, province);
});
+ it('Create city', () => {
+ const postCode = '9011';
+ const province = 'Saskatchew';
+ cy.get(dialogInputs).eq(0).type(postCode);
+ // city create button
+ cy.get(
+ '.q-dialog__inner > .column > #formModel > .q-card > :nth-child(4) > .q-select > .q-field__inner > .q-field__control > :nth-child(2) > .q-icon'
+ ).click();
+ cy.selectOption('#q-portal--dialog--2 .q-select', 'one');
+ cy.get('#q-portal--dialog--2 .q-input').type(province);
+ cy.get('#q-portal--dialog--2 .q-btn--standard').click();
+ cy.get('#q-portal--dialog--1 .q-btn--standard').click();
+ checkVnLocation(postCode, province);
+ });
+
+ function checkVnLocation(postCode, province) {
+ cy.get('.q-dialog__inner > .column > #formModel > .q-card').should(
+ 'not.exist'
+ );
+ cy.get('.q-form > .q-card > .vn-row:nth-child(6)')
+ .find('input')
+ .invoke('val')
+ .then((text) => {
+ expect(text).to.contain(postCode);
+ expect(text).to.contain(province);
+ });
+ }
});
});