diff --git a/fyo/core/docHandler.ts b/fyo/core/docHandler.ts index b8fded44..620849e3 100644 --- a/fyo/core/docHandler.ts +++ b/fyo/core/docHandler.ts @@ -99,7 +99,7 @@ export class DocHandler { } const doc = new Model!(schema, data, this.fyo, isRawValueMap); - doc.name ??= this.#getTemporaryName(schema); + doc.name ??= this.getTemporaryName(schema); if (cacheDoc) { this.#addToCache(doc); } @@ -107,7 +107,7 @@ export class DocHandler { return doc; } - #getTemporaryName(schema: Schema): string { + getTemporaryName(schema: Schema): string { if (schema.naming === 'random') { return getRandomString(); } diff --git a/fyo/model/doc.ts b/fyo/model/doc.ts index c5902c12..ff276114 100644 --- a/fyo/model/doc.ts +++ b/fyo/model/doc.ts @@ -454,7 +454,7 @@ export class Doc extends Observable { convertToDocValue: boolean = false ): Doc { if (!this.name && this.schema.naming !== 'manual') { - this.name = getRandomString(); + this.name = this.fyo.doc.getTemporaryName(this.schema); } docValueMap.name ??= getRandomString(); diff --git a/models/baseModels/JournalEntry/JournalEntry.ts b/models/baseModels/JournalEntry/JournalEntry.ts index dced2554..2a844ba3 100644 --- a/models/baseModels/JournalEntry/JournalEntry.ts +++ b/models/baseModels/JournalEntry/JournalEntry.ts @@ -4,9 +4,9 @@ import { Action, DefaultMap, FiltersMap, + HiddenMap, ListViewSettings, } from 'fyo/model/types'; -import { DateTime } from 'luxon'; import { getDocStatus, getLedgerLinkAction, @@ -39,6 +39,17 @@ export class JournalEntry extends Transactional { return posting; } + hidden: HiddenMap = { + referenceNumber: () => + !(this.referenceNumber || !(this.isSubmitted || this.isCancelled)), + referenceDate: () => + !(this.referenceDate || !(this.isSubmitted || this.isCancelled)), + userRemark: () => + !(this.userRemark || !(this.isSubmitted || this.isCancelled)), + attachment: () => + !(this.attachment || !(this.isSubmitted || this.isCancelled)), + }; + static defaults: DefaultMap = { numberSeries: (doc) => getNumberSeries(doc.schemaName, doc.fyo), date: () => new Date(), diff --git a/schemas/app/JournalEntry.json b/schemas/app/JournalEntry.json index cf0210a8..4a7c1f4e 100644 --- a/schemas/app/JournalEntry.json +++ b/schemas/app/JournalEntry.json @@ -4,6 +4,24 @@ "naming": "numberSeries", "isSubmittable": true, "fields": [ + { + "label": "Entry No", + "fieldname": "name", + "fieldtype": "Data", + "required": true, + "readOnly": true, + "section": "Default" + }, + { + "fieldname": "numberSeries", + "label": "Number Series", + "fieldtype": "Link", + "target": "NumberSeries", + "create": true, + "required": true, + "default": "JV-", + "section": "Default" + }, { "fieldname": "entryType", "label": "Entry Type", @@ -55,58 +73,49 @@ "label": "Depreciation Entry" } ], - "required": true - }, - { - "label": "Entry No", - "fieldname": "name", - "fieldtype": "Data", "required": true, - "readOnly": true + "section": "Default" }, { "fieldname": "date", "label": "Date", "fieldtype": "Date", - "required": true + "required": true, + "section": "Default" }, { "fieldname": "accounts", "label": "Account Entries", "fieldtype": "Table", "target": "JournalEntryAccount", - "required": true + "required": true, + "section": "Accounts" }, { "fieldname": "referenceNumber", "label": "Reference Number", - "fieldtype": "Data" + "fieldtype": "Data", + "section": "References" }, { "fieldname": "referenceDate", "label": "Reference Date", - "fieldtype": "Date" + "fieldtype": "Date", + "section": "References" }, { "fieldname": "userRemark", "label": "User Remark", "fieldtype": "Text", - "placeholder": "Add a remark" - }, - { - "fieldname": "numberSeries", - "label": "Number Series", - "fieldtype": "Link", - "target": "NumberSeries", - "create": true, - "required": true, - "default": "JV-" + "placeholder": "Add a remark", + "section": "References" }, { "fieldname": "attachment", "placeholder": "Add attachment", "label": "Attachment", - "fieldtype": "Attachment" + "fieldtype": "Attachment", + "section": "References" } ], "keywordFields": ["name", "entryType"] diff --git a/src/components/Controls/Attachment.vue b/src/components/Controls/Attachment.vue index c03ad11c..87760201 100644 --- a/src/components/Controls/Attachment.vue +++ b/src/components/Controls/Attachment.vue @@ -1,41 +1,50 @@ diff --git a/src/pages/CommonForm/CommonForm.vue b/src/pages/CommonForm/CommonForm.vue index 5dd466d4..c3a48031 100644 --- a/src/pages/CommonForm/CommonForm.vue +++ b/src/pages/CommonForm/CommonForm.vue @@ -155,7 +155,7 @@ export default defineComponent({ } await this.setDoc(); - this.groupedFields = this.getGroupedFields(); + this.updateGroupedFields(); }, computed: { hasDoc(): boolean { @@ -227,16 +227,20 @@ export default defineComponent({ }, }, methods: { - getGroupedFields(): UIGroupedFields { + updateGroupedFields(): void { if (!this.hasDoc) { - return new Map(); + return; } - return getFieldsGroupedByTabAndSection(this.schema, this.doc); + this.groupedFields = getFieldsGroupedByTabAndSection( + this.schema, + this.doc + ); }, async sync() { try { await this.doc.sync(); + this.updateGroupedFields(); } catch (err) { if (!(err instanceof Error)) { return; @@ -248,6 +252,7 @@ export default defineComponent({ async submit() { try { await this.doc.submit(); + this.updateGroupedFields(); } catch (err) { if (!(err instanceof Error)) { return; @@ -297,7 +302,7 @@ export default defineComponent({ this.errors[fieldname] = getErrorMessage(err, this.doc); } - this.groupedFields = this.getGroupedFields(); + this.updateGroupedFields(); }, }, components: { diff --git a/src/pages/CommonForm/CommonFormSection.vue b/src/pages/CommonForm/CommonFormSection.vue index 0fa80a87..dac5dce2 100644 --- a/src/pages/CommonForm/CommonFormSection.vue +++ b/src/pages/CommonForm/CommonFormSection.vue @@ -18,10 +18,11 @@
-
+
{{ errors[field.fieldname] }}
@@ -57,6 +58,24 @@ export default defineComponent({ collapsed: boolean; }; }, + mounted() { + this.focusOnNameField(); + }, + methods: { + focusOnNameField() { + const naming = this.fyo.schemaMap[this.doc.schemaName]?.naming; + if (naming !== 'manual') { + return; + } + + const nameField = (this.$refs.nameField as { focus: Function }[])?.[0]; + if (!nameField) { + return; + } + + nameField.focus(); + }, + }, components: { FormControl }, }); diff --git a/src/pages/JournalEntryForm.vue b/src/pages/JournalEntryForm.vue deleted file mode 100644 index bc884acb..00000000 --- a/src/pages/JournalEntryForm.vue +++ /dev/null @@ -1,269 +0,0 @@ - - diff --git a/src/router.ts b/src/router.ts index d9e6aaad..987de9d4 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,22 +1,21 @@ import { ModelNameEnum } from 'models/types'; import ChartOfAccounts from 'src/pages/ChartOfAccounts.vue'; +import CommonForm from 'src/pages/CommonForm/CommonForm.vue'; import Dashboard from 'src/pages/Dashboard/Dashboard.vue'; -import ImportWizard from 'src/pages/ImportWizard.vue'; import GeneralForm from 'src/pages/GeneralForm.vue'; import GetStarted from 'src/pages/GetStarted.vue'; +import ImportWizard from 'src/pages/ImportWizard.vue'; import InvoiceForm from 'src/pages/InvoiceForm.vue'; -import JournalEntryForm from 'src/pages/JournalEntryForm.vue'; import ListView from 'src/pages/ListView/ListView.vue'; import PrintView from 'src/pages/PrintView/PrintView.vue'; import QuickEditForm from 'src/pages/QuickEditForm.vue'; -import CommonForm from 'src/pages/CommonForm/CommonForm.vue'; import Report from 'src/pages/Report.vue'; import Settings from 'src/pages/Settings/Settings.vue'; import { createRouter, createWebHistory, RouteLocationRaw, - RouteRecordRaw, + RouteRecordRaw } from 'vue-router'; function getGeneralFormItems(): RouteRecordRaw[] { @@ -46,6 +45,7 @@ function getGeneralFormItems(): RouteRecordRaw[] { function getCommonFormItems(): RouteRecordRaw[] { return [ + ModelNameEnum.JournalEntry, ModelNameEnum.Payment, ModelNameEnum.StockMovement, ModelNameEnum.Item, @@ -82,25 +82,6 @@ const routes: RouteRecordRaw[] = [ }, ...getGeneralFormItems(), ...getCommonFormItems(), - { - path: '/edit/JournalEntry/:name', - name: 'JournalEntryForm', - components: { - default: JournalEntryForm, - edit: QuickEditForm, - }, - props: { - default: (route) => { - // for sidebar item active state - route.params.schemaName = 'JournalEntry'; - return { - schemaName: 'JournalEntry', - name: route.params.name, - }; - }, - edit: (route) => route.query, - }, - }, { path: '/edit/:schemaName/:name', name: 'InvoiceForm',