diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 03f75477d..3100b9f43 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -117,8 +117,8 @@ onMounted(async () => { state.set($props.model, $props.formInitialData); if ($props.autoLoad && !$props.formInitialData && $props.url) await fetch(); - else if (arrayData.store.data) updateAndEmit(arrayData.store.data, 'onFetch'); - + else if (arrayData.store.data && !$props.formInitialData) + updateAndEmit(arrayData.store.data, 'onFetch'); if ($props.observeFormChanges) { watch( () => formData.value, diff --git a/src/pages/Travel/Card/TravelDescriptorMenuItems.vue b/src/pages/Travel/Card/TravelDescriptorMenuItems.vue index ab1de5b3e..9309f8686 100644 --- a/src/pages/Travel/Card/TravelDescriptorMenuItems.vue +++ b/src/pages/Travel/Card/TravelDescriptorMenuItems.vue @@ -32,11 +32,11 @@ const cloneTravel = () => { redirectToCreateView(stringifiedTravelData); }; -const cloneTravelWithEntries = () => { +const cloneTravelWithEntries = async () => { try { - axios.post(`Travels/${$props.travel.id}/cloneWithEntries`); + const { id } = await axios.post(`Travels/${$props.travel.id}/cloneWithEntries`); notify('globals.dataSaved', 'positive'); - redirectToCreateView(); + router.push({ name: 'TravelBasicData', params: { id } }); } catch (err) { console.err('Error cloning travel with entries'); } diff --git a/src/pages/Travel/TravelCreate.vue b/src/pages/Travel/TravelCreate.vue index 53c8d402d..5f61f3c74 100644 --- a/src/pages/Travel/TravelCreate.vue +++ b/src/pages/Travel/TravelCreate.vue @@ -15,33 +15,23 @@ const { t } = useI18n(); const route = useRoute(); const router = useRouter(); -const newTravelForm = reactive({ - ref: null, - agencyModeFk: null, - shipped: null, - landed: null, - warehouseOutFk: null, - warehouseInFk: null, -}); - const agenciesOptions = ref([]); const warehousesOptions = ref([]); const viewAction = ref(); +const newTravelForm = ref({}); onBeforeMount(() => { - // Esto nos permite decirle a FormModel si queremos observar los cambios o no - // Ya que si queremos clonar queremos que nos permita guardar inmediatamente sin realizar cambios en el form viewAction.value = route.query.travelData ? 'clone' : 'create'; if (route.query.travelData) { const travelData = JSON.parse(route.query.travelData); - for (let key in newTravelForm) { - newTravelForm[key] = travelData[key]; - } + + newTravelForm.value = { ...newTravelForm.value, ...travelData }; + delete newTravelForm.value.id; } }); -const redirectToTravelBasicData = (_, { id }) => { +const redirectToTravelBasicData = ({ id }) => { router.push({ name: 'TravelBasicData', params: { id } }); }; @@ -60,8 +50,8 @@ const redirectToTravelBasicData = (_, { id }) => {