#6943 Customer FiscalData already exists #1365
|
@ -75,6 +75,10 @@ const $props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
hasConfirmModal: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
saveFn: {
|
saveFn: {
|
||||||
type: Function,
|
type: Function,
|
||||||
default: null,
|
default: null,
|
||||||
|
@ -231,7 +235,7 @@ async function save() {
|
||||||
|
|
||||||
if ($props.saveFn) response = await $props.saveFn(body);
|
if ($props.saveFn) response = await $props.saveFn(body);
|
||||||
else response = await axios[method](url, body);
|
else response = await axios[method](url, body);
|
||||||
|
if ($props.hasConfirmModal) return;
|
||||||
|
|||||||
if ($props.urlCreate) notify('globals.dataCreated', 'positive');
|
if ($props.urlCreate) notify('globals.dataCreated', 'positive');
|
||||||
|
|
||||||
updateAndEmit('onDataSaved', {
|
updateAndEmit('onDataSaved', {
|
||||||
|
|
|
@ -4,14 +4,14 @@ import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'src/components/FetchData.vue';
|
||||||
import FormModel from 'components/FormModel.vue';
|
import FormModel from 'src/components/FormModel.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'src/components/ui/VnRow.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import VnLocation from 'src/components/common/VnLocation.vue';
|
import VnLocation from 'src/components/common/VnLocation.vue';
|
||||||
|
import { useVnConfirm } from 'composables/useVnConfirm';
|
||||||
import VnCheckbox from 'src/components/common/VnCheckbox.vue';
|
import VnCheckbox from 'src/components/common/VnCheckbox.vue';
|
||||||
import { getDifferences, getUpdatedValues } from 'src/filters';
|
import { getDifferences, getUpdatedValues } from 'src/filters';
|
||||||
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
||||||
|
@ -19,6 +19,7 @@ import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const { openConfirmationModal } = useVnConfirm();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
|
|
||||||
const typesTaxes = ref([]);
|
const typesTaxes = ref([]);
|
||||||
|
@ -31,6 +32,44 @@ function handleLocation(data, location) {
|
||||||
data.provinceFk = provinceFk;
|
data.provinceFk = provinceFk;
|
||||||
data.countryFk = countryFk;
|
data.countryFk = countryFk;
|
||||||
}
|
}
|
||||||
|
const formModelRef = ref({});
|
||||||
|
const hasChangedTaxData = ref(false);
|
||||||
|
|
||||||
|
async function formCustomFn(body) {
|
||||||
|
const data = formModelRef.value.formData;
|
||||||
|
const { email, phone, mobile } = data;
|
||||||
jgallego
commented
que @alexm confirme técnicamente el enfoque i en caso que este correcto, hazle test de front. que @alexm confirme técnicamente el enfoque i en caso que este correcto, hazle test de front.
jsegarra
commented
Este caso es muy concreto por eso la nueva prop en FormModel Este caso es muy concreto por eso la nueva prop en FormModel
No puede usarse lo que hay porque al darle a guardar tiene que hacer una comprobación previa(beforeSave), y según eso ejecutar una cosa después del guardado onDataSaved.
Me parece complicado y fácil de entender, el separar un flujo en dos funciones
jsegarra
commented
Okey, ya lo tengo. Cuando me confirmes hago e2e Okey, ya lo tengo. Cuando me confirmes hago e2e
|
|||||||
|
|
||||||
|
const hasContactData = email || phone || mobile;
|
||||||
|
if (hasChangedTaxData.value && hasContactData) await checkExistingClient(body, data);
|
||||||
|
else await confirm(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkExistingClient(body, { email, phone, mobile, id }) {
|
||||||
|
const findParams = Object.entries({ email, phone, mobile })
|
||||||
|
.filter(([, value]) => value)
|
||||||
|
.map(([key, value]) => ({ [key]: value }));
|
||||||
|
|
||||||
|
const filter = JSON.stringify({
|
||||||
|
where: {
|
||||||
|
and: [{ or: findParams }, { id: { neq: id } }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: exist } = await axios.get(`Clients/findOne`, { params: { filter } });
|
||||||
|
if (!exist) confirm(data);
|
||||||
|
else {
|
||||||
|
openConfirmationModal(
|
||||||
|
t('Found a client with this data'),
|
||||||
|
`${t('foundClient_before')} <a class="link" href="#!/client/${exist.id}/summary" target="_blank">${exist.id}</a> ${t('foundClient_after')}`,
|
||||||
|
() => confirm(body),
|
||||||
jgallego
commented
aqui llamas con data primero y luego con body, imagino que lo habrás probado, de donde sale body? aqui llamas con _data_ primero y luego con _body_, imagino que lo habrás probado, de donde sale body?
|
|||||||
|
null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function confirm(data) {
|
||||||
|
await axios.patch(`Clients/${route.params.id}/updateFiscalData`, data);
|
||||||
|
}
|
||||||
|
|
||||||
function onBeforeSave(formData, originalData) {
|
function onBeforeSave(formData, originalData) {
|
||||||
return getUpdatedValues(
|
return getUpdatedValues(
|
||||||
Object.keys(getDifferences(formData, originalData)),
|
Object.keys(getDifferences(formData, originalData)),
|
||||||
|
@ -72,9 +111,12 @@ async function acceptPropagate({ isEqualizated }) {
|
||||||
url="SageTransactionTypes"
|
url="SageTransactionTypes"
|
||||||
/>
|
/>
|
||||||
<FormModel
|
<FormModel
|
||||||
:url-update="`Clients/${route.params.id}/updateFiscalData`"
|
:has-confirm-modal="true"
|
||||||
|
ref="formModelRef"
|
||||||
auto-load
|
auto-load
|
||||||
model="Customer"
|
model="Customer"
|
||||||
|
:save-fn="formCustomFn"
|
||||||
|
prevent-submit
|
||||||
:mapper="onBeforeSave"
|
:mapper="onBeforeSave"
|
||||||
observe-form-changes
|
observe-form-changes
|
||||||
@on-data-saved="checkEtChanges"
|
@on-data-saved="checkEtChanges"
|
||||||
|
@ -101,7 +143,6 @@ async function acceptPropagate({ isEqualizated }) {
|
||||||
<VnRow>
|
<VnRow>
|
||||||
<VnInput :label="t('Street')" clearable v-model="data.street" required />
|
<VnInput :label="t('Street')" clearable v-model="data.street" required />
|
||||||
</VnRow>
|
</VnRow>
|
||||||
|
|
||||||
<VnRow>
|
<VnRow>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Sage tax type')"
|
:label="t('Sage tax type')"
|
||||||
|
@ -112,6 +153,7 @@ async function acceptPropagate({ isEqualizated }) {
|
||||||
v-model="data.sageTaxTypeFk"
|
v-model="data.sageTaxTypeFk"
|
||||||
data-cy="sageTaxTypeFk"
|
data-cy="sageTaxTypeFk"
|
||||||
:required="data.isTaxDataChecked"
|
:required="data.isTaxDataChecked"
|
||||||
|
@update:model-value="hasChangedTaxData = true"
|
||||||
alexm
commented
Duda, esto lo han pedido? Duda, esto lo han pedido?
jsegarra
commented
Esto estaba en salix, y no se migró, Esto estaba en salix, y no se migró,
|
|||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Sage transaction type')"
|
:label="t('Sage transaction type')"
|
||||||
|
@ -122,6 +164,7 @@ async function acceptPropagate({ isEqualizated }) {
|
||||||
data-cy="sageTransactionTypeFk"
|
data-cy="sageTransactionTypeFk"
|
||||||
v-model="data.sageTransactionTypeFk"
|
v-model="data.sageTransactionTypeFk"
|
||||||
:required="data.isTaxDataChecked"
|
:required="data.isTaxDataChecked"
|
||||||
|
@update:model-value="hasChangedTaxData = true"
|
||||||
>
|
>
|
||||||
<template #option="scope">
|
<template #option="scope">
|
||||||
<QItem v-bind="scope.itemProps">
|
<QItem v-bind="scope.itemProps">
|
||||||
|
@ -183,6 +226,7 @@ async function acceptPropagate({ isEqualizated }) {
|
||||||
/><QCheckbox
|
/><QCheckbox
|
||||||
:label="t('Verified data')"
|
:label="t('Verified data')"
|
||||||
v-model="data.isTaxDataChecked"
|
v-model="data.isTaxDataChecked"
|
||||||
|
@update:model-value="hasChangedTaxData = true"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
</template>
|
</template>
|
||||||
|
@ -191,6 +235,9 @@ async function acceptPropagate({ isEqualizated }) {
|
||||||
|
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
|
Found a client with this data: Se ha encontrado un cliente con estos datos
|
||||||
|
foundClient_before: El cliente con id
|
||||||
|
foundClient_after: ya tiene este teléfono o email. ¿Quieres continuar?
|
||||||
Social name: Razón social
|
Social name: Razón social
|
||||||
Tax number: NIF / CIF
|
Tax number: NIF / CIF
|
||||||
Street: Dirección fiscal
|
Street: Dirección fiscal
|
||||||
|
@ -217,6 +264,9 @@ es:
|
||||||
You changed the equalization tax: Has cambiado el recargo de equivalencia
|
You changed the equalization tax: Has cambiado el recargo de equivalencia
|
||||||
Do you want to spread the change?: ¿Deseas propagar el cambio a sus consignatarios?
|
Do you want to spread the change?: ¿Deseas propagar el cambio a sus consignatarios?
|
||||||
en:
|
en:
|
||||||
|
Found a client with this data: A client with this data has been found
|
||||||
|
foundClient_before: The client with id
|
||||||
|
foundClient_after: already has this phone or email. ¿Do you want to continue?
|
||||||
onlyLetters: Only letters, numbers and spaces can be used
|
onlyLetters: Only letters, numbers and spaces can be used
|
||||||
whenActivatingIt: When activating it, do not enter the country code in the ID field
|
whenActivatingIt: When activating it, do not enter the country code in the ID field
|
||||||
inOrderToInvoice: In order to invoice, this field is not contulted, but the consignee's ET. When modifiying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not
|
inOrderToInvoice: In order to invoice, this field is not contulted, but the consignee's ET. When modifiying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not
|
||||||
|
|
Loading…
Reference in New Issue
El await en saveFn al abrir el popup no se espera a que confirmes para continuar?
Si te refieres a la linea 236, la función saveFn apunta a formCustomFn y ahi es donde se gestiona la petición, por tanto termina la implicación de FormModel