From 98044865628a4cac31d1e71738048bf1a8a52e54 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Wed, 14 Dec 2022 12:27:40 +0530 Subject: [PATCH] fix: setupwizard datetime issue --- dummy/index.ts | 6 ++--- fyo/core/converter.ts | 3 --- models/baseModels/SetupWizard/SetupWizard.ts | 24 +++++++++++++------- src/components/Widgets/LinkedEntryWidget.vue | 1 - src/pages/SetupWizard/SetupWizard.vue | 4 ++++ tests/helpers.ts | 12 +++++----- utils/misc.ts | 11 +++++---- 7 files changed, 36 insertions(+), 25 deletions(-) diff --git a/dummy/index.ts b/dummy/index.ts index 4cde7872..1c27ae9c 100644 --- a/dummy/index.ts +++ b/dummy/index.ts @@ -14,7 +14,7 @@ import { flow, getFlowConstant, getRandomDates, - purchaseItemPartyMap + purchaseItemPartyMap, } from './helpers'; import items from './items.json'; import logo from './logo'; @@ -39,8 +39,8 @@ export async function setupDummyInstance( email: 'lin@flosclothes.com', bankName: 'Supreme Bank', currency: 'INR', - fiscalYearStart: getFiscalYear('04-01', true), - fiscalYearEnd: getFiscalYear('04-01', false), + fiscalYearStart: getFiscalYear('04-01', true)!.toISOString(), + fiscalYearEnd: getFiscalYear('04-01', false)!.toISOString(), chartOfAccounts: 'India - Chart of Accounts', }; await setupInstance(dbPath, options, fyo); diff --git a/fyo/core/converter.ts b/fyo/core/converter.ts index 713b8de7..07521dae 100644 --- a/fyo/core/converter.ts +++ b/fyo/core/converter.ts @@ -283,14 +283,12 @@ function toDocAttachment(value: RawValue, field: Field): null | Attachment { } if (typeof value !== 'string') { - console.log('being thrown doc1', typeof value, value); throwError(value, field, 'doc'); } try { return JSON.parse(value) || null; } catch { - console.log('being thrown doc2', typeof value, value); throwError(value, field, 'doc'); } } @@ -429,7 +427,6 @@ function toRawAttachment(value: DocValue, field: Field): null | string { return JSON.stringify(value); } - console.log('being thrown raw', typeof value, value); throwError(value, field, 'raw'); } diff --git a/models/baseModels/SetupWizard/SetupWizard.ts b/models/baseModels/SetupWizard/SetupWizard.ts index d5121d62..d5163f5c 100644 --- a/models/baseModels/SetupWizard/SetupWizard.ts +++ b/models/baseModels/SetupWizard/SetupWizard.ts @@ -42,17 +42,21 @@ export function getCOAList() { } export class SetupWizard extends Doc { - fiscalYearEnd?: string; - fiscalYearStart?: string; + fiscalYearEnd?: Date; + fiscalYearStart?: Date; formulas: FormulaMap = { fiscalYearStart: { formula: async (fieldname?: string) => { - if (fieldname === 'fiscalYearEnd' && this.fiscalYearEnd) { - return DateTime.fromISO(this.fiscalYearEnd) + if ( + fieldname === 'fiscalYearEnd' && + this.fiscalYearEnd && + !this.fiscalYearStart + ) { + return DateTime.fromJSDate(this.fiscalYearEnd) .minus({ years: 1 }) .plus({ days: 1 }) - .toISODate(); + .toJSDate(); } if (!this.country) { @@ -68,11 +72,15 @@ export class SetupWizard extends Doc { }, fiscalYearEnd: { formula: async (fieldname?: string) => { - if (fieldname === 'fiscalYearStart' && this.fiscalYearStart) { - return DateTime.fromISO(this.fiscalYearStart) + if ( + fieldname === 'fiscalYearStart' && + this.fiscalYearStart && + !this.fiscalYearEnd + ) { + return DateTime.fromJSDate(this.fiscalYearStart) .plus({ years: 1 }) .minus({ days: 1 }) - .toISODate(); + .toJSDate(); } if (!this.country) { diff --git a/src/components/Widgets/LinkedEntryWidget.vue b/src/components/Widgets/LinkedEntryWidget.vue index 8516089f..f4a535d1 100644 --- a/src/components/Widgets/LinkedEntryWidget.vue +++ b/src/components/Widgets/LinkedEntryWidget.vue @@ -80,7 +80,6 @@ export default defineComponent({ methods: { getStatus, async openEntry(name: string) { - console.log('op', name); const route = getEntryRoute(this.linked.schemaName, name); await routeTo(route); }, diff --git a/src/pages/SetupWizard/SetupWizard.vue b/src/pages/SetupWizard/SetupWizard.vue index 44d36dac..6497adc3 100644 --- a/src/pages/SetupWizard/SetupWizard.vue +++ b/src/pages/SetupWizard/SetupWizard.vue @@ -109,6 +109,10 @@ export default { this.doc.on('change', () => { this.valuesFilled = this.allValuesFilled(); }); + + if (this.fyo.store.isDevelopment) { + window.sw = this; + } }, methods: { async fill() { diff --git a/tests/helpers.ts b/tests/helpers.ts index 9959cbfd..dd8bf5e5 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -17,8 +17,8 @@ export function getTestSetupWizardOptions(): SetupWizardOptions { email: 'test@testmyfantasy.com', bankName: 'Test Bank of Scriptia', currency: 'INR', - fiscalYearStart: getFiscalYear('04-01', true), - fiscalYearEnd: getFiscalYear('04-01', false), + fiscalYearStart: getFiscalYear('04-01', true)!.toISOString(), + fiscalYearEnd: getFiscalYear('04-01', false)!.toISOString(), chartOfAccounts: 'India - Chart of Accounts', }; } @@ -30,16 +30,16 @@ export function getTestDbPath(dbPath?: string) { /** * Test Boilerplate - * + * * The bottom three functions are test boilerplate for when * an initialized fyo object is to be used. - * + * * They are required because top level await is not supported. * - * Therefore setup and cleanup of the fyo object is wrapped + * Therefore setup and cleanup of the fyo object is wrapped * in tests which are executed serially (and awaited in order) * by tape. - * + * * If `closeTestFyo` is not called the test process won't exit. */ diff --git a/utils/misc.ts b/utils/misc.ts index abb3c56a..1d54a2fb 100644 --- a/utils/misc.ts +++ b/utils/misc.ts @@ -18,9 +18,12 @@ export function getCountryCodeFromCountry(countryName: string): string { return countryInfo.code; } -export function getFiscalYear(date: string, isStart: boolean) { +export function getFiscalYear( + date: string, + isStart: boolean +): undefined | Date { if (!date) { - return ''; + return undefined; } const today = DateTime.local(); @@ -28,12 +31,12 @@ export function getFiscalYear(date: string, isStart: boolean) { if (isStart) { return dateTime .plus({ year: [1, 2, 3].includes(today.month) ? -1 : 0 }) - .toISODate(); + .toJSDate(); } return dateTime .plus({ year: [1, 2, 3].includes(today.month) ? 0 : 1 }) - .toISODate(); + .toJSDate(); } export function logUnexpected(detail: Partial) {