2
0
mirror of https://github.com/frappe/books.git synced 2025-01-04 23:55:24 +00:00

fix: allow single value child tables

This commit is contained in:
18alantom 2023-07-13 12:48:27 +05:30
parent 8d8d9ee06e
commit 319466ae04
5 changed files with 34 additions and 24 deletions

View File

@ -774,7 +774,17 @@ export default class DatabaseCore extends DatabaseBase {
order: 'asc', 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) { #insertOne(schemaName: string, fieldValueMap: FieldValueMap) {
@ -800,7 +810,7 @@ export default class DatabaseCore extends DatabaseBase {
fieldValueMap: FieldValueMap fieldValueMap: FieldValueMap
) { ) {
const fields = this.schemaMap[singleSchemaName]!.fields.filter( const fields = this.schemaMap[singleSchemaName]!.fields.filter(
(f) => !f.computed (f) => !f.computed && f.fieldtype !== 'Table'
); );
for (const field of fields) { for (const field of fields) {
const value = fieldValueMap[field.fieldname] as RawValue | undefined; const value = fieldValueMap[field.fieldname] as RawValue | undefined;
@ -935,7 +945,11 @@ export default class DatabaseCore extends DatabaseBase {
fieldValueMap: FieldValueMap, fieldValueMap: FieldValueMap,
isUpdate: boolean 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); const tableFields = this.#getTableFields(schemaName);
for (const field of tableFields) { for (const field of tableFields) {

View File

@ -198,7 +198,7 @@ export class DatabaseManager extends DatabaseDemuxBase {
const backupFolder = path.join(path.dirname(dbPath), 'backups'); const backupFolder = path.join(path.dirname(dbPath), 'backups');
const date = new Date().toISOString().split('T')[0]; const date = new Date().toISOString().split('T')[0];
const version = await this.#getAppVersion(); const version = await this.#getAppVersion();
const backupFile = `${fileName}-${version}-${date}.books.db`; const backupFile = `${fileName}_${version}_${date}.books.db`;
fs.ensureDirSync(backupFolder); fs.ensureDirSync(backupFolder);
return path.join(backupFolder, backupFile); return path.join(backupFolder, backupFile);
} }

View File

@ -14,7 +14,7 @@ import {
TargetField, TargetField,
} from 'schemas/types'; } from 'schemas/types';
import { getIsNullOrUndef, getMapFromList, getRandomString } from 'utils'; import { getIsNullOrUndef, getMapFromList, getRandomString } from 'utils';
import { markRaw } from 'vue'; import { markRaw, reactive } from 'vue';
import { isPesa } from '../utils/index'; import { isPesa } from '../utils/index';
import { getDbSyncError } from './errorHelpers'; import { getDbSyncError } from './errorHelpers';
import { import {
@ -83,6 +83,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
this._setDefaults(); this._setDefaults();
this._setValuesWithoutChecks(data, convertToDocValue); this._setValuesWithoutChecks(data, convertToDocValue);
return reactive(this) as Doc;
} }
get schemaName(): string { get schemaName(): string {

View File

@ -155,17 +155,11 @@ export default {
}, },
methods: { methods: {
focus() {}, focus() {},
addRow() { async addRow() {
this.doc.append(this.df.fieldname, {}).then((s) => { await this.doc.append(this.df.fieldname);
if (!s) { await nextTick();
return; this.scrollToRow(this.value.length - 1);
} this.triggerChange(this.value);
nextTick(() => {
this.scrollToRow(this.value.length - 1);
});
this.triggerChange(this.value);
});
}, },
removeRow(row) { removeRow(row) {
this.doc.remove(this.df.fieldname, row.idx).then((s) => { this.doc.remove(this.df.fieldname, row.idx).then((s) => {

View File

@ -101,17 +101,24 @@ export default defineComponent({
data() { data() {
return { return {
errors: {}, errors: {},
canSave: false,
activeTab: ModelNameEnum.AccountingSettings, activeTab: ModelNameEnum.AccountingSettings,
groupedFields: null, groupedFields: null,
} as { } as {
errors: Record<string, string>; errors: Record<string, string>;
canSave: boolean;
activeTab: string; activeTab: string;
groupedFields: null | UIGroupedFields; groupedFields: null | UIGroupedFields;
}; };
}, },
computed: { computed: {
canSave() {
return [
ModelNameEnum.AccountingSettings,
ModelNameEnum.InventorySettings,
ModelNameEnum.Defaults,
ModelNameEnum.PrintSettings,
ModelNameEnum.SystemSettings,
].some((s) => this.fyo.singles[s]?.canSave);
},
doc(): Doc | null { doc(): Doc | null {
const doc = this.fyo.singles[this.activeTab]; const doc = this.fyo.singles[this.activeTab];
if (!doc) { if (!doc) {
@ -256,14 +263,8 @@ export default defineComponent({
this.update(); this.update();
}, },
update(): void { update(): void {
this.updateCanSave();
this.updateGroupedFields(); this.updateGroupedFields();
}, },
updateCanSave(): void {
this.canSave = this.schemas
.map(({ name }) => this.fyo.singles[name]?.canSave)
.some(Boolean);
},
updateGroupedFields(): void { updateGroupedFields(): void {
const grouped: UIGroupedFields = new Map(); const grouped: UIGroupedFields = new Map();
const fields: Field[] = this.schemas.map((s) => s.fields).flat(); const fields: Field[] = this.schemas.map((s) => s.fields).flat();