mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
fix: list ordering issues
This commit is contained in:
parent
290772d924
commit
7c60b71294
@ -422,12 +422,21 @@ export default class DatabaseCore extends DatabaseBase {
|
|||||||
|
|
||||||
this.#applyFiltersToBuilder(builder, filters);
|
this.#applyFiltersToBuilder(builder, filters);
|
||||||
|
|
||||||
if (options.orderBy) {
|
const { orderBy, groupBy, order } = options;
|
||||||
builder.orderBy(options.orderBy, options.order);
|
if (Array.isArray(orderBy)) {
|
||||||
|
builder.orderBy(orderBy.map((column) => ({ column, order })));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.groupBy) {
|
if (typeof orderBy === 'string') {
|
||||||
builder.groupBy(options.groupBy);
|
builder.orderBy(orderBy, order);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(groupBy)) {
|
||||||
|
builder.groupBy(...groupBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof groupBy === 'string') {
|
||||||
|
builder.groupBy(groupBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.offset) {
|
if (options.offset) {
|
||||||
|
@ -5,8 +5,8 @@ import { DatabaseManager } from './manager';
|
|||||||
export interface GetQueryBuilderOptions {
|
export interface GetQueryBuilderOptions {
|
||||||
offset?: number;
|
offset?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
groupBy?: string;
|
groupBy?: string | string[];
|
||||||
orderBy?: string;
|
orderBy?: string | string[];
|
||||||
order?: 'desc' | 'asc';
|
order?: 'desc' | 'asc';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ export abstract class LedgerReport extends Report {
|
|||||||
{
|
{
|
||||||
fields,
|
fields,
|
||||||
filters,
|
filters,
|
||||||
orderBy: 'date',
|
orderBy: ['date', 'created'],
|
||||||
order: this.ascending ? 'asc' : 'desc',
|
order: this.ascending ? 'asc' : 'desc',
|
||||||
}
|
}
|
||||||
)) as RawLedgerEntry[];
|
)) as RawLedgerEntry[];
|
||||||
|
@ -26,7 +26,7 @@ export async function getRawStockLedgerEntries(fyo: Fyo) {
|
|||||||
|
|
||||||
return (await fyo.db.getAllRaw(ModelNameEnum.StockLedgerEntry, {
|
return (await fyo.db.getAllRaw(ModelNameEnum.StockLedgerEntry, {
|
||||||
fields: fieldnames,
|
fields: fieldnames,
|
||||||
orderBy: 'date',
|
orderBy: ['date', 'created', 'name'],
|
||||||
order: 'asc',
|
order: 'asc',
|
||||||
})) as RawStockLedgerEntry[];
|
})) as RawStockLedgerEntry[];
|
||||||
}
|
}
|
||||||
|
@ -198,9 +198,10 @@ export default defineComponent({
|
|||||||
|
|
||||||
filters = objectForEach(clone(filters), toRaw);
|
filters = objectForEach(clone(filters), toRaw);
|
||||||
|
|
||||||
const orderBy = !!fyo.getField(this.schemaName, 'date')
|
const orderBy = ['created'];
|
||||||
? 'date'
|
if (fyo.db.fieldMap[this.schemaName]['date']) {
|
||||||
: 'created';
|
orderBy.unshift('date');
|
||||||
|
}
|
||||||
|
|
||||||
this.data = (
|
this.data = (
|
||||||
await fyo.db.getAll(this.schemaName, {
|
await fyo.db.getAll(this.schemaName, {
|
||||||
|
@ -260,9 +260,11 @@ async function getParentData(
|
|||||||
limit: number | null,
|
limit: number | null,
|
||||||
fyo: Fyo
|
fyo: Fyo
|
||||||
) {
|
) {
|
||||||
const orderBy = !!fields.find((f) => f.fieldname === 'date')
|
const orderBy = ['created'];
|
||||||
? 'date'
|
if (fyo.db.fieldMap[schemaName]['date']) {
|
||||||
: 'created';
|
orderBy.unshift('date');
|
||||||
|
}
|
||||||
|
|
||||||
const options: GetAllOptions = { filters, orderBy, order: 'desc' };
|
const options: GetAllOptions = { filters, orderBy, order: 'desc' };
|
||||||
if (limit) {
|
if (limit) {
|
||||||
options.limit = limit;
|
options.limit = limit;
|
||||||
|
@ -59,8 +59,8 @@ export interface GetAllOptions {
|
|||||||
filters?: QueryFilter;
|
filters?: QueryFilter;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
groupBy?: string;
|
groupBy?: string | string[];
|
||||||
orderBy?: string;
|
orderBy?: string | string[];
|
||||||
order?: 'asc' | 'desc';
|
order?: 'asc' | 'desc';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user