2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00

feat: add more search items

- fix a few actions
- fix listview page titles
This commit is contained in:
18alantom 2022-05-02 11:01:11 +05:30
parent 89983f24e2
commit 185110276d
11 changed files with 119 additions and 48 deletions

View File

@ -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', {

View File

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

View File

@ -86,6 +86,7 @@
"label": "Both"
}
],
"readOnly": true,
"default": "both"
},
{

View File

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

View File

@ -3,6 +3,7 @@
v-if="actions && actions.length"
class="text-xs"
:items="actions"
:doc="doc"
right
>
<template v-slot="{ toggleDropdown }">
@ -30,6 +31,7 @@ export default {
actions: { default: [] },
type: { type: String, default: 'secondary' },
},
inject: ['doc'],
components: {
Dropdown,
Button,

View File

@ -18,6 +18,7 @@ const keys = useKeys();
w-48
px-3
items-center
hover:bg-gray-200
"
>
<feather-icon name="search" class="w-4 h-4" />
@ -73,7 +74,7 @@ const keys = useKeys();
class="flex flex-row w-full justify-between px-3 items-center"
style="height: 48px"
>
<p class="">
<p class="text-gray-900">
{{ si.label }}
</p>
<div

View File

@ -188,6 +188,7 @@ export default {
if (group.action) {
group.action();
}
if (group.route) {
routeTo(group.route);
}

View File

@ -36,7 +36,11 @@ import List from './List';
export default {
name: 'ListView',
props: ['schemaName', 'filters'],
props: {
schemaName: String,
filters: Object,
pageTitle: { type: String, default: '' },
},
components: {
PageHeader,
List,
@ -92,7 +96,7 @@ export default {
},
computed: {
title() {
return fyo.schemaMap[this.schemaName].label;
return this.pageTitle || fyo.schemaMap[this.schemaName].label;
},
fields() {
return fyo.schemaMap[this.schemaName].fields;

View File

@ -6,7 +6,7 @@ import GetStarted from 'src/pages/GetStarted.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 PrintView from 'src/pages/PrintView/PrintView.vue';
import QuickEditForm from 'src/pages/QuickEditForm.vue';
// import Report from 'src/pages/Report.vue';
import Settings from 'src/pages/Settings/Settings.vue';
@ -54,7 +54,7 @@ const routes: RouteRecordRaw[] = [
},
},
{
path: '/list/:schemaName/:fieldname?/:value?',
path: '/list/:schemaName/:fieldname?/:value?/:pageTitle?',
name: 'ListView',
components: {
default: ListView,
@ -62,7 +62,7 @@ const routes: RouteRecordRaw[] = [
},
props: {
default: (route) => {
const { schemaName, fieldname, value } = route.params;
const { schemaName, fieldname, value, pageTitle } = route.params;
let { filters } = route.params;
if (filters === undefined && fieldname && value) {
@ -73,6 +73,7 @@ const routes: RouteRecordRaw[] = [
return {
schemaName,
filters,
pageTitle: pageTitle ?? '',
};
},
edit: (route) => {
@ -80,13 +81,13 @@ const routes: RouteRecordRaw[] = [
},
},
},
/*
{
path: '/print/:schemaName/:name',
name: 'PrintView',
component: PrintView,
props: true,
},
/*
{
path: '/report/:reportName',
name: 'Report',

View File

@ -70,7 +70,53 @@ function getCreateList(): SearchItem[] {
} as SearchItem)
);
return [quickEditCreateList, formEditCreateList].flat();
const filteredCreateList = [
{
label: t`Customers`,
schemaName: ModelNameEnum.Party,
filter: { role: 'Customer' },
},
{
label: t`Suppliers`,
schemaName: ModelNameEnum.Party,
filter: { role: 'Supplier' },
},
{
label: t`Sales Items`,
schemaName: ModelNameEnum.Item,
filter: { for: 'sales' },
},
{
label: t`Purchase Items`,
schemaName: ModelNameEnum.Item,
filter: { for: 'purchases' },
},
{
label: t`Common Items`,
schemaName: ModelNameEnum.Item,
filter: { for: 'both' },
},
].map(({ label, filter, schemaName }) => {
const fk = Object.keys(filter)[0] as 'for' | 'role';
const ep = `${fk}/${filter[fk]}`;
const route = `/list/${schemaName}/${ep}/${label}`;
return {
label,
group: 'Create',
async action() {
await routeTo(route);
const doc = await fyo.doc.getNewDoc(schemaName, filter);
const { openQuickEdit } = await import('src/utils/ui');
await openQuickEdit({
schemaName,
name: doc.name as string,
});
},
} as SearchItem;
});
return [quickEditCreateList, formEditCreateList, filteredCreateList].flat();
}
function getReportList(): SearchItem[] {
@ -84,10 +130,9 @@ function getReportList(): SearchItem[] {
}
function getListViewList(): SearchItem[] {
return [
const standardLists = [
ModelNameEnum.Account,
ModelNameEnum.Party,
ModelNameEnum.Item,
ModelNameEnum.Payment,
ModelNameEnum.JournalEntry,
ModelNameEnum.PurchaseInvoice,
@ -96,11 +141,33 @@ function getListViewList(): SearchItem[] {
]
.map((s) => fyo.schemaMap[s])
.filter((s) => s && !s.isChild && !s.isSingle)
.map((s) => ({
label: s!.label,
route: `/list/${s!.name}`,
group: 'List',
}));
.map(
(s) =>
({
label: s!.label,
route: `/list/${s!.name}`,
group: 'List',
} as SearchItem)
);
const filteredLists = [
{ label: t`Customers`, route: `/list/Party/role/Customer/${t`Customers`}` },
{ label: t`Suppliers`, route: `/list/Party/role/Supplier/${t`Suppliers`}` },
{
label: t`Sales Items`,
route: `/list/Item/for/sales/${t`Sales Items`}`,
},
{
label: t`Purchase Items`,
route: `/list/Item/for/purchases/${t`Purchase Items`}`,
},
{
label: t`Common Items`,
route: `/list/Item/for/both/${t`Common Items`}`,
},
].map((i) => ({ ...i, group: 'List' } as SearchItem));
return [standardLists, filteredLists].flat();
}
function getSetupList(): SearchItem[] {

View File

@ -63,13 +63,13 @@ function getCompleteSidebar(): SidebarConfig {
{
label: t`Customers`,
name: 'customers',
route: '/list/Party/role/Customer',
route: `/list/Party/role/Customer/${t`Customers`}`,
schemaName: 'Party',
},
{
label: t`Sales Items`,
name: 'sales-items',
route: '/list/Item/for/sales',
route: `/list/Item/for/sales/${t`Sales Items`}`,
schemaName: 'Item',
},
],
@ -95,13 +95,13 @@ function getCompleteSidebar(): SidebarConfig {
{
label: t`Suppliers`,
name: 'suppliers',
route: '/list/Party/role/Supplier',
route: `/list/Party/role/Supplier/${t`Suppliers`}`,
schemaName: 'Party',
},
{
label: t`Purchase Items`,
name: 'purchase-items',
route: '/list/Item/for/purchases',
route: `/list/Item/for/purchases/${t`Purchase Items`}`,
schemaName: 'Item',
},
],
@ -121,7 +121,7 @@ function getCompleteSidebar(): SidebarConfig {
{
label: t`Common Items`,
name: 'common-items',
route: '/list/Item/for/both',
route: `/list/Item/for/both/${t`Common Items`}`,
schemaName: 'Item',
},
{