diff --git a/backend/patches/index.ts b/backend/patches/index.ts index e22f94340..c9df6a2ad 100644 --- a/backend/patches/index.ts +++ b/backend/patches/index.ts @@ -37,7 +37,7 @@ export default [ }, { name: 'fixLedgerDateTime', - version: '0.21.1', + version: '0.21.2', patch: fixLedgerDateTime, }, ] as Patch[]; diff --git a/backend/patches/v0_21_0/fixLedgerDateTime.ts b/backend/patches/v0_21_0/fixLedgerDateTime.ts index 6f01cf009..7796a3f16 100644 --- a/backend/patches/v0_21_0/fixLedgerDateTime.ts +++ b/backend/patches/v0_21_0/fixLedgerDateTime.ts @@ -2,30 +2,36 @@ import { DatabaseManager } from '../../database/manager'; /* eslint-disable */ async function execute(dm: DatabaseManager) { - await dm.db!.knex!('AccountingLedgerEntry') - .select('name', 'date') - .then((trx: Array<{name: string; date: Date;}> ) => { - trx.forEach(async entry => { - const entryDate = new Date(entry['date']); - const timeZoneOffset = entryDate.getTimezoneOffset(); - const offsetMinutes = timeZoneOffset % 60; - const offsetHours = (timeZoneOffset - offsetMinutes) / 60; - let daysToAdd = 0; // If behind or at GMT/Zulu time, don't need to add a day - if (timeZoneOffset < 0) { - // If ahead of GMT/Zulu time, need to advance a day forward first - daysToAdd = 1; - } + const sourceTables = [ + "PurchaseInvoice", + "SalesInvoice", + "JournalEntry", + "Payment", + "StockMovement", + "StockTransfer" + ]; - entryDate.setDate(entryDate.getDate() + daysToAdd); - entryDate.setHours(0 - offsetHours); - entryDate.setMinutes(0 - offsetMinutes); - entryDate.setSeconds(0); - entryDate.setMilliseconds(0); + await dm.db!.knex!('AccountingLedgerEntry') + .select('name', 'date', 'referenceName') + .then((trx: Array<{name: string; date: Date; referenceName: string;}> ) => { + trx.forEach(async entry => { - await dm.db!.knex!('AccountingLedgerEntry') - .where({ name: entry['name'] }) - .update({ date: entryDate.toISOString() }); + sourceTables.forEach(async table => { + await dm.db!.knex! + .select('name','date') + .from(table) + .where({ name: entry['referenceName'] }) + .then(async (resp: Array<{name: string; date: Date;}>) => { + if (resp.length !== 0) { + + const dateTimeValue = new Date(resp[0]['date']); + await dm.db!.knex!('AccountingLedgerEntry') + .where({ name: entry['name'] }) + .update({ date: dateTimeValue.toISOString() }); + } + }) + }); }); }); } diff --git a/build/scripts/build.mjs b/build/scripts/build.mjs index 779456d66..158bbf402 100644 --- a/build/scripts/build.mjs +++ b/build/scripts/build.mjs @@ -8,6 +8,7 @@ import * as vite from 'vite'; import { getMainProcessCommonConfig } from './helpers.mjs'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; +import frappeBooksConfig from '../../electron-builder-config.mjs'; const dirname = path.dirname(fileURLToPath(import.meta.url)); const root = path.join(dirname, '..', '..'); @@ -154,11 +155,7 @@ async function packageApp() { } let buildOptions = { - config: { - directories: { output: packageDirPath, app: buildDirPath }, - files: ['**'], - extends: null, - }, + config: frappeBooksConfig, ...builderArgs, }; diff --git a/electron-builder.ts b/electron-builder-config.mjs similarity index 69% rename from electron-builder.ts rename to electron-builder-config.mjs index eae609346..c04c7f918 100644 --- a/electron-builder.ts +++ b/electron-builder-config.mjs @@ -1,4 +1,6 @@ -import type { Configuration } from 'electron-builder'; +// App is tagged with a .mjs extension to allow +import path from 'path'; +import { fileURLToPath } from 'url'; /** * electron-builder doesn't look for the APPLE_TEAM_ID environment variable for some reason. @@ -6,7 +8,13 @@ import type { Configuration } from 'electron-builder'; * collection. See: https://github.com/electron-userland/electron-builder/issues/7812 */ -const config: Configuration = { +const dirname = path.dirname(fileURLToPath(import.meta.url)); +// const root = path.join(dirname, '..', '..'); +const root = dirname; // redundant, but is meant to keep with the previous line +const buildDirPath = path.join(root, 'dist_electron', 'build'); +const packageDirPath = path.join(root, 'dist_electron', 'bundled'); + +const frappeBooksConfig = { productName: 'Frappe Books', appId: 'io.frappe.books', asarUnpack: '**/*.node', @@ -15,6 +23,12 @@ const config: Configuration = { { from: 'translations', to: '../translations' }, { from: 'templates', to: '../templates' }, ], + files: '**', + extends: null, + directories: { + output: packageDirPath, + app: buildDirPath, + }, mac: { type: 'distribution', category: 'public.app-category.finance', @@ -34,7 +48,7 @@ const config: Configuration = { signDlls: true, icon: 'build/icon.ico', publish: ['github'], - target: ['portable', 'nsis'], + target: ['nsis', 'portable'], }, nsis: { oneClick: false, @@ -52,4 +66,4 @@ const config: Configuration = { }, }; -export default config; +export default frappeBooksConfig; diff --git a/models/Transactional/LedgerPosting.ts b/models/Transactional/LedgerPosting.ts index b342a0ce5..cbc791f86 100644 --- a/models/Transactional/LedgerPosting.ts +++ b/models/Transactional/LedgerPosting.ts @@ -61,6 +61,21 @@ export class LedgerPosting { this._validateIsEqual(); } + timezoneDateTimeAdjuster(setDate: string | Date) { + const dateTimeValue = new Date(setDate); + + const dtFixedValue = dateTimeValue; + const dtMinutes = dtFixedValue.getTimezoneOffset() % 60; + const dtHours = (dtFixedValue.getTimezoneOffset() - dtMinutes) / 60; + // Forcing the time to always be set to 00:00.000 for locale time + dtFixedValue.setHours(0 - dtHours); + dtFixedValue.setMinutes(0 - dtMinutes); + dtFixedValue.setSeconds(0); + dtFixedValue.setMilliseconds(0); + + return dtFixedValue; + } + async makeRoundOffEntry() { const { debit, credit } = this._getTotalDebitAndCredit(); const difference = debit.sub(credit); @@ -90,23 +105,6 @@ export class LedgerPosting { return map[account]; } - // Timezone inconsistency fix (very ugly code for now) - const entryDateTime = this.refDoc.date as string | Date; - let dateTimeValue: Date; - if (typeof entryDateTime === 'string' || entryDateTime instanceof String) { - dateTimeValue = new Date(entryDateTime); - } else { - dateTimeValue = entryDateTime; - } - const dtFixedValue = dateTimeValue; - const dtMinutes = dtFixedValue.getTimezoneOffset() % 60; - const dtHours = (dtFixedValue.getTimezoneOffset() - dtMinutes) / 60; - // Forcing the time to always be set to 00:00.000 for locale time - dtFixedValue.setHours(0 - dtHours); - dtFixedValue.setMinutes(0 - dtMinutes); - dtFixedValue.setSeconds(0); - dtFixedValue.setMilliseconds(0); - // end ugly timezone fix code const ledgerEntry = this.fyo.doc.getNewDoc( @@ -114,7 +112,7 @@ export class LedgerPosting { { account: account, party: (this.refDoc.party as string) ?? '', - date: dtFixedValue, + date: this.timezoneDateTimeAdjuster(this.refDoc.date as string | Date), referenceType: this.refDoc.schemaName, referenceName: this.refDoc.name!, reverted: this.reverted, diff --git a/package.json b/package.json index 4667e7e30..c8f94644c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "frappe-books", - "version": "0.21.1", + "version": "0.21.2", "description": "Simple book-keeping app for everyone", "author": { "name": "Frappe Technologies Pvt. Ltd.",