[REF] web,purchase: SampleServer: mock registry

This commit changes the API of the SampleServer's mock
registry s.t. one can register a mocked version of a method,
whatever the model. The former API required a specific
model to be specified, and only applied on this model.

However, in order to enable the sample data feature on the
cohort view, the 'get_cohort_data' method needs to be
mocked, whatever the concerned model.

One can now register mocked methods for a specific
model only (with key 'model/method') or for every
models (with key 'method').

Task ID: 2282196
This commit is contained in:
Aaron Bohy
2020-08-12 08:52:20 +00:00
committed by Mathieu Duckerts-Antoine
parent f3ee2e0cec
commit 06b8af3212
2 changed files with 13 additions and 12 deletions
@@ -26,10 +26,8 @@ var QWeb = core.qweb;
// Add mock of method 'retrieve_dashboard' in SampleServer, so that we can have
// the sample data in empty purchase kanban and list view
let dashboardValues;
SampleServer.mockRegistry.add('purchase.order', {
retrieve_dashboard: () => {
return Object.assign({}, dashboardValues);
},
SampleServer.mockRegistry.add('purchase.order/retrieve_dashboard', () => {
return Object.assign({}, dashboardValues);
});
@@ -116,8 +116,12 @@ odoo.define('web.SampleServer', function (require) {
case 'read':
return this._mockRead(params);
}
const mock = SampleServer.mockRegistry.get(params.model);
const mockFunction = mock && mock[params.method || params.route];
// this rpc can't be mocked by the SampleServer itself, so check if there is an handler
// in the mockRegistry: either specific for this model (with key 'model/method'), or
// global (with key 'method')
const method = params.method || params.route;
const mockFunction = SampleServer.mockRegistry.get(`${params.model}/${method}`) ||
SampleServer.mockRegistry.get(method);
if (mockFunction) {
return mockFunction.call(this, params);
}
@@ -652,12 +656,11 @@ odoo.define('web.SampleServer', function (require) {
SampleServer.UnimplementedRouteError = UnimplementedRouteError;
// mockRegistry allows to register mock version of methods or routes for
// specific models, for instance
// SampleServer.mockRegistry.registry('res.partner' {
// some_method: () => 23,
// some_route: () => "abcd",
// });
// mockRegistry allows to register mock version of methods or routes,
// for all models:
// SampleServer.mockRegistry.add('some_route', () => "abcd");
// for a specific model (e.g. 'res.partner'):
// SampleServer.mockRegistry.add('res.partner/some_method', () => 23);
SampleServer.mockRegistry = new Registry();
return SampleServer;