2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

fix: setupwizard datetime issue

This commit is contained in:
18alantom 2022-12-14 12:27:40 +05:30
parent ff8b5431f5
commit 9804486562
7 changed files with 36 additions and 25 deletions

View File

@ -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);

View File

@ -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');
}

View File

@ -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) {

View File

@ -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);
},

View File

@ -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() {

View File

@ -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',
};
}

View File

@ -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<UnexpectedLogObject>) {