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