diff --git a/fyo/core/docHandler.ts b/fyo/core/docHandler.ts index 2b98b88b..620849e3 100644 --- a/fyo/core/docHandler.ts +++ b/fyo/core/docHandler.ts @@ -14,9 +14,11 @@ export class DocHandler { singles: SinglesMap = {}; docs: Observable = new Observable(); observer: Observable = new Observable(); + #temporaryNameCounters: Record; constructor(fyo: Fyo) { this.fyo = fyo; + this.#temporaryNameCounters = {}; } init() { @@ -97,7 +99,7 @@ export class DocHandler { } const doc = new Model!(schema, data, this.fyo, isRawValueMap); - doc.name ??= getRandomString(); + doc.name ??= this.getTemporaryName(schema); if (cacheDoc) { this.#addToCache(doc); } @@ -105,6 +107,22 @@ export class DocHandler { return doc; } + getTemporaryName(schema: Schema): string { + if (schema.naming === 'random') { + return getRandomString(); + } + + this.#temporaryNameCounters[schema.name] ??= 1; + + const idx = this.#temporaryNameCounters[schema.name]; + this.#temporaryNameCounters[schema.name] = idx + 1; + + return this.fyo.t`New ${schema.label ?? schema.name} ${String(idx).padStart( + 2, + '0' + )}`; + } + /** * Cache operations */ diff --git a/fyo/model/doc.ts b/fyo/model/doc.ts index 18128bfd..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(); @@ -868,9 +868,9 @@ export class Doc extends Observable { } async _insert() { - await setName(this, this.fyo); this._setBaseMetaValues(); await this._preSync(); + await setName(this, this.fyo); const validDict = this.getValidDict(false, true); let data: DocValueMap; diff --git a/models/baseModels/Item/Item.ts b/models/baseModels/Item/Item.ts index 61db702b..58b80747 100644 --- a/models/baseModels/Item/Item.ts +++ b/models/baseModels/Item/Item.ts @@ -111,6 +111,7 @@ export class Item extends Doc { static getListViewSettings(): ListViewSettings { return { + formRoute: ({ name }) => `/edit/Item/${name}`, columns: ['name', 'unit', 'tax', 'rate'], }; } 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/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index 0f928138..176b7e95 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -617,6 +617,7 @@ export class Payment extends Transactional { static getListViewSettings(fyo: Fyo): ListViewSettings { return { + formRoute: ({ name }) => `/edit/Payment/${name}`, columns: ['name', getDocStatusListColumn(), 'party', 'date', 'amount'], }; } diff --git a/models/inventory/StockMovement.ts b/models/inventory/StockMovement.ts index 2a157e83..b6d19a65 100644 --- a/models/inventory/StockMovement.ts +++ b/models/inventory/StockMovement.ts @@ -75,6 +75,7 @@ export class StockMovement extends Transfer { static getListViewSettings(fyo: Fyo): ListViewSettings { return { + formRoute: ({ name }) => `/edit/StockMovement/${name}`, columns: [ 'name', getDocStatusListColumn(), diff --git a/models/inventory/StockTransfer.ts b/models/inventory/StockTransfer.ts index ae0f992b..fce4f61e 100644 --- a/models/inventory/StockTransfer.ts +++ b/models/inventory/StockTransfer.ts @@ -1,7 +1,13 @@ import { Fyo, t } from 'fyo'; import { Attachment } from 'fyo/core/types'; import { Doc } from 'fyo/model/doc'; -import { Action, DefaultMap, FiltersMap, FormulaMap } from 'fyo/model/types'; +import { + Action, + DefaultMap, + FiltersMap, + FormulaMap, + HiddenMap, +} from 'fyo/model/types'; import { ValidationError } from 'fyo/utils/errors'; import { Defaults } from 'models/baseModels/Defaults/Defaults'; import { Invoice } from 'models/baseModels/Invoice/Invoice'; @@ -33,6 +39,14 @@ export abstract class StockTransfer extends Transfer { }, }; + hidden: HiddenMap = { + backReference: () => + !(this.backReference || !(this.isSubmitted || this.isCancelled)), + terms: () => !(this.terms || !(this.isSubmitted || this.isCancelled)), + attachment: () => + !(this.attachment || !(this.isSubmitted || this.isCancelled)), + }; + static defaults: DefaultMap = { numberSeries: (doc) => getNumberSeries(doc.schemaName, doc.fyo), terms: (doc) => { diff --git a/schemas/app/Item.json b/schemas/app/Item.json index b9d81b9d..deb74828 100644 --- a/schemas/app/Item.json +++ b/schemas/app/Item.json @@ -4,50 +4,20 @@ "isSingle": false, "naming": "manual", "fields": [ + { + "fieldname": "image", + "label": "Image", + "section": "Default", + "fieldtype": "AttachImage" + }, { "fieldname": "name", "label": "Item Name", "fieldtype": "Data", "placeholder": "Item Name", + "section": "Default", "required": true }, - { - "fieldname": "image", - "label": "Image", - "fieldtype": "AttachImage" - }, - { - "fieldname": "description", - "label": "Description", - "placeholder": "Item Description", - "fieldtype": "Text" - }, - { - "fieldname": "unit", - "label": "Unit Type", - "fieldtype": "Link", - "target": "UOM", - "create": true, - "default": "Unit", - "placeholder": "Unit Type" - }, - { - "fieldname": "itemType", - "label": "Type", - "placeholder": "Type", - "fieldtype": "Select", - "default": "Product", - "options": [ - { - "value": "Product", - "label": "Product" - }, - { - "value": "Service", - "label": "Service" - } - ] - }, { "fieldname": "for", "label": "For", @@ -67,14 +37,57 @@ } ], "required": true, + "section": "Default", "default": "Both" }, + { + "fieldname": "itemType", + "label": "Type", + "placeholder": "Type", + "fieldtype": "Select", + "default": "Product", + "section": "Default", + "options": [ + { + "value": "Product", + "label": "Product" + }, + { + "value": "Service", + "label": "Service" + } + ] + }, + { + "fieldname": "unit", + "label": "Unit Type", + "fieldtype": "Link", + "target": "UOM", + "create": true, + "default": "Unit", + "section": "Details", + "placeholder": "Unit Type" + }, + { + "fieldname": "rate", + "label": "Rate", + "section": "Details", + "fieldtype": "Currency" + }, + { + "fieldname": "description", + "label": "Description", + "placeholder": "Item Description", + "section": "Details", + "fieldtype": "Text" + }, { "fieldname": "incomeAccount", "label": "Sales Acc.", "fieldtype": "Link", "target": "Account", "placeholder": "Income", + "section": "Accounts", "create": true, "required": true }, @@ -84,6 +97,7 @@ "fieldtype": "Link", "target": "Account", "placeholder": "Expense", + "section": "Accounts", "create": true, "required": true }, @@ -92,31 +106,30 @@ "label": "Tax", "fieldtype": "Link", "target": "Tax", + "section": "Accounts", "create": true, "placeholder": "Tax" }, - { - "fieldname": "rate", - "label": "Rate", - "fieldtype": "Currency" - }, { "fieldname": "hsnCode", "label": "HSN/SAC", "fieldtype": "Int", - "placeholder": "HSN/SAC Code" + "placeholder": "HSN/SAC Code", + "section": "Inventory" }, { "fieldname": "barcode", "label": "Barcode", "fieldtype": "Data", - "placeholder": "Barcode" + "placeholder": "Barcode", + "section": "Inventory" }, { "fieldname": "trackItem", "label": "Track Item", "fieldtype": "Check", - "default": false + "default": false, + "section": "Inventory" } ], "quickEditFields": [ 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/schemas/app/Party.json b/schemas/app/Party.json index 820efd1d..2ee7d547 100644 --- a/schemas/app/Party.json +++ b/schemas/app/Party.json @@ -46,7 +46,8 @@ { "fieldname": "outstandingAmount", "label": "Outstanding Amount", - "fieldtype": "Currency" + "fieldtype": "Currency", + "hidden": true }, { "fieldname": "currency", diff --git a/schemas/app/Payment.json b/schemas/app/Payment.json index c9e44c3e..336a9e8c 100644 --- a/schemas/app/Payment.json +++ b/schemas/app/Payment.json @@ -11,7 +11,18 @@ "fieldname": "name", "fieldtype": "Data", "required": true, - "readOnly": true + "readOnly": true, + "section": "Default" + }, + { + "fieldname": "numberSeries", + "label": "Number Series", + "fieldtype": "Link", + "target": "NumberSeries", + "create": true, + "required": true, + "default": "PAY-", + "section": "Default" }, { "fieldname": "party", @@ -19,13 +30,15 @@ "fieldtype": "Link", "target": "Party", "create": true, - "required": true + "required": true, + "section": "Default" }, { "fieldname": "date", "label": "Posting Date", "fieldtype": "Date", - "required": true + "required": true, + "section": "Default" }, { "fieldname": "paymentType", @@ -42,16 +55,27 @@ "label": "Pay" } ], - "required": true + "required": true, + "section": "Default" }, { - "fieldname": "numberSeries", - "label": "Number Series", + "fieldname": "account", + "label": "From Account", "fieldtype": "Link", - "target": "NumberSeries", + "target": "Account", "create": true, "required": true, - "default": "PAY-" + "section": "Details" + }, + { + "fieldname": "paymentAccount", + "label": "To Account", + "placeholder": "To Account", + "fieldtype": "Link", + "target": "Account", + "create": true, + "required": true, + "section": "Details" }, { "fieldname": "paymentMethod", @@ -73,72 +97,64 @@ } ], "default": "Cash", - "required": true - }, - { - "fieldname": "account", - "label": "From Account", - "fieldtype": "Link", - "target": "Account", - "create": true, - "required": true - }, - { - "fieldname": "paymentAccount", - "label": "To Account", - "placeholder": "To Account", - "fieldtype": "Link", - "target": "Account", - "create": true, - "required": true - }, - { - "fieldname": "referenceId", - "label": "Ref. / Cheque No.", - "placeholder": "Ref. / Cheque No.", - "fieldtype": "Data" - }, - { - "fieldname": "referenceDate", - "label": "Ref. Date", - "placeholder": "Ref. Date", - "fieldtype": "Date" + "required": true, + "section": "Details" }, { "fieldname": "clearanceDate", "label": "Clearance Date", "placeholder": "Clearance Date", - "fieldtype": "Date" + "fieldtype": "Date", + "section": "Details" + }, + { + "fieldname": "referenceId", + "label": "Ref. / Cheque No.", + "placeholder": "Ref. / Cheque No.", + "fieldtype": "Data", + "section": "Details" + }, + { + "fieldname": "referenceDate", + "label": "Reference Date", + "placeholder": "Ref. Date", + "fieldtype": "Date", + "section": "Details" }, { "fieldname": "amount", "label": "Amount", "fieldtype": "Currency", - "required": true + "required": true, + "section": "Amounts" }, { "fieldname": "writeoff", "label": "Write Off", - "fieldtype": "Currency" + "fieldtype": "Currency", + "section": "Amounts" }, { "fieldname": "amountPaid", "label": "Amount Paid", "fieldtype": "Currency", - "computed": true + "computed": true, + "section": "Amounts" }, { "fieldname": "for", "label": "Payment Reference", "fieldtype": "Table", "target": "PaymentFor", - "required": false + "required": false, + "section": "References" }, { "fieldname": "attachment", "placeholder": "Add attachment", "label": "Attachment", - "fieldtype": "Attachment" + "fieldtype": "Attachment", + "section": "References" } ], "quickEditFields": [ diff --git a/schemas/app/inventory/PurchaseReceipt.json b/schemas/app/inventory/PurchaseReceipt.json index 33fcebfa..7b051053 100644 --- a/schemas/app/inventory/PurchaseReceipt.json +++ b/schemas/app/inventory/PurchaseReceipt.json @@ -5,14 +5,6 @@ "naming": "numberSeries", "showTitle": true, "fields": [ - { - "fieldname": "items", - "label": "Items", - "fieldtype": "Table", - "target": "PurchaseReceiptItem", - "required": true, - "edit": true - }, { "fieldname": "numberSeries", "label": "Number Series", @@ -20,14 +12,24 @@ "target": "NumberSeries", "create": true, "required": true, - "default": "PREC-" + "default": "PREC-", + "section": "Default" }, { "fieldname": "backReference", "label": "Back Reference", "fieldtype": "Link", "target": "PurchaseInvoice", - "readOnly": true + "readOnly": true, + "section": "References" + }, + { + "fieldname": "items", + "label": "Items", + "fieldtype": "Table", + "target": "PurchaseReceiptItem", + "required": true, + "edit": true } ], "keywordFields": ["name", "party"] diff --git a/schemas/app/inventory/Shipment.json b/schemas/app/inventory/Shipment.json index 10df12dd..242a0d64 100644 --- a/schemas/app/inventory/Shipment.json +++ b/schemas/app/inventory/Shipment.json @@ -5,14 +5,6 @@ "naming": "numberSeries", "showTitle": true, "fields": [ - { - "fieldname": "items", - "label": "Items", - "fieldtype": "Table", - "target": "ShipmentItem", - "required": true, - "edit": true - }, { "fieldname": "numberSeries", "label": "Number Series", @@ -20,14 +12,25 @@ "target": "NumberSeries", "create": true, "required": true, - "default": "SHPM-" + "default": "SHPM-", + "section": "Default" }, { "fieldname": "backReference", "label": "Back Reference", "fieldtype": "Link", "target": "SalesInvoice", - "readOnly": true + "readOnly": true, + "section": "References" + }, + { + "fieldname": "items", + "label": "Items", + "fieldtype": "Table", + "target": "ShipmentItem", + "required": true, + "edit": true, + "section": "Items" } ], "keywordFields": ["name", "party"] diff --git a/schemas/app/inventory/StockMovement.json b/schemas/app/inventory/StockMovement.json index 99651250..9c6ed7cc 100644 --- a/schemas/app/inventory/StockMovement.json +++ b/schemas/app/inventory/StockMovement.json @@ -11,13 +11,18 @@ "fieldname": "name", "fieldtype": "Data", "required": true, - "readOnly": true + "readOnly": true, + "section": "Default" }, { - "fieldname": "date", - "label": "Date", - "fieldtype": "Datetime", - "required": true + "fieldname": "numberSeries", + "label": "Number Series", + "fieldtype": "Link", + "target": "NumberSeries", + "create": true, + "required": true, + "default": "SMOV-", + "section": "Default" }, { "fieldname": "movementType", @@ -41,29 +46,30 @@ "label": "Manufacture" } ], - "required": true - }, - { - "fieldname": "numberSeries", - "label": "Number Series", - "fieldtype": "Link", - "target": "NumberSeries", - "create": true, "required": true, - "default": "SMOV-" + "section": "Default" }, { - "fieldname": "amount", - "label": "Total Amount", - "fieldtype": "Currency", - "readOnly": true + "fieldname": "date", + "label": "Date", + "fieldtype": "Datetime", + "required": true, + "section": "Default" }, { "fieldname": "items", "label": "Items", "fieldtype": "Table", "target": "StockMovementItem", - "required": true + "required": true, + "section": "Items" + }, + { + "fieldname": "amount", + "label": "Total Amount", + "fieldtype": "Currency", + "readOnly": true, + "section": "Items" } ], "quickEditFields": [ diff --git a/schemas/app/inventory/StockTransfer.json b/schemas/app/inventory/StockTransfer.json index c2fa869a..de7f15c2 100644 --- a/schemas/app/inventory/StockTransfer.json +++ b/schemas/app/inventory/StockTransfer.json @@ -11,13 +11,13 @@ "fieldname": "name", "fieldtype": "Data", "required": true, - "readOnly": true + "readOnly": true, + "section": "Default" }, { - "fieldname": "date", - "label": "Date", - "fieldtype": "Datetime", - "required": true + "abstract": true, + "fieldname": "numberSeries", + "section": "Default" }, { "fieldname": "party", @@ -25,25 +25,46 @@ "fieldtype": "Link", "target": "Party", "create": true, - "required": true + "required": true, + "section": "Default" }, { - "fieldname": "terms", - "label": "Notes", - "placeholder": "Add transfer terms", - "fieldtype": "Text" + "fieldname": "date", + "label": "Date", + "fieldtype": "Datetime", + "required": true, + "section": "Default" }, { - "fieldname": "attachment", - "placeholder": "Add attachment", - "label": "Attachment", - "fieldtype": "Attachment" + "abstract": true, + "fieldname": "items", + "section": "Items" }, { "fieldname": "grandTotal", "label": "Grand Total", "fieldtype": "Currency", - "readOnly": true + "readOnly": true, + "section": "Items" + }, + { + "fieldname": "terms", + "label": "Notes", + "placeholder": "Add transfer terms", + "fieldtype": "Text", + "section": "References" + }, + { + "fieldname": "attachment", + "placeholder": "Add attachment", + "label": "Attachment", + "fieldtype": "Attachment", + "section": "References" + }, + { + "abstract": true, + "fieldname": "backReference", + "section": "References" } ], "keywordFields": ["name", "party"] diff --git a/schemas/meta/base.json b/schemas/meta/base.json index c596594b..763a3dbe 100644 --- a/schemas/meta/base.json +++ b/schemas/meta/base.json @@ -6,28 +6,32 @@ "label": "Created By", "fieldtype": "Data", "required": true, - "meta": true + "meta": true, + "section": "System" }, { "fieldname": "modifiedBy", "label": "Modified By", "fieldtype": "Data", "required": true, - "meta": true + "meta": true, + "section": "System" }, { "fieldname": "created", "label": "Created", "fieldtype": "Datetime", "required": true, - "meta": true + "meta": true, + "section": "System" }, { "fieldname": "modified", "label": "Modified", "fieldtype": "Datetime", "required": true, - "meta": true + "meta": true, + "section": "System" } ] } diff --git a/schemas/meta/submittable.json b/schemas/meta/submittable.json index dbe6e524..f02772ac 100644 --- a/schemas/meta/submittable.json +++ b/schemas/meta/submittable.json @@ -6,14 +6,16 @@ "label": "Submitted", "fieldtype": "Check", "required": true, - "meta": true + "meta": true, + "section": "System" }, { "fieldname": "cancelled", "label": "Cancelled", "fieldtype": "Check", "required": true, - "meta": true + "meta": true, + "section": "System" } ] } diff --git a/schemas/types.ts b/schemas/types.ts index 2cf49c28..f542bdf3 100644 --- a/schemas/types.ts +++ b/schemas/types.ts @@ -64,6 +64,9 @@ export interface BaseField { inline?: boolean; // UI Facing config, whether to display doc inline. filter?: boolean; // UI Facing config, whether to be used to filter the List. computed?: boolean; // Computed values are not stored in the database. + section?: string; // UI Facing config, for grouping by sections + tab?: string; // UI Facing config, for grouping by tabs + abstract?: string; // Uused to mark the location of a field in an Abstract schema } export type SelectOption = { value: string; label: string }; 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/components/Controls/Color.vue b/src/components/Controls/Color.vue index 4d5ac6c0..88fb579f 100644 --- a/src/components/Controls/Color.vue +++ b/src/components/Controls/Color.vue @@ -28,7 +28,7 @@ @@ -101,6 +107,10 @@ export default { type: Number, default: 3, }, + border: { + type: Boolean, + default: false, + }, }, components: { Row, diff --git a/src/components/Controls/TableRow.vue b/src/components/Controls/TableRow.vue index bef30b88..638a4cc0 100644 --- a/src/components/Controls/TableRow.vue +++ b/src/components/Controls/TableRow.vue @@ -4,7 +4,6 @@ class=" w-full px-2 - border-b hover:bg-gray-25 group flex diff --git a/src/components/FormHeader.vue b/src/components/FormHeader.vue index 7664dd0b..993f1919 100644 --- a/src/components/FormHeader.vue +++ b/src/components/FormHeader.vue @@ -8,6 +8,7 @@ justify-between h-row-large items-center + flex-shrink-0 " >

{{ formTitle }}

diff --git a/src/components/Row.vue b/src/components/Row.vue index 4bad1f25..e83079f5 100644 --- a/src/components/Row.vue +++ b/src/components/Row.vue @@ -1,5 +1,5 @@ diff --git a/src/components/Widgets/LinkedEntryWidget.vue b/src/components/Widgets/LinkedEntryWidget.vue index 6a39eecd..9289eb86 100644 --- a/src/components/Widgets/LinkedEntryWidget.vue +++ b/src/components/Widgets/LinkedEntryWidget.vue @@ -56,7 +56,7 @@ diff --git a/src/pages/CommonForm/CommonFormSection.vue b/src/pages/CommonForm/CommonFormSection.vue new file mode 100644 index 00000000..dac5dce2 --- /dev/null +++ b/src/pages/CommonForm/CommonFormSection.vue @@ -0,0 +1,81 @@ + + diff --git a/src/pages/GeneralForm.vue b/src/pages/GeneralForm.vue deleted file mode 100644 index ed92a0b1..00000000 --- a/src/pages/GeneralForm.vue +++ /dev/null @@ -1,320 +0,0 @@ - - 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/pages/ListView/List.vue b/src/pages/ListView/List.vue index db5dcc37..192328b2 100644 --- a/src/pages/ListView/List.vue +++ b/src/pages/ListView/List.vue @@ -9,7 +9,7 @@ >

#

@@ -45,7 +45,7 @@

diff --git a/src/router.ts b/src/router.ts index 5f862a01..73d4370b 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,11 +1,10 @@ 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'; @@ -18,29 +17,34 @@ import { RouteRecordRaw, } from 'vue-router'; -function getGeneralFormItems(): RouteRecordRaw[] { - return [ModelNameEnum.Shipment, ModelNameEnum.PurchaseReceipt].map( - (schemaName) => { - return { - path: `/edit/${schemaName}/:name`, - name: `${schemaName}Form`, - components: { - default: GeneralForm, - edit: QuickEditForm, +function getCommonFormItems(): RouteRecordRaw[] { + return [ + ModelNameEnum.Shipment, + ModelNameEnum.PurchaseReceipt, + ModelNameEnum.JournalEntry, + ModelNameEnum.Payment, + ModelNameEnum.StockMovement, + ModelNameEnum.Item, + ].map((schemaName) => { + return { + path: `/edit/${schemaName}/:name`, + name: `${schemaName}Form`, + components: { + default: CommonForm, + edit: QuickEditForm, + }, + props: { + default: (route) => { + route.params.schemaName = schemaName; + return { + schemaName, + name: route.params.name, + }; }, - props: { - default: (route) => { - route.params.schemaName = schemaName; - return { - schemaName, - name: route.params.name, - }; - }, - edit: (route) => route.query, - }, - }; - } - ); + edit: (route) => route.query, + }, + }; + }); } const routes: RouteRecordRaw[] = [ @@ -52,26 +56,7 @@ const routes: RouteRecordRaw[] = [ path: '/get-started', component: GetStarted, }, - ...getGeneralFormItems(), - { - 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, - }, - }, + ...getCommonFormItems(), { path: '/edit/:schemaName/:name', name: 'InvoiceForm', @@ -167,6 +152,9 @@ export function getCreateRoute( ModelNameEnum.JournalEntry, ModelNameEnum.Shipment, ModelNameEnum.PurchaseReceipt, + ModelNameEnum.StockMovement, + ModelNameEnum.Payment, + ModelNameEnum.Item, ].includes(schemaName as ModelNameEnum) ) { return `/edit/${schemaName}/${name}`; diff --git a/src/utils/search.ts b/src/utils/search.ts index 95eb60cd..05832e73 100644 --- a/src/utils/search.ts +++ b/src/utils/search.ts @@ -93,25 +93,16 @@ async function openFormEditDoc(schemaName: string, fyo: Fyo) { function getCreateList(fyo: Fyo): SearchItem[] { const hasInventory = fyo.doc.singles.AccountingSettings?.enableInventory; - const quickEditCreateList = [ - ...(hasInventory ? [ModelNameEnum.StockMovement] : []), - ].map( - (schemaName) => - ({ - label: fyo.schemaMap[schemaName]?.label, - group: 'Create', - action() { - openQuickEditDoc(schemaName, fyo); - }, - } as SearchItem) - ); - const formEditCreateList = [ ModelNameEnum.SalesInvoice, ModelNameEnum.PurchaseInvoice, ModelNameEnum.JournalEntry, ...(hasInventory - ? [ModelNameEnum.Shipment, ModelNameEnum.PurchaseReceipt] + ? [ + ModelNameEnum.Shipment, + ModelNameEnum.PurchaseReceipt, + ModelNameEnum.StockMovement, + ] : []), ].map( (schemaName) => @@ -197,7 +188,7 @@ function getCreateList(fyo: Fyo): SearchItem[] { } as SearchItem; }); - return [quickEditCreateList, formEditCreateList, filteredCreateList].flat(); + return [formEditCreateList, filteredCreateList].flat(); } function getReportList(fyo: Fyo): SearchItem[] { diff --git a/src/utils/types.ts b/src/utils/types.ts index 00e6c1a4..e24702ac 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -1,6 +1,7 @@ -import { Doc } from "fyo/model/doc"; -import { FieldType } from "schemas/types"; -import { QueryFilter } from "utils/db/types"; +import type { Doc } from 'fyo/model/doc'; +import type { Action } from 'fyo/model/types'; +import type { Field, FieldType } from 'schemas/types'; +import type { QueryFilter } from 'utils/db/types'; export interface MessageDialogButton { label: string; @@ -31,7 +32,7 @@ export interface QuickEditOptions { hideFields?: string[]; showFields?: string[]; defaults?: Record; - listFilters?: QueryFilter + listFilters?: QueryFilter; } export type SidebarConfig = SidebarRoot[]; @@ -44,7 +45,7 @@ export interface SidebarRoot { iconHeight?: string; hidden?: () => boolean; items?: SidebarItem[]; - filters?: QueryFilter + filters?: QueryFilter; } export interface SidebarItem { @@ -55,7 +56,6 @@ export interface SidebarItem { hidden?: () => boolean; } - export interface ExportField { fieldname: string; fieldtype: FieldType; @@ -70,5 +70,13 @@ export interface ExportTableField { fields: ExportField[]; } +export type ActionGroup = { + group: string; + label: string; + type: string; + actions: Action[]; +}; + +export type UIGroupedFields = Map>; export type ExportFormat = 'csv' | 'json'; -export type PeriodKey = 'This Year' | 'This Quarter' | 'This Month' \ No newline at end of file +export type PeriodKey = 'This Year' | 'This Quarter' | 'This Month'; diff --git a/src/utils/ui.ts b/src/utils/ui.ts index 38a59c55..0f1013a6 100644 --- a/src/utils/ui.ts +++ b/src/utils/ui.ts @@ -9,6 +9,7 @@ import { Action } from 'fyo/model/types'; import { getActions } from 'fyo/utils'; import { getDbError, LinkValidationError, ValueError } from 'fyo/utils/errors'; import { ModelNameEnum } from 'models/types'; +import { Schema } from 'schemas/types'; import { handleErrorWithDialog } from 'src/errorHandling'; import { fyo } from 'src/initFyo'; import router from 'src/router'; @@ -16,11 +17,14 @@ import { IPC_ACTIONS } from 'utils/messages'; import { App, createApp, h, ref } from 'vue'; import { RouteLocationRaw } from 'vue-router'; import { stringifyCircular } from './'; +import { evaluateHidden } from './doc'; import { + ActionGroup, MessageDialogOptions, QuickEditOptions, SettingsTab, ToastOptions, + UIGroupedFields, } from './types'; export async function openQuickEdit({ @@ -70,6 +74,7 @@ export async function openQuickEdit({ if (forWhat[0] === 'not in' && forWhat[1] === 'Sales') { defaults = Object.assign({ for: 'Purchases' }); } + console.log(method, schemaName, name); router[method]({ query: { @@ -274,14 +279,7 @@ export function getActionsForDoc(doc?: Doc): Action[] { }); } -export function getGroupedActionsForDoc(doc?: Doc) { - type Group = { - group: string; - label: string; - type: string; - actions: Action[]; - }; - +export function getGroupedActionsForDoc(doc?: Doc): ActionGroup[] { const actions = getActionsForDoc(doc); const actionsMap = actions.reduce((acc, ac) => { if (!ac.group) { @@ -297,7 +295,7 @@ export function getGroupedActionsForDoc(doc?: Doc) { acc[ac.group].actions.push(ac); return acc; - }, {} as Record); + }, {} as Record); const grouped = Object.keys(actionsMap) .filter(Boolean) @@ -393,14 +391,33 @@ function getDuplicateAction(doc: Doc): Action { }; } -export function getStatus(entry: { cancelled?: boolean; submitted?: boolean }) { - if (entry.cancelled) { - return 'Cancelled'; +export function getFieldsGroupedByTabAndSection( + schema: Schema, + doc: Doc +): UIGroupedFields { + const grouped: UIGroupedFields = new Map(); + for (const field of schema?.fields ?? []) { + const tab = field.tab ?? 'Default'; + const section = field.section ?? 'Default'; + if (!grouped.has(tab)) { + grouped.set(tab, new Map()); + } + + const tabbed = grouped.get(tab)!; + if (!tabbed.has(section)) { + tabbed.set(section, []); + } + + if (field.meta) { + continue; + } + + if (evaluateHidden(field, doc)) { + continue; + } + + tabbed.get(section)!.push(field); } - if (entry.submitted) { - return 'Submitted'; - } - - return 'Saved'; + return grouped; } diff --git a/utils/translationHelpers.ts b/utils/translationHelpers.ts index c354d7e5..36fbaf03 100644 --- a/utils/translationHelpers.ts +++ b/utils/translationHelpers.ts @@ -2,7 +2,13 @@ * Properties of a schema which are to be translated, * irrespective of nesting. */ -export const schemaTranslateables = ['label', 'description', 'placeholder']; +export const schemaTranslateables = [ + 'label', + 'description', + 'placeholder', + 'section', + 'tab', +]; export function getIndexFormat(inp: string | string[]) { /**