2
0
mirror of https://github.com/frappe/books.git synced 2024-09-18 18:49:01 +00:00

fix: allow single value child tables

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

View File

@ -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) {

View File

@ -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);
}

View File

@ -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<DocValue | Doc[]> {
this._setDefaults();
this._setValuesWithoutChecks(data, convertToDocValue);
return reactive(this) as Doc;
}
get schemaName(): string {

View File

@ -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) => {

View File

@ -101,17 +101,24 @@ export default defineComponent({
data() {
return {
errors: {},
canSave: false,
activeTab: ModelNameEnum.AccountingSettings,
groupedFields: null,
} as {
errors: Record<string, string>;
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();