[REF] web: Allow to get ir.filter values without creating the record
In the spreadsheet app, we need the exact same values which are saved for "ir.filter" records. This commit refactor a bit things to allows getting those values without actually creating the "ir.filter" record. Task 2572184 Part-of: odoo/odoo#75859 Co-authored-by: LucasLefevre <lul@odoo.com>
This commit is contained in:
committed by
Lucas Lefèvre
co-authored by
LucasLefevre
parent
5419fe445d
commit
1dcf1acd3b
@@ -199,6 +199,7 @@ odoo.define("web/static/src/js/control_panel/control_panel_model_extension.js",
|
||||
case "groupBy": return this.getGroupBy();
|
||||
case "orderedBy": return this.getOrderedBy();
|
||||
case "timeRanges": return this.getTimeRanges();
|
||||
case "irFilterValues": return this.getIrFilterValues({ type: "favorite" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +261,52 @@ odoo.define("web/static/src/js/control_panel/control_panel_model_extension.js",
|
||||
this.state.query = [];
|
||||
}
|
||||
|
||||
getIrFilterValues(preFilter) {
|
||||
const groups = this._getGroups();
|
||||
|
||||
const userContext = this.env.session.user_context;
|
||||
let controllerQueryParams;
|
||||
this.config.trigger("get-controller-query-params", params => {
|
||||
controllerQueryParams = params;
|
||||
});
|
||||
controllerQueryParams = controllerQueryParams || {};
|
||||
controllerQueryParams.context = controllerQueryParams.context || {};
|
||||
|
||||
const queryContext = this._getContext(groups);
|
||||
const context = pyUtils.eval(
|
||||
'contexts',
|
||||
[userContext, controllerQueryParams.context, queryContext]
|
||||
);
|
||||
for (const key in userContext) {
|
||||
delete context[key];
|
||||
}
|
||||
|
||||
const requireEvaluation = false;
|
||||
const domain = this._getDomain(groups);
|
||||
const groupBys = this._getGroupBy(groups);
|
||||
const timeRanges = this._getTimeRanges(requireEvaluation);
|
||||
const orderedBy = controllerQueryParams.orderedBy ?
|
||||
controllerQueryParams.orderedBy :
|
||||
(this._getOrderedBy(groups) || []);
|
||||
|
||||
const userId = preFilter.isShared ? false : this.env.session.uid;
|
||||
delete preFilter.isShared;
|
||||
|
||||
Object.assign(preFilter, {
|
||||
context,
|
||||
domain,
|
||||
groupBys,
|
||||
groupNumber: userId ? FAVORITE_PRIVATE_GROUP : FAVORITE_SHARED_GROUP,
|
||||
orderedBy,
|
||||
removable: true,
|
||||
userId,
|
||||
});
|
||||
if (timeRanges) {
|
||||
preFilter.comparison = timeRanges;
|
||||
}
|
||||
return this._favoriteToIrFilter(preFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new filter of type 'favorite' and activate it.
|
||||
* A new group containing only that filter is created.
|
||||
@@ -1580,49 +1627,7 @@ odoo.define("web/static/src/js/control_panel/control_panel_model_extension.js",
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async _saveQuery(preFilter) {
|
||||
const groups = this._getGroups();
|
||||
|
||||
const userContext = this.env.session.user_context;
|
||||
let controllerQueryParams;
|
||||
this.config.trigger("get-controller-query-params", params => {
|
||||
controllerQueryParams = params;
|
||||
});
|
||||
controllerQueryParams = controllerQueryParams || {};
|
||||
controllerQueryParams.context = controllerQueryParams.context || {};
|
||||
|
||||
const queryContext = this._getContext(groups);
|
||||
const context = pyUtils.eval(
|
||||
'contexts',
|
||||
[userContext, controllerQueryParams.context, queryContext]
|
||||
);
|
||||
for (const key in userContext) {
|
||||
delete context[key];
|
||||
}
|
||||
|
||||
const requireEvaluation = false;
|
||||
const domain = this._getDomain(groups);
|
||||
const groupBys = this._getGroupBy(groups);
|
||||
const timeRanges = this._getTimeRanges(requireEvaluation);
|
||||
const orderedBy = controllerQueryParams.orderedBy ?
|
||||
controllerQueryParams.orderedBy :
|
||||
(this._getOrderedBy(groups) || []);
|
||||
|
||||
const userId = preFilter.isShared ? false : this.env.session.uid;
|
||||
delete preFilter.isShared;
|
||||
|
||||
Object.assign(preFilter, {
|
||||
context,
|
||||
domain,
|
||||
groupBys,
|
||||
groupNumber: userId ? FAVORITE_PRIVATE_GROUP : FAVORITE_SHARED_GROUP,
|
||||
orderedBy,
|
||||
removable: true,
|
||||
userId,
|
||||
});
|
||||
if (timeRanges) {
|
||||
preFilter.comparison = timeRanges;
|
||||
}
|
||||
const irFilter = this._favoriteToIrFilter(preFilter);
|
||||
const irFilter = this.getIrFilterValues(preFilter);
|
||||
const serverSideId = await this.env.dataManager.create_filter(irFilter);
|
||||
|
||||
preFilter.serverSideId = serverSideId;
|
||||
|
||||
@@ -328,6 +328,34 @@ odoo.define("web/static/tests/control_panel/control_panel_model_extension_tests.
|
||||
|
||||
});
|
||||
|
||||
QUnit.test('ir.filter values', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const context = {
|
||||
search_default_filter: true,
|
||||
search_default_bar: 0,
|
||||
search_default_groupby: 2,
|
||||
};
|
||||
const arch = `
|
||||
<search>
|
||||
<filter name="filter" string="Hello" domain="[['foo', '=', 'hello']]"/>
|
||||
<filter name="groupby" string="Goodbye" context="{'group_by': 'foo'}"/>
|
||||
<field name="bar"/>
|
||||
</search>`;
|
||||
const fields = this.fields;
|
||||
const model = createModel({ arch, fields, context });
|
||||
assert.deepEqual(model.get("irFilterValues"), {
|
||||
action_id: undefined,
|
||||
context: {
|
||||
group_by: ["foo"],
|
||||
},
|
||||
domain: '[["foo", "=", "hello"]]',
|
||||
model_id: undefined,
|
||||
sort: "[]",
|
||||
user_id: undefined
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('falsy search defaults are not activated', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user