[FIX] web: list: save list orderBy in favorite
When creating a favorite in a (new) list view, the list orderBy (if any) was not saved with the favorite. We fix that. Part-of: odoo/odoo#92475
This commit is contained in:
committed by
Aaron Bohy
parent
8279607488
commit
dc6834b216
@@ -1738,6 +1738,11 @@ export class SearchModel extends EventBus {
|
||||
const { description, isDefault, isShared } = params;
|
||||
const fns = this.env.__getContext__.callbacks;
|
||||
const localContext = Object.assign({}, ...fns.map((fn) => fn()));
|
||||
const gs = this.env.__getOrderBy__.callbacks;
|
||||
let localOrderBy;
|
||||
if (gs.length) {
|
||||
localOrderBy = gs.flatMap((g) => g());
|
||||
}
|
||||
const context = makeContext([this._getContext(), localContext]);
|
||||
const userContext = this.userService.context;
|
||||
for (const key in context) {
|
||||
@@ -1749,7 +1754,7 @@ export class SearchModel extends EventBus {
|
||||
const domain = this._getDomain({ raw: true, withGlobal: false }).toString();
|
||||
const groupBys = this._getGroupBy();
|
||||
const comparison = this.getFullComparison();
|
||||
const orderBy = this._getOrderBy();
|
||||
const orderBy = localOrderBy || this._getOrderBy();
|
||||
const userId = isShared ? false : this.userService.userId;
|
||||
|
||||
const preFavorite = {
|
||||
|
||||
@@ -13,6 +13,9 @@ export class WithSearch extends Component {
|
||||
if (!this.env.__getContext__) {
|
||||
useSubEnv({ __getContext__: new CallbackRecorder() });
|
||||
}
|
||||
if (!this.env.__getOrderBy__) {
|
||||
useSubEnv({ __getOrderBy__: new CallbackRecorder() });
|
||||
}
|
||||
|
||||
const SearchModelClass = this.props.SearchModel || SearchModel;
|
||||
this.searchModel = new SearchModelClass(this.env, {
|
||||
|
||||
@@ -104,6 +104,9 @@ export class ListController extends Component {
|
||||
rootState: this.model.root.exportState(),
|
||||
};
|
||||
},
|
||||
getOrderBy: () => {
|
||||
return this.model.root.orderBy;
|
||||
},
|
||||
});
|
||||
|
||||
usePager(() => {
|
||||
|
||||
@@ -59,6 +59,7 @@ export function useSetupAction(params = {}) {
|
||||
__getGlobalState__,
|
||||
__getLocalState__,
|
||||
__getContext__,
|
||||
__getOrderBy__,
|
||||
} = component.env;
|
||||
|
||||
const { beforeUnload, beforeLeave, getGlobalState, getLocalState, rootRef } = params;
|
||||
@@ -150,4 +151,7 @@ export function useSetupAction(params = {}) {
|
||||
if (__getContext__ && params.getContext) {
|
||||
useCallbackRecorder(__getContext__, params.getContext);
|
||||
}
|
||||
if (__getOrderBy__ && params.getOrderBy) {
|
||||
useCallbackRecorder(__getOrderBy__, params.getOrderBy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
triggerHotkey,
|
||||
} from "../helpers/utils";
|
||||
import {
|
||||
editFavoriteName,
|
||||
getButtons,
|
||||
getFacetTexts,
|
||||
getPagerLimit,
|
||||
@@ -43,11 +44,13 @@ import {
|
||||
groupByMenu,
|
||||
pagerNext,
|
||||
pagerPrevious,
|
||||
saveFavorite,
|
||||
toggleActionMenu,
|
||||
toggleFavoriteMenu,
|
||||
toggleFilterMenu,
|
||||
toggleGroupByMenu,
|
||||
toggleMenuItem,
|
||||
toggleSaveFavorite,
|
||||
validateSearch,
|
||||
} from "../search/helpers";
|
||||
import { createWebClient, doAction, loadState } from "../webclient/helpers";
|
||||
@@ -1520,40 +1523,36 @@ QUnit.module("Views", (hooks) => {
|
||||
);
|
||||
|
||||
QUnit.test("ordered target, sort attribute in context", async function (assert) {
|
||||
// Equivalent to saving a custom filter
|
||||
// FIXME WOWL: no it isn't
|
||||
|
||||
serverData.models.foo.fields.foo.sortable = true;
|
||||
serverData.models.foo.fields.date.sortable = true;
|
||||
|
||||
const list = await makeView({
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "foo",
|
||||
serverData,
|
||||
arch: '<tree><field name="foo"/><field name="date"/></tree>',
|
||||
mockRPC: (route, args) => {
|
||||
if (args.method === "create_or_replace") {
|
||||
const favorite = args.args[0];
|
||||
assert.step(favorite.sort);
|
||||
return 7;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Descending order on Foo
|
||||
await click($(target).find('th.o_column_sortable:contains("Foo")')[0]);
|
||||
await click($(target).find('th.o_column_sortable:contains("Foo")')[0]);
|
||||
await click(target, "th.o_column_sortable[data-name=foo]");
|
||||
await click(target, "th.o_column_sortable[data-name=foo]");
|
||||
|
||||
// Ascending order on Date
|
||||
await click($(target).find('th.o_column_sortable:contains("Date")')[0]);
|
||||
await click(target, "th.o_column_sortable[data-name=date]");
|
||||
|
||||
assert.deepEqual(
|
||||
list.model.root.orderBy,
|
||||
[
|
||||
{
|
||||
name: "date",
|
||||
asc: true,
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
asc: false,
|
||||
},
|
||||
],
|
||||
"the list should have the right orderedBy"
|
||||
);
|
||||
await toggleFavoriteMenu(target);
|
||||
await toggleSaveFavorite(target);
|
||||
await editFavoriteName(target, "My favorite");
|
||||
await saveFavorite(target);
|
||||
|
||||
assert.verifySteps(['["date","foo desc"]']);
|
||||
});
|
||||
|
||||
QUnit.test("Loading a filter with a sort attribute", async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user