From dd7cb43abcb61fe02e0237eb9f2f674754ea65a9 Mon Sep 17 00:00:00 2001 From: Isaac GC Date: Tue, 6 Feb 2024 16:29:44 -0800 Subject: [PATCH 1/4] fixing reports/ledger issues --- models/Transactional/LedgerPosting.ts | 34 +++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) 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, From d4b6c0d4f61927c53026c7430bc8ed57e17401d6 Mon Sep 17 00:00:00 2001 From: Isaac GC Date: Tue, 6 Feb 2024 20:17:04 -0800 Subject: [PATCH 2/4] Build config changed from .ts to .mjs to fix contents not being used properly --- build/scripts/build.mjs | 9 ++++---- ...-builder.ts => electron-builder-config.mjs | 22 +++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) rename electron-builder.ts => electron-builder-config.mjs (69%) diff --git a/build/scripts/build.mjs b/build/scripts/build.mjs index 779456d66..826e64304 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, '..', '..'); @@ -153,12 +154,10 @@ async function packageApp() { delete builderArgs[opt]; } + + 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..6c24afe7b 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; \ No newline at end of file From 556d91dc6cb230cf172c0ca8d3e9b6d964b3c9e7 Mon Sep 17 00:00:00 2001 From: Isaac GC Date: Wed, 7 Feb 2024 20:12:30 -0800 Subject: [PATCH 3/4] bumped version number and fixed patch --- backend/patches/index.ts | 2 +- backend/patches/v0_21_0/fixLedgerDateTime.ts | 48 +++++++++++--------- package.json | 2 +- 3 files changed, 29 insertions(+), 23 deletions(-) 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/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.", From b45214a75eabce5f7ebe723123f8a6ec1b88cfe6 Mon Sep 17 00:00:00 2001 From: Isaac GC Date: Sun, 11 Feb 2024 16:09:35 -0800 Subject: [PATCH 4/4] Fixed linting for PR 843 --- build/scripts/build.mjs | 2 -- electron-builder-config.mjs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/build/scripts/build.mjs b/build/scripts/build.mjs index 826e64304..158bbf402 100644 --- a/build/scripts/build.mjs +++ b/build/scripts/build.mjs @@ -154,8 +154,6 @@ async function packageApp() { delete builderArgs[opt]; } - - let buildOptions = { config: frappeBooksConfig, ...builderArgs, diff --git a/electron-builder-config.mjs b/electron-builder-config.mjs index 6c24afe7b..c04c7f918 100644 --- a/electron-builder-config.mjs +++ b/electron-builder-config.mjs @@ -1,4 +1,4 @@ -// App is tagged with a .mjs extension to allow +// App is tagged with a .mjs extension to allow import path from 'path'; import { fileURLToPath } from 'url'; @@ -66,4 +66,4 @@ const frappeBooksConfig = { }, }; -export default frappeBooksConfig; \ No newline at end of file +export default frappeBooksConfig;