mirror of
https://github.com/frappe/books.git
synced 2026-08-24 10:04:45 -05:00
Merge pull request #843 from frappe/reports_db_patch_fix
Reports and Ledger DateTime Bug Fix
This commit is contained in:
@@ -37,7 +37,7 @@ export default [
|
||||
},
|
||||
{
|
||||
name: 'fixLedgerDateTime',
|
||||
version: '0.21.1',
|
||||
version: '0.21.2',
|
||||
patch: fixLedgerDateTime,
|
||||
},
|
||||
] as Patch[];
|
||||
|
||||
@@ -2,30 +2,36 @@ import { DatabaseManager } from '../../database/manager';
|
||||
|
||||
/* eslint-disable */
|
||||
async function execute(dm: DatabaseManager) {
|
||||
|
||||
const sourceTables = [
|
||||
"PurchaseInvoice",
|
||||
"SalesInvoice",
|
||||
"JournalEntry",
|
||||
"Payment",
|
||||
"StockMovement",
|
||||
"StockTransfer"
|
||||
];
|
||||
|
||||
await dm.db!.knex!('AccountingLedgerEntry')
|
||||
.select('name', 'date')
|
||||
.then((trx: Array<{name: string; date: Date;}> ) => {
|
||||
.select('name', 'date', 'referenceName')
|
||||
.then((trx: Array<{name: string; date: Date; referenceName: string;}> ) => {
|
||||
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;
|
||||
}
|
||||
|
||||
entryDate.setDate(entryDate.getDate() + daysToAdd);
|
||||
entryDate.setHours(0 - offsetHours);
|
||||
entryDate.setMinutes(0 - offsetMinutes);
|
||||
entryDate.setSeconds(0);
|
||||
entryDate.setMilliseconds(0);
|
||||
|
||||
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() });
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user