From 185110276da28ed03c17476414a8b0f214cce1ad Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 2 May 2022 11:01:11 +0530 Subject: [PATCH] feat: add more search items - fix a few actions - fix listview page titles --- models/baseModels/Item/Item.ts | 8 +-- models/baseModels/Party/Party.ts | 32 ++++------ schemas/app/Item.json | 1 + src/components/Dropdown.vue | 10 +++- src/components/DropdownWithActions.vue | 2 + src/components/SearchBar.vue | 3 +- src/components/Sidebar.vue | 1 + src/pages/ListView/ListView.vue | 8 ++- src/router.ts | 9 +-- src/utils/search.ts | 83 +++++++++++++++++++++++--- src/utils/sidebarConfig.ts | 10 ++-- 11 files changed, 119 insertions(+), 48 deletions(-) diff --git a/models/baseModels/Item/Item.ts b/models/baseModels/Item/Item.ts index f8d9068f..121db713 100644 --- a/models/baseModels/Item/Item.ts +++ b/models/baseModels/Item/Item.ts @@ -66,8 +66,8 @@ export class Item extends Doc { static getActions(fyo: Fyo): Action[] { return [ { - label: fyo.t`New Invoice`, - condition: (doc) => !doc.notInserted, + label: fyo.t`New Sale`, + condition: (doc) => !doc.notInserted && doc.for !== 'purchases', action: async (doc, router) => { const invoice = await fyo.doc.getNewDoc('SalesInvoice'); await invoice.append('items', { @@ -79,8 +79,8 @@ export class Item extends Doc { }, }, { - label: fyo.t`New Bill`, - condition: (doc) => !doc.notInserted, + label: fyo.t`New Purchase`, + condition: (doc) => !doc.notInserted && doc.for !== 'sales', action: async (doc, router) => { const invoice = await fyo.doc.getNewDoc('PurchaseInvoice'); await invoice.append('items', { diff --git a/models/baseModels/Party/Party.ts b/models/baseModels/Party/Party.ts index 5064014e..5d4038f7 100644 --- a/models/baseModels/Party/Party.ts +++ b/models/baseModels/Party/Party.ts @@ -118,7 +118,10 @@ export class Party extends Doc { condition: (doc: Doc) => !doc.notInserted && (doc.role as PartyRole) !== 'Customer', action: async (partyDoc, router) => { - const doc = await fyo.doc.getNewDoc('PurchaseInvoice'); + const doc = await fyo.doc.getNewDoc('PurchaseInvoice', { + party: partyDoc.name, + account: partyDoc.defaultAccount as string, + }); router.push({ path: `/edit/PurchaseInvoice/${doc.name}`, query: { @@ -136,16 +139,7 @@ export class Party extends Doc { condition: (doc: Doc) => !doc.notInserted && (doc.role as PartyRole) !== 'Customer', action: async (partyDoc, router) => { - router.push({ - name: 'ListView', - params: { - schemaName: 'PurchaseInvoice', - filters: { - // @ts-ignore - party: partyDoc.name!, - }, - }, - }); + router.push(`/list/PurchaseInvoice/party/${partyDoc.name}`); }, }, { @@ -153,7 +147,10 @@ export class Party extends Doc { condition: (doc: Doc) => !doc.notInserted && (doc.role as PartyRole) !== 'Supplier', action: async (partyDoc, router) => { - const doc = await fyo.doc.getNewDoc('SalesInvoice'); + const doc = await fyo.doc.getNewDoc('SalesInvoice', { + party: partyDoc.name, + account: partyDoc.defaultAccount as string, + }); router.push({ path: `/edit/SalesInvoice/${doc.name}`, query: { @@ -171,16 +168,7 @@ export class Party extends Doc { condition: (doc: Doc) => !doc.notInserted && (doc.role as PartyRole) !== 'Supplier', action: async (partyDoc, router) => { - router.push({ - name: 'ListView', - params: { - schemaName: 'SalesInvoice', - filters: { - // @ts-ignore - party: partyDoc.name!, - }, - }, - }); + router.push(`/list/SalesInvoice/party/${partyDoc.name}`); }, }, ]; diff --git a/schemas/app/Item.json b/schemas/app/Item.json index fb6a3e29..0b9dec05 100644 --- a/schemas/app/Item.json +++ b/schemas/app/Item.json @@ -86,6 +86,7 @@ "label": "Both" } ], + "readOnly": true, "default": "both" }, { diff --git a/src/components/Dropdown.vue b/src/components/Dropdown.vue index d2769e30..10e1469f 100644 --- a/src/components/Dropdown.vue +++ b/src/components/Dropdown.vue @@ -184,9 +184,15 @@ export default { return emptyMessage; }, selectItem(d) { - if (d.action) { - d.action(); + if (!d.action) { + return; } + + if (this.doc) { + return d.action(this.doc, this.$router); + } + + d.action() }, toggleDropdown(flag) { if (flag == null) { diff --git a/src/components/DropdownWithActions.vue b/src/components/DropdownWithActions.vue index 18097d02..fb631268 100644 --- a/src/components/DropdownWithActions.vue +++ b/src/components/DropdownWithActions.vue @@ -3,6 +3,7 @@ v-if="actions && actions.length" class="text-xs" :items="actions" + :doc="doc" right >