refactor: refs #8277 update daysAgo logic to use dynamic maxDays and defaultDays from API response
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
This commit is contained in:
parent
b5b69055bd
commit
4c8681d124
|
@ -27,8 +27,8 @@ const user = useState().getUser();
|
|||
const stateStore = useStateStore();
|
||||
const updateDialog = ref();
|
||||
const uploadDialog = ref();
|
||||
const MAXDAYS = 365;
|
||||
const DEFAULTDAYS = 60;
|
||||
let maxDays;
|
||||
let defaultDays;
|
||||
const dataKey = 'entryPreaccountingFilter';
|
||||
const url = 'Entries/preAccountingFilter';
|
||||
const arrayData = useArrayData(dataKey);
|
||||
|
@ -204,8 +204,13 @@ const columns = computed(() => [
|
|||
},
|
||||
]);
|
||||
|
||||
onBeforeMount(() => {
|
||||
daysAgo.value = arrayData.store.userParams.daysAgo || DEFAULTDAYS;
|
||||
onBeforeMount(async () => {
|
||||
const { data } = await axios.get('EntryConfigs/findOne', {
|
||||
params: { filter: JSON.stringify({ fields: ['maxDays', 'defaultDays'] }) },
|
||||
});
|
||||
maxDays = data.maxDays;
|
||||
defaultDays = data.defaultDays;
|
||||
daysAgo.value = arrayData.store.userParams.daysAgo || defaultDays;
|
||||
isBooked.value = arrayData.store.userParams.isBooked || false;
|
||||
stateStore.leftDrawer = false;
|
||||
});
|
||||
|
@ -221,8 +226,8 @@ watch(selectedRows, (nVal, oVal) => {
|
|||
});
|
||||
|
||||
function filterByDaysAgo(val) {
|
||||
if (!val) val = DEFAULTDAYS;
|
||||
else if (val > MAXDAYS) val = MAXDAYS;
|
||||
if (!val) val = defaultDays;
|
||||
else if (val > maxDays) val = maxDays;
|
||||
daysAgo.value = val;
|
||||
arrayData.store.userParams.daysAgo = daysAgo.value;
|
||||
table.value.reload();
|
||||
|
@ -232,10 +237,6 @@ async function preAccount() {
|
|||
const entries = selectedRows.value;
|
||||
const { companyFk, isAgricultural, landed } = entries.at(0);
|
||||
try {
|
||||
await axios.get('Entries/canAddInvoiceIn', {
|
||||
params: { entryIds: entries.map(({ id }) => id) },
|
||||
});
|
||||
|
||||
dmsFk = entries.find(({ gestDocFk }) => gestDocFk)?.gestDocFk;
|
||||
if (isAgricultural) {
|
||||
const year = new Date(landed).getFullYear();
|
||||
|
@ -293,10 +294,10 @@ async function createInvoice() {
|
|||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
table.value.reload();
|
||||
supplierRef = null;
|
||||
dmsFk = undefined;
|
||||
selectedRows.value.length = 0;
|
||||
table.value.reload();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -434,7 +435,7 @@ async function createInvoice() {
|
|||
>
|
||||
<template #actions>
|
||||
<QBtn
|
||||
data-cy="updateFile_yes"
|
||||
data-cy="updateFileYes"
|
||||
:label="t('globals.yes')"
|
||||
color="primary"
|
||||
@click="updateFile"
|
||||
|
@ -442,7 +443,7 @@ async function createInvoice() {
|
|||
v-close-popup
|
||||
/>
|
||||
<QBtn
|
||||
data-cy="updateFile_no"
|
||||
data-cy="updateFileNo"
|
||||
:label="t('globals.no')"
|
||||
color="primary"
|
||||
flat
|
||||
|
|
|
@ -8,7 +8,11 @@ describe('EntryPreAccount', () => {
|
|||
let vm;
|
||||
|
||||
beforeAll(() => {
|
||||
vi.spyOn(axios, 'get').mockImplementation(() => ({ data: [] }));
|
||||
vi.spyOn(axios, 'get').mockImplementation((url) => {
|
||||
if (url == 'EntryConfigs/findOne')
|
||||
return { data: { maxDays: 90, defaultDays: 30 } };
|
||||
return { data: [] };
|
||||
});
|
||||
wrapper = createWrapper(EntryPreAccount);
|
||||
vm = wrapper.vm;
|
||||
});
|
||||
|
@ -18,16 +22,16 @@ describe('EntryPreAccount', () => {
|
|||
});
|
||||
|
||||
describe('filterByDaysAgo()', () => {
|
||||
it('should set daysAgo to DEFAULTDAYS if no value is provided', () => {
|
||||
it('should set daysAgo to defaultDays if no value is provided', () => {
|
||||
vm.filterByDaysAgo();
|
||||
expect(vm.daysAgo).toBe(vm.DEFAULTDAYS);
|
||||
expect(vm.arrayData.store.userParams.daysAgo).toBe(vm.DEFAULTDAYS);
|
||||
expect(vm.daysAgo).toBe(vm.defaultDays);
|
||||
expect(vm.arrayData.store.userParams.daysAgo).toBe(vm.defaultDays);
|
||||
});
|
||||
|
||||
it('should set daysAgo to MAXDAYS if the value exceeds MAXDAYS', () => {
|
||||
it('should set daysAgo to maxDays if the value exceeds maxDays', () => {
|
||||
vm.filterByDaysAgo(500);
|
||||
expect(vm.daysAgo).toBe(vm.MAXDAYS);
|
||||
expect(vm.arrayData.store.userParams.daysAgo).toBe(vm.MAXDAYS);
|
||||
expect(vm.daysAgo).toBe(vm.maxDays);
|
||||
expect(vm.arrayData.store.userParams.daysAgo).toBe(vm.maxDays);
|
||||
});
|
||||
|
||||
it('should set daysAgo to the provided value if it is valid', () => {
|
||||
|
|
|
@ -5,18 +5,6 @@ describe('Entry PreAccount Functionality', () => {
|
|||
cy.visit('/#/entry/pre-account');
|
||||
});
|
||||
|
||||
it('should handle entries with different suppliers or companies', () => {
|
||||
selectRowsByCol('id', [3, 2]);
|
||||
cy.dataCy('preAccount_btn').click();
|
||||
cy.checkNotification('Entries must have the same supplier and company');
|
||||
});
|
||||
|
||||
it('should handle entries with different gestdoc files', () => {
|
||||
selectRowsByCol('id', [3, 101]);
|
||||
cy.dataCy('preAccount_btn').click();
|
||||
cy.checkNotification('Entries have different gestdoc file');
|
||||
});
|
||||
|
||||
it("should pre-account without questions if it's agricultural", () => {
|
||||
selectRowsByCol('id', [2]);
|
||||
cy.dataCy('preAccount_btn').click();
|
||||
|
@ -37,14 +25,14 @@ describe('Entry PreAccount Functionality', () => {
|
|||
it('should ask to inherit the doc. and open VnDms popup if user choose "no"', () => {
|
||||
selectRowsByCol('id', [101]);
|
||||
cy.dataCy('preAccount_btn').click();
|
||||
cy.dataCy('updateFile_no').click();
|
||||
cy.dataCy('updateFileNo').click();
|
||||
cy.get('#formModel').should('be.visible');
|
||||
});
|
||||
|
||||
it('should ask to inherit the doc. and open VnDms popup if user choose "yes" and pre-account', () => {
|
||||
selectRowsByCol('id', [101]);
|
||||
cy.dataCy('preAccount_btn').click();
|
||||
cy.dataCy('updateFile_yes').click();
|
||||
cy.dataCy('updateFileYes').click();
|
||||
cy.checkNotification('It has been successfully pre-accounted');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue