From 6dfad44ba3982bcbbc9d23b265960f0fe001872a Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Fri, 6 May 2022 12:30:32 +0530 Subject: [PATCH] incr: save version in the db --- schemas/core/SystemSettings.json | 14 +++++++++++++- src/initFyo.ts | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/schemas/core/SystemSettings.json b/schemas/core/SystemSettings.json index 4fe68c98..3d5cc287 100644 --- a/schemas/core/SystemSettings.json +++ b/schemas/core/SystemSettings.json @@ -88,7 +88,19 @@ "label": "Currency", "fieldtype": "AutoComplete", "required": true + }, + { + "fieldname": "version", + "label": "Version", + "fieldtype": "Data", + "readOnly": true } ], - "quickEditFields": ["locale", "dateFormat", "currency", "displayPrecision", "hideGetStarted"] + "quickEditFields": [ + "locale", + "dateFormat", + "currency", + "displayPrecision", + "hideGetStarted" + ] } diff --git a/src/initFyo.ts b/src/initFyo.ts index 721d5450..1c02a3f8 100644 --- a/src/initFyo.ts +++ b/src/initFyo.ts @@ -31,6 +31,7 @@ export async function initializeInstance( await setSingles(fyo); await setCreds(fyo); + await setVersion(fyo); await setCurrencySymbols(fyo); } @@ -48,6 +49,21 @@ async function setCreds(fyo: Fyo) { fyo.auth.user = email ?? user; } +async function setVersion(fyo: Fyo) { + const version = (await fyo.getValue( + ModelNameEnum.SystemSettings, + 'version' + )) as string | undefined; + + const { appVersion } = fyo.store; + if (version !== appVersion) { + const systemSettings = await fyo.doc.getSingle( + ModelNameEnum.SystemSettings + ); + await systemSettings?.setAndSync('version', appVersion); + } +} + async function setCurrencySymbols(fyo: Fyo) { const currencies = (await fyo.db.getAll(ModelNameEnum.Currency, { fields: ['name', 'symbol'],