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

fix(ux): use CommonForm for all entries

- update search routing, listConfigs
This commit is contained in:
18alantom 2023-04-14 13:22:13 +05:30
parent 42a2de8dda
commit 0c369309e3
13 changed files with 34 additions and 237 deletions

View File

@ -112,7 +112,6 @@ export class Item extends Doc {
static getListViewSettings(): ListViewSettings { static getListViewSettings(): ListViewSettings {
return { return {
formRoute: (name) => `/edit/Item/${name}`,
columns: ['name', 'unit', 'tax', 'rate'], columns: ['name', 'unit', 'tax', 'rate'],
}; };
} }

View File

@ -65,7 +65,6 @@ export class JournalEntry extends Transactional {
static getListViewSettings(): ListViewSettings { static getListViewSettings(): ListViewSettings {
return { return {
formRoute: (name) => `/edit/JournalEntry/${name}`,
columns: [ columns: [
'name', 'name',
{ {

View File

@ -617,7 +617,6 @@ export class Payment extends Transactional {
static getListViewSettings(fyo: Fyo): ListViewSettings { static getListViewSettings(fyo: Fyo): ListViewSettings {
return { return {
formRoute: (name) => `/edit/Payment/${name}`,
columns: ['name', getDocStatusListColumn(), 'party', 'date', 'amount'], columns: ['name', getDocStatusListColumn(), 'party', 'date', 'amount'],
}; };
} }

View File

@ -37,7 +37,6 @@ export class PurchaseInvoice extends Invoice {
static getListViewSettings(): ListViewSettings { static getListViewSettings(): ListViewSettings {
return { return {
formRoute: (name) => `/edit/PurchaseInvoice/${name}`,
columns: [ columns: [
'name', 'name',
getTransactionStatusColumn(), getTransactionStatusColumn(),

View File

@ -37,7 +37,6 @@ export class SalesInvoice extends Invoice {
static getListViewSettings(): ListViewSettings { static getListViewSettings(): ListViewSettings {
return { return {
formRoute: (name) => `/edit/SalesInvoice/${name}`,
columns: [ columns: [
'name', 'name',
getTransactionStatusColumn(), getTransactionStatusColumn(),

View File

@ -8,7 +8,6 @@ export class PurchaseReceipt extends StockTransfer {
static getListViewSettings(): ListViewSettings { static getListViewSettings(): ListViewSettings {
return { return {
formRoute: (name) => `/edit/PurchaseReceipt/${name}`,
columns: [ columns: [
'name', 'name',
getTransactionStatusColumn(), getTransactionStatusColumn(),

View File

@ -8,7 +8,6 @@ export class Shipment extends StockTransfer {
static getListViewSettings(): ListViewSettings { static getListViewSettings(): ListViewSettings {
return { return {
formRoute: (name) => `/edit/Shipment/${name}`,
columns: [ columns: [
'name', 'name',
getTransactionStatusColumn(), getTransactionStatusColumn(),

View File

@ -88,7 +88,6 @@ export class StockMovement extends Transfer {
}; };
return { return {
formRoute: (name) => `/edit/StockMovement/${name}`,
columns: [ columns: [
'name', 'name',
getDocStatusListColumn(), getDocStatusListColumn(),

View File

@ -42,7 +42,6 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Doc } from 'fyo/model/doc';
import { Field } from 'schemas/types'; import { Field } from 'schemas/types';
import Button from 'src/components/Button.vue'; import Button from 'src/components/Button.vue';
import ExportWizard from 'src/components/ExportWizard.vue'; import ExportWizard from 'src/components/ExportWizard.vue';
@ -50,17 +49,15 @@ import FilterDropdown from 'src/components/FilterDropdown.vue';
import Modal from 'src/components/Modal.vue'; import Modal from 'src/components/Modal.vue';
import PageHeader from 'src/components/PageHeader.vue'; import PageHeader from 'src/components/PageHeader.vue';
import { fyo } from 'src/initFyo'; import { fyo } from 'src/initFyo';
import { getRouteData } from 'src/utils/filters';
import { shortcutsKey } from 'src/utils/injectionKeys'; import { shortcutsKey } from 'src/utils/injectionKeys';
import { import {
docsPathMap, docsPathMap,
getCreateFiltersFromListViewFilters, getCreateFiltersFromListViewFilters,
} from 'src/utils/misc'; } from 'src/utils/misc';
import { docsPathRef } from 'src/utils/refs'; import { docsPathRef } from 'src/utils/refs';
import { openQuickEdit, routeTo } from 'src/utils/ui'; import { getFormRoute, routeTo } from 'src/utils/ui';
import { QueryFilter } from 'utils/db/types'; import { QueryFilter } from 'utils/db/types';
import { defineComponent, inject, ref } from 'vue'; import { defineComponent, inject, ref } from 'vue';
import { RouteLocationRaw } from 'vue-router';
import List from './List.vue'; import List from './List.vue';
export default defineComponent({ export default defineComponent({
@ -135,18 +132,8 @@ export default defineComponent({
this.listFilters = listFilters; this.listFilters = listFilters;
}, },
async openDoc(name: string) { async openDoc(name: string) {
const doc = await this.fyo.doc.getDoc(this.schemaName, name); const route = getFormRoute(this.schemaName, name);
await routeTo(route);
if (this.listConfig?.formRoute) {
return await routeTo(this.listConfig.formRoute(name));
}
const { routeFilter } = getRouteData({ doc });
openQuickEdit({
doc,
listFilters: routeFilter,
});
}, },
async makeNewDoc() { async makeNewDoc() {
if (!this.canCreate) { if (!this.canCreate) {
@ -155,43 +142,17 @@ export default defineComponent({
const filters = getCreateFiltersFromListViewFilters(this.filters ?? {}); const filters = getCreateFiltersFromListViewFilters(this.filters ?? {});
const doc = fyo.doc.getNewDoc(this.schemaName, filters); const doc = fyo.doc.getNewDoc(this.schemaName, filters);
const path = this.getFormPath(doc); const route = getFormRoute(this.schemaName, doc.name!);
await routeTo(route);
await routeTo(path);
doc.on('afterSync', () => { doc.on('afterSync', () => {
const path = this.getFormPath(doc); const route = getFormRoute(this.schemaName, doc.name!);
this.$router.replace(path); this.$router.replace(route);
}); });
}, },
applyFilter(filters: QueryFilter) { applyFilter(filters: QueryFilter) {
this.list?.updateData(filters); this.list?.updateData(filters);
}, },
getFormPath(doc: Doc) {
const { label, routeFilter } = getRouteData({ doc });
const currentPath = this.$router.currentRoute.value.path;
// Maintain filters
let path = `/list/${this.schemaName}/${label}`;
if (currentPath.startsWith(path)) {
path = currentPath;
}
let route: RouteLocationRaw = {
path,
query: {
edit: 1,
schemaName: this.schemaName,
name: doc.name,
filters: JSON.stringify(routeFilter),
},
};
if (this.listConfig?.formRoute) {
route = this.listConfig.formRoute(doc.name!);
}
return route;
},
}, },
computed: { computed: {
context(): string { context(): string {

View File

@ -12,38 +12,6 @@ import Settings from 'src/pages/Settings/Settings.vue';
import TemplateBuilder from 'src/pages/TemplateBuilder/TemplateBuilder.vue'; import TemplateBuilder from 'src/pages/TemplateBuilder/TemplateBuilder.vue';
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'; import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
function getCommonFormItems(): RouteRecordRaw[] {
return [
ModelNameEnum.SalesInvoice,
ModelNameEnum.PurchaseInvoice,
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,
};
},
edit: (route) => route.query,
},
};
});
}
const routes: RouteRecordRaw[] = [ const routes: RouteRecordRaw[] = [
{ {
path: '/', path: '/',
@ -53,7 +21,23 @@ const routes: RouteRecordRaw[] = [
path: '/get-started', path: '/get-started',
component: GetStarted, component: GetStarted,
}, },
...getCommonFormItems(), {
path: `/edit/:schemaName/:name`,
name: `CommonForm`,
components: {
default: CommonForm,
edit: QuickEditForm,
},
props: {
default: (route) => {
return {
schemaName: route.params.schemaName,
name: route.params.name,
};
},
edit: (route) => route.query,
},
},
{ {
path: '/list/:schemaName/:pageTitle?', path: '/list/:schemaName/:pageTitle?',
name: 'ListView', name: 'ListView',

View File

@ -1,11 +1,3 @@
import { t } from 'fyo';
import type { Doc } from 'fyo/model/doc';
import { ValueError } from 'fyo/utils/errors';
import type { Item } from 'models/baseModels/Item/Item';
import type { Party } from 'models/baseModels/Party/Party';
import type { Payment } from 'models/baseModels/Payment/Payment';
import { ModelNameEnum } from 'models/types';
import { fyo } from 'src/initFyo';
export const routeFilters = { export const routeFilters = {
SalesItems: { for: ['in', ['Sales', 'Both']] }, SalesItems: { for: ['in', ['Sales', 'Both']] },
@ -28,96 +20,3 @@ export const createFilters = {
Customers: { role: 'Customer' }, Customers: { role: 'Customer' },
Party: { role: 'Both' }, Party: { role: 'Both' },
}; };
export function getRouteData({ doc, uiname }: { doc?: Doc; uiname?: string }) {
if (doc) {
uiname = getUiName(doc);
}
if (!uiname) {
throw new ValueError(`Doc and uiname not passed to getFilters`);
}
const routeFilter = routeFilters[uiname as keyof typeof routeFilters] ?? {};
const createFilter =
createFilters[uiname as keyof typeof createFilters] ?? {};
const label = getLabelName(uiname);
return { routeFilter, createFilter, label };
}
function getLabelName(uiname: string) {
const labels = {
SalesItems: t`Sales Items`,
PurchaseItems: t`Purchase Items`,
Items: t`Items`,
Suppliers: t`Suppliers`,
Customers: t`Customers`,
Party: t`Party`,
PurchasePayments: t`Purchase Payments`,
SalesPayments: t`Sales Payments`,
};
return labels[uiname as keyof typeof labels] ?? fyo.schemaMap[uiname]?.label;
}
function getUiName(doc: Doc) {
const isDual = [
ModelNameEnum.Party,
ModelNameEnum.Payment,
ModelNameEnum.Item,
].includes(doc.schemaName as ModelNameEnum);
if (!isDual) {
return doc.schemaName;
}
if (doc.schemaName === ModelNameEnum.Party) {
return getPartyUiName(doc as Party);
}
if (doc.schemaName === ModelNameEnum.Payment) {
return getPaymentUiName(doc as Payment);
}
if (doc.schemaName === ModelNameEnum.Item) {
return getItemUiName(doc as Item);
}
return doc.schemaName;
}
function getPartyUiName(doc: Party) {
switch (doc.role) {
case 'Customer':
return 'Customers';
case 'Supplier':
return 'Suppliers';
default:
return doc.schemaName;
}
}
function getPaymentUiName(doc: Payment) {
switch (doc.paymentType) {
case 'Pay':
return 'PurchasePayments';
case 'Receive':
return 'SalesPayments';
default:
return doc.schemaName;
}
}
function getItemUiName(doc: Item) {
switch (doc.for) {
case 'Purchases':
return 'PurchaseItems';
case 'Sales':
return 'SalesItems';
case 'Both':
return 'Items';
default:
return doc.schemaName;
}
}

View File

@ -104,74 +104,50 @@ function getCreateList(fyo: Fyo): SearchItem[] {
const filteredCreateList = [ const filteredCreateList = [
{ {
label: t`Sales Payments`, label: t`Sales Payment`,
schemaName: ModelNameEnum.Payment, schemaName: ModelNameEnum.Payment,
create: createFilters.SalesPayments, create: createFilters.SalesPayments,
}, },
{ {
label: t`Purchase Payments`, label: t`Purchase Payment`,
schemaName: ModelNameEnum.Payment, schemaName: ModelNameEnum.Payment,
create: createFilters.PurchasePayments, create: createFilters.PurchasePayments,
}, },
{ {
label: t`Customers`, label: t`Customer`,
schemaName: ModelNameEnum.Party, schemaName: ModelNameEnum.Party,
create: createFilters.Customers, create: createFilters.Customers,
filter: routeFilters.Customers,
}, },
{ {
label: t`Suppliers`, label: t`Supplier`,
schemaName: ModelNameEnum.Party, schemaName: ModelNameEnum.Party,
create: createFilters.Suppliers, create: createFilters.Suppliers,
filter: routeFilters.Suppliers,
}, },
{ {
label: t`Party`, label: t`Party`,
schemaName: ModelNameEnum.Party, schemaName: ModelNameEnum.Party,
create: createFilters.Party, create: createFilters.Party,
filter: routeFilters.Party,
}, },
{ {
label: t`Sales Items`, label: t`Sales Item`,
schemaName: ModelNameEnum.Item, schemaName: ModelNameEnum.Item,
create: createFilters.SalesItems, create: createFilters.SalesItems,
}, },
{ {
label: t`Purchase Items`, label: t`Purchase Item`,
schemaName: ModelNameEnum.Item, schemaName: ModelNameEnum.Item,
create: createFilters.PurchaseItems, create: createFilters.PurchaseItems,
}, },
{ {
label: t`Items`, label: t`Item`,
schemaName: ModelNameEnum.Item, schemaName: ModelNameEnum.Item,
create: createFilters.Items, create: createFilters.Items,
}, },
].map(({ label, filter, create, schemaName }) => { ].map(({ label, create, schemaName }) => {
let action: Function;
if (!filter) {
action = getCreateAction(fyo, schemaName, create);
} else {
const route = {
path: `/list/${schemaName}/${label}`,
query: { filters: JSON.stringify(filter) },
};
action = async () => {
await routeTo(route);
const doc = fyo.doc.getNewDoc(schemaName, create);
const { openQuickEdit } = await import('src/utils/ui');
await openQuickEdit({
schemaName,
name: doc.name as string,
listFilters: filter,
});
};
}
return { return {
label, label,
group: 'Create', group: 'Create',
action, action: getCreateAction(fyo, schemaName, create),
} as SearchItem; } as SearchItem;
}); });

View File

@ -384,22 +384,7 @@ export function getFormRoute(
return route; return route;
} }
if ( return `/edit/${schemaName}/${name}`;
[
ModelNameEnum.SalesInvoice,
ModelNameEnum.PurchaseInvoice,
ModelNameEnum.JournalEntry,
ModelNameEnum.Shipment,
ModelNameEnum.PurchaseReceipt,
ModelNameEnum.StockMovement,
ModelNameEnum.Payment,
ModelNameEnum.Item,
].includes(schemaName as ModelNameEnum)
) {
return `/edit/${schemaName}/${name}`;
}
return `/list/${schemaName}?edit=1&schemaName=${schemaName}&name=${name}`;
} }
export async function getDocFromNameIfExistsElseNew( export async function getDocFromNameIfExistsElseNew(