diff --git a/backend/database/core.ts b/backend/database/core.ts index 719183e6..b5f9a9a1 100644 --- a/backend/database/core.ts +++ b/backend/database/core.ts @@ -774,7 +774,17 @@ export default class DatabaseCore extends DatabaseBase { order: 'asc', }); - return getValueMapFromList(values, 'fieldname', 'value') as FieldValueMap; + const fieldValueMap = getValueMapFromList( + values, + 'fieldname', + 'value' + ) as FieldValueMap; + const tableFields: TargetField[] = this.#getTableFields(schemaName); + if (tableFields.length) { + await this.#loadChildren(schemaName, fieldValueMap, tableFields); + } + + return fieldValueMap; } #insertOne(schemaName: string, fieldValueMap: FieldValueMap) { @@ -800,7 +810,7 @@ export default class DatabaseCore extends DatabaseBase { fieldValueMap: FieldValueMap ) { const fields = this.schemaMap[singleSchemaName]!.fields.filter( - (f) => !f.computed + (f) => !f.computed && f.fieldtype !== 'Table' ); for (const field of fields) { const value = fieldValueMap[field.fieldname] as RawValue | undefined; @@ -935,7 +945,11 @@ export default class DatabaseCore extends DatabaseBase { fieldValueMap: FieldValueMap, isUpdate: boolean ) { - const parentName = fieldValueMap.name as string; + let parentName = fieldValueMap.name as string; + if (this.schemaMap[schemaName]?.isSingle) { + parentName = schemaName; + } + const tableFields = this.#getTableFields(schemaName); for (const field of tableFields) { diff --git a/backend/database/manager.ts b/backend/database/manager.ts index ba5460fd..a2b5f24f 100644 --- a/backend/database/manager.ts +++ b/backend/database/manager.ts @@ -198,7 +198,7 @@ export class DatabaseManager extends DatabaseDemuxBase { const backupFolder = path.join(path.dirname(dbPath), 'backups'); const date = new Date().toISOString().split('T')[0]; const version = await this.#getAppVersion(); - const backupFile = `${fileName}-${version}-${date}.books.db`; + const backupFile = `${fileName}_${version}_${date}.books.db`; fs.ensureDirSync(backupFolder); return path.join(backupFolder, backupFile); } diff --git a/fyo/model/doc.ts b/fyo/model/doc.ts index 9c3783f0..f9f5e2bb 100644 --- a/fyo/model/doc.ts +++ b/fyo/model/doc.ts @@ -14,7 +14,7 @@ import { TargetField, } from 'schemas/types'; import { getIsNullOrUndef, getMapFromList, getRandomString } from 'utils'; -import { markRaw } from 'vue'; +import { markRaw, reactive } from 'vue'; import { isPesa } from '../utils/index'; import { getDbSyncError } from './errorHelpers'; import { @@ -83,6 +83,7 @@ export class Doc extends Observable { this._setDefaults(); this._setValuesWithoutChecks(data, convertToDocValue); + return reactive(this) as Doc; } get schemaName(): string { diff --git a/src/components/Controls/Table.vue b/src/components/Controls/Table.vue index 7d0f82b0..899ecafc 100644 --- a/src/components/Controls/Table.vue +++ b/src/components/Controls/Table.vue @@ -155,17 +155,11 @@ export default { }, methods: { focus() {}, - addRow() { - this.doc.append(this.df.fieldname, {}).then((s) => { - if (!s) { - return; - } - - nextTick(() => { - this.scrollToRow(this.value.length - 1); - }); - this.triggerChange(this.value); - }); + async addRow() { + await this.doc.append(this.df.fieldname); + await nextTick(); + this.scrollToRow(this.value.length - 1); + this.triggerChange(this.value); }, removeRow(row) { this.doc.remove(this.df.fieldname, row.idx).then((s) => { diff --git a/src/pages/Settings/Settings.vue b/src/pages/Settings/Settings.vue index f8ccf36b..65716363 100644 --- a/src/pages/Settings/Settings.vue +++ b/src/pages/Settings/Settings.vue @@ -101,17 +101,24 @@ export default defineComponent({ data() { return { errors: {}, - canSave: false, activeTab: ModelNameEnum.AccountingSettings, groupedFields: null, } as { errors: Record; - canSave: boolean; activeTab: string; groupedFields: null | UIGroupedFields; }; }, computed: { + canSave() { + return [ + ModelNameEnum.AccountingSettings, + ModelNameEnum.InventorySettings, + ModelNameEnum.Defaults, + ModelNameEnum.PrintSettings, + ModelNameEnum.SystemSettings, + ].some((s) => this.fyo.singles[s]?.canSave); + }, doc(): Doc | null { const doc = this.fyo.singles[this.activeTab]; if (!doc) { @@ -256,14 +263,8 @@ export default defineComponent({ this.update(); }, update(): void { - this.updateCanSave(); this.updateGroupedFields(); }, - updateCanSave(): void { - this.canSave = this.schemas - .map(({ name }) => this.fyo.singles[name]?.canSave) - .some(Boolean); - }, updateGroupedFields(): void { const grouped: UIGroupedFields = new Map(); const fields: Field[] = this.schemas.map((s) => s.fields).flat();