mirror of
https://github.com/frappe/books.git
synced 2024-12-22 10:58:59 +00:00
fix(ux): use CommonForm for all entries
- update search routing, listConfigs
This commit is contained in:
parent
42a2de8dda
commit
0c369309e3
@ -112,7 +112,6 @@ export class Item extends Doc {
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/Item/${name}`,
|
||||
columns: ['name', 'unit', 'tax', 'rate'],
|
||||
};
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ export class JournalEntry extends Transactional {
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/JournalEntry/${name}`,
|
||||
columns: [
|
||||
'name',
|
||||
{
|
||||
|
@ -617,7 +617,6 @@ export class Payment extends Transactional {
|
||||
|
||||
static getListViewSettings(fyo: Fyo): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/Payment/${name}`,
|
||||
columns: ['name', getDocStatusListColumn(), 'party', 'date', 'amount'],
|
||||
};
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ export class PurchaseInvoice extends Invoice {
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/PurchaseInvoice/${name}`,
|
||||
columns: [
|
||||
'name',
|
||||
getTransactionStatusColumn(),
|
||||
|
@ -37,7 +37,6 @@ export class SalesInvoice extends Invoice {
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/SalesInvoice/${name}`,
|
||||
columns: [
|
||||
'name',
|
||||
getTransactionStatusColumn(),
|
||||
|
@ -8,7 +8,6 @@ export class PurchaseReceipt extends StockTransfer {
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/PurchaseReceipt/${name}`,
|
||||
columns: [
|
||||
'name',
|
||||
getTransactionStatusColumn(),
|
||||
|
@ -8,7 +8,6 @@ export class Shipment extends StockTransfer {
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
formRoute: (name) => `/edit/Shipment/${name}`,
|
||||
columns: [
|
||||
'name',
|
||||
getTransactionStatusColumn(),
|
||||
|
@ -88,7 +88,6 @@ export class StockMovement extends Transfer {
|
||||
};
|
||||
|
||||
return {
|
||||
formRoute: (name) => `/edit/StockMovement/${name}`,
|
||||
columns: [
|
||||
'name',
|
||||
getDocStatusListColumn(),
|
||||
|
@ -42,7 +42,6 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { Field } from 'schemas/types';
|
||||
import Button from 'src/components/Button.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 PageHeader from 'src/components/PageHeader.vue';
|
||||
import { fyo } from 'src/initFyo';
|
||||
import { getRouteData } from 'src/utils/filters';
|
||||
import { shortcutsKey } from 'src/utils/injectionKeys';
|
||||
import {
|
||||
docsPathMap,
|
||||
getCreateFiltersFromListViewFilters,
|
||||
} from 'src/utils/misc';
|
||||
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 { defineComponent, inject, ref } from 'vue';
|
||||
import { RouteLocationRaw } from 'vue-router';
|
||||
import List from './List.vue';
|
||||
|
||||
export default defineComponent({
|
||||
@ -135,18 +132,8 @@ export default defineComponent({
|
||||
this.listFilters = listFilters;
|
||||
},
|
||||
async openDoc(name: string) {
|
||||
const doc = await this.fyo.doc.getDoc(this.schemaName, name);
|
||||
|
||||
if (this.listConfig?.formRoute) {
|
||||
return await routeTo(this.listConfig.formRoute(name));
|
||||
}
|
||||
|
||||
const { routeFilter } = getRouteData({ doc });
|
||||
|
||||
openQuickEdit({
|
||||
doc,
|
||||
listFilters: routeFilter,
|
||||
});
|
||||
const route = getFormRoute(this.schemaName, name);
|
||||
await routeTo(route);
|
||||
},
|
||||
async makeNewDoc() {
|
||||
if (!this.canCreate) {
|
||||
@ -155,43 +142,17 @@ export default defineComponent({
|
||||
|
||||
const filters = getCreateFiltersFromListViewFilters(this.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', () => {
|
||||
const path = this.getFormPath(doc);
|
||||
this.$router.replace(path);
|
||||
const route = getFormRoute(this.schemaName, doc.name!);
|
||||
this.$router.replace(route);
|
||||
});
|
||||
},
|
||||
applyFilter(filters: QueryFilter) {
|
||||
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: {
|
||||
context(): string {
|
||||
|
@ -12,38 +12,6 @@ import Settings from 'src/pages/Settings/Settings.vue';
|
||||
import TemplateBuilder from 'src/pages/TemplateBuilder/TemplateBuilder.vue';
|
||||
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[] = [
|
||||
{
|
||||
path: '/',
|
||||
@ -53,7 +21,23 @@ const routes: RouteRecordRaw[] = [
|
||||
path: '/get-started',
|
||||
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?',
|
||||
name: 'ListView',
|
||||
|
@ -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 = {
|
||||
SalesItems: { for: ['in', ['Sales', 'Both']] },
|
||||
@ -28,96 +20,3 @@ export const createFilters = {
|
||||
Customers: { role: 'Customer' },
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -104,74 +104,50 @@ function getCreateList(fyo: Fyo): SearchItem[] {
|
||||
|
||||
const filteredCreateList = [
|
||||
{
|
||||
label: t`Sales Payments`,
|
||||
label: t`Sales Payment`,
|
||||
schemaName: ModelNameEnum.Payment,
|
||||
create: createFilters.SalesPayments,
|
||||
},
|
||||
{
|
||||
label: t`Purchase Payments`,
|
||||
label: t`Purchase Payment`,
|
||||
schemaName: ModelNameEnum.Payment,
|
||||
create: createFilters.PurchasePayments,
|
||||
},
|
||||
{
|
||||
label: t`Customers`,
|
||||
label: t`Customer`,
|
||||
schemaName: ModelNameEnum.Party,
|
||||
create: createFilters.Customers,
|
||||
filter: routeFilters.Customers,
|
||||
},
|
||||
{
|
||||
label: t`Suppliers`,
|
||||
label: t`Supplier`,
|
||||
schemaName: ModelNameEnum.Party,
|
||||
create: createFilters.Suppliers,
|
||||
filter: routeFilters.Suppliers,
|
||||
},
|
||||
{
|
||||
label: t`Party`,
|
||||
schemaName: ModelNameEnum.Party,
|
||||
create: createFilters.Party,
|
||||
filter: routeFilters.Party,
|
||||
},
|
||||
{
|
||||
label: t`Sales Items`,
|
||||
label: t`Sales Item`,
|
||||
schemaName: ModelNameEnum.Item,
|
||||
create: createFilters.SalesItems,
|
||||
},
|
||||
{
|
||||
label: t`Purchase Items`,
|
||||
label: t`Purchase Item`,
|
||||
schemaName: ModelNameEnum.Item,
|
||||
create: createFilters.PurchaseItems,
|
||||
},
|
||||
{
|
||||
label: t`Items`,
|
||||
label: t`Item`,
|
||||
schemaName: ModelNameEnum.Item,
|
||||
create: createFilters.Items,
|
||||
},
|
||||
].map(({ label, filter, 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,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
].map(({ label, create, schemaName }) => {
|
||||
return {
|
||||
label,
|
||||
group: 'Create',
|
||||
action,
|
||||
action: getCreateAction(fyo, schemaName, create),
|
||||
} as SearchItem;
|
||||
});
|
||||
|
||||
|
@ -384,22 +384,7 @@ export function getFormRoute(
|
||||
return route;
|
||||
}
|
||||
|
||||
if (
|
||||
[
|
||||
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}`;
|
||||
return `/edit/${schemaName}/${name}`;
|
||||
}
|
||||
|
||||
export async function getDocFromNameIfExistsElseNew(
|
||||
|
Loading…
Reference in New Issue
Block a user