refactor: refs #8388 update VnSelectExpense to use computed for expenses and improve data fetching
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
cc397f6b20
commit
f020db7fe1
|
@ -1,13 +1,21 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { computed, onMounted } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import VnSelectDialog from './VnSelectDialog.vue';
|
import VnSelectDialog from './VnSelectDialog.vue';
|
||||||
import CreateNewExpenseForm from '../CreateNewExpenseForm.vue';
|
import CreateNewExpenseForm from '../CreateNewExpenseForm.vue';
|
||||||
import FetchData from '../FetchData.vue';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
|
|
||||||
const model = defineModel({ type: [String, Number, Object] });
|
const model = defineModel({ type: [String, Number, Object] });
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const expenses = ref([]);
|
const arrayData = useArrayData('expenses', { url: 'Expenses' });
|
||||||
|
const expenses = computed(() => arrayData.store.data);
|
||||||
|
|
||||||
|
onMounted(async () => await arrayData.fetch({}));
|
||||||
|
|
||||||
|
async function updateModel(evt) {
|
||||||
|
await arrayData.fetch({});
|
||||||
|
model.value = evt.id;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VnSelectDialog
|
<VnSelectDialog
|
||||||
|
@ -22,15 +30,9 @@ const expenses = ref([]);
|
||||||
:acls="[{ model: 'Expense', props: '*', accessType: 'WRITE' }]"
|
:acls="[{ model: 'Expense', props: '*', accessType: 'WRITE' }]"
|
||||||
>
|
>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewExpenseForm @on-data-saved="$refs.expensesRef.fetch()" />
|
<CreateNewExpenseForm @on-data-saved="updateModel" />
|
||||||
</template>
|
</template>
|
||||||
</VnSelectDialog>
|
</VnSelectDialog>
|
||||||
<FetchData
|
|
||||||
ref="expensesRef"
|
|
||||||
url="Expenses"
|
|
||||||
auto-load
|
|
||||||
@on-fetch="(data) => (expenses = data)"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, markRaw } from 'vue';
|
import { ref, computed, markRaw, useTemplateRef, onBeforeMount } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useArrayData } from 'src/composables/useArrayData';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
|
@ -14,15 +14,15 @@ import { useAccountShortToStandard } from 'src/composables/useAccountShortToStan
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const arrayData = useArrayData();
|
const arrayData = useArrayData();
|
||||||
|
const expensesArrayData = useArrayData('expenses', { url: 'Expenses' });
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const invoiceIn = computed(() => arrayData.store.data);
|
const invoiceIn = computed(() => arrayData.store.data);
|
||||||
const currency = computed(() => invoiceIn.value?.currency?.code);
|
const currency = computed(() => invoiceIn.value?.currency?.code);
|
||||||
const expenses = ref([]);
|
const expenses = computed(() => expensesArrayData.store.data);
|
||||||
const sageTaxTypes = ref([]);
|
const sageTaxTypes = ref([]);
|
||||||
const sageTransactionTypes = ref([]);
|
const sageTransactionTypes = ref([]);
|
||||||
const rowsSelected = ref([]);
|
const rowsSelected = ref([]);
|
||||||
const invoiceInVatTableRef = ref();
|
const invoiceInVatTableRef = useTemplateRef('invoiceInVatTableRef');
|
||||||
|
|
||||||
defineProps({ actionIcon: { type: String, default: 'add' } });
|
defineProps({ actionIcon: { type: String, default: 'add' } });
|
||||||
|
|
||||||
function taxRate(invoiceInTax) {
|
function taxRate(invoiceInTax) {
|
||||||
|
@ -42,7 +42,7 @@ const columns = computed(() => [
|
||||||
label: t('Expense'),
|
label: t('Expense'),
|
||||||
component: markRaw(VnSelectExpense),
|
component: markRaw(VnSelectExpense),
|
||||||
format: (row, dashIfEmpty) => {
|
format: (row, dashIfEmpty) => {
|
||||||
const expense = expenses.value.find((e) => e.id === row.expenseFk);
|
const expense = expenses.value?.find((e) => e.id === row.expenseFk);
|
||||||
return expense ? `${expense.id}: ${expense.name}` : dashIfEmpty(null);
|
return expense ? `${expense.id}: ${expense.name}` : dashIfEmpty(null);
|
||||||
},
|
},
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
@ -151,6 +151,7 @@ const columns = computed(() => [
|
||||||
align: 'left',
|
align: 'left',
|
||||||
create: true,
|
create: true,
|
||||||
isEditable: isNotEuro(currency.value),
|
isEditable: isNotEuro(currency.value),
|
||||||
|
format: (row, dashIfEmpty) => dashIfEmpty(row.foreignValue),
|
||||||
cellEvent: {
|
cellEvent: {
|
||||||
'update:modelValue': async (value, oldValue, row) =>
|
'update:modelValue': async (value, oldValue, row) =>
|
||||||
await handleForeignValueUpdate(value, row),
|
await handleForeignValueUpdate(value, row),
|
||||||
|
@ -193,6 +194,8 @@ const filter = computed(() => ({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
onBeforeMount(async () => await expensesArrayData.fetch({}));
|
||||||
|
|
||||||
const isNotEuro = (code) => code != 'EUR';
|
const isNotEuro = (code) => code != 'EUR';
|
||||||
|
|
||||||
async function handleForeignValueUpdate(val, row) {
|
async function handleForeignValueUpdate(val, row) {
|
||||||
|
@ -205,7 +208,6 @@ async function handleForeignValueUpdate(val, row) {
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<FetchData url="Expenses" auto-load @on-fetch="(data) => (expenses = data)" />
|
|
||||||
<FetchData url="SageTaxTypes" auto-load @on-fetch="(data) => (sageTaxTypes = data)" />
|
<FetchData url="SageTaxTypes" auto-load @on-fetch="(data) => (sageTaxTypes = data)" />
|
||||||
<FetchData
|
<FetchData
|
||||||
url="sageTransactionTypes"
|
url="sageTransactionTypes"
|
||||||
|
|
Loading…
Reference in New Issue