summaryrefslogtreecommitdiff
path: root/addons/lunch/static
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-04-16 15:09:47 +0000
committerJulien Mougenot <jum@odoo.com>2020-04-17 14:21:02 +0000
commit7ace5a986a042ced675fb821bbf527d2d69ca614 (patch)
tree1dbd94412506f49a3373973f6662f25462873c47 /addons/lunch/static
parentb3149d84a0253fad63ae00880d9e832e7bfe9057 (diff)
[FIX] web,lunch: separate search panel domain
Before this commit, the SearchPanel widget was given a single unified domain coming from the view/controller. The issue was that some modules injected additional leaves in this domain and there was no way to remove them/separate them from the original view/controller domain. Now, another paramater (the `viewDomain`) is given to the SearchPanel, containing the distinct domain related to the view. The Lunch module has been adapted to give the `location` domain through this new key. Note that some tests steps had to be inverted since the method retreiving the domain of the view/controller is asynchronous (needed by Lunch to give time to the model to be loaded). It mainly concerns the RPC order which does not matter in this case. Task 2239706 closes odoo/odoo#49720 X-original-commit: e895e553899933be14c8abfd8c676b44a7f534d8 Signed-off-by: Julien Mougenot (jum) <jum@odoo.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/lunch/static')
-rw-r--r--addons/lunch/static/src/js/lunch_kanban_controller.js7
-rw-r--r--addons/lunch/static/src/js/lunch_kanban_model.js13
-rw-r--r--addons/lunch/static/src/js/lunch_kanban_view.js14
-rw-r--r--addons/lunch/static/tests/lunch_kanban_tests.js32
4 files changed, 34 insertions, 32 deletions
diff --git a/addons/lunch/static/src/js/lunch_kanban_controller.js b/addons/lunch/static/src/js/lunch_kanban_controller.js
index 7713c192bb3..6e75d4839b3 100644
--- a/addons/lunch/static/src/js/lunch_kanban_controller.js
+++ b/addons/lunch/static/src/js/lunch_kanban_controller.js
@@ -81,12 +81,9 @@ var LunchKanbanController = KanbanController.extend({
* to the searchDomain (coming from the controlPanel).
*
* @override
- * @private
*/
- _getSearchDomain: function () {
- var searchDomain = this._super.apply(this, arguments) || [];
- var locationId = this.model.getCurrentLocationId();
- return searchDomain.concat([['is_available_at', 'in', [locationId]]]);
+ _getViewDomain: async function () {
+ return this.model.getLocationDomain();
},
/**
* Renders and appends the lunch banner widget.
diff --git a/addons/lunch/static/src/js/lunch_kanban_model.js b/addons/lunch/static/src/js/lunch_kanban_model.js
index 7ab7b279e43..07acbcd8b69 100644
--- a/addons/lunch/static/src/js/lunch_kanban_model.js
+++ b/addons/lunch/static/src/js/lunch_kanban_model.js
@@ -23,12 +23,6 @@ var LunchKanbanModel = KanbanModel.extend({
//--------------------------------------------------------------------------
/**
- * @returns {integer|false}
- */
- getCurrentLocationId: function () {
- return this.locationId;
- },
- /**
* @return {Promise} resolved with the location domain
*/
getLocationDomain: function () {
@@ -84,12 +78,11 @@ var LunchKanbanModel = KanbanModel.extend({
* Builds the domain leaf corresponding to the current user's location
*
* @private
- * @return {Array}
+ * @return {(Array[])|undefined}
*/
_buildLocationDomainLeaf: function () {
- var locationId = this.getCurrentLocationId();
- if (locationId) {
- return ['is_available_at', 'in', [locationId]];
+ if (this.locationId) {
+ return ['is_available_at', 'in', [this.locationId]];
}
},
_getUserLocation: function () {
diff --git a/addons/lunch/static/src/js/lunch_kanban_view.js b/addons/lunch/static/src/js/lunch_kanban_view.js
index 8dda159f006..0b54497fc55 100644
--- a/addons/lunch/static/src/js/lunch_kanban_view.js
+++ b/addons/lunch/static/src/js/lunch_kanban_view.js
@@ -24,19 +24,11 @@ var LunchKanbanView = KanbanView.extend({
//--------------------------------------------------------------------------
/**
- * Injects an additional domain in the search panel
- *
- * @private
* @override
*/
- _createSearchPanel: function (parent, params) {
- var self = this;
- var model = this.getModel(parent);
- var _super = this._super.bind(this);
- return model.getLocationDomain().then(function (domain) {
- self.loadParams.domain = self.loadParams.domain.concat(domain);
- return _super(parent, params);
- });
+ _getViewDomain: function (parent) {
+ const model = this.getModel(parent);
+ return model.getLocationDomain();
},
});
diff --git a/addons/lunch/static/tests/lunch_kanban_tests.js b/addons/lunch/static/tests/lunch_kanban_tests.js
index 6dfb524ef9e..bb2b0beb3f7 100644
--- a/addons/lunch/static/tests/lunch_kanban_tests.js
+++ b/addons/lunch/static/tests/lunch_kanban_tests.js
@@ -212,8 +212,9 @@ QUnit.module('LunchKanbanView', {
});
QUnit.test('search panel domain location', async function (assert) {
- assert.expect(10);
- const locationId = this.data['lunch.location'].records[0].id;
+ assert.expect(20);
+ let expectedLocation = 1;
+ let locationId = this.data['lunch.location'].records[0].id;
const regularInfos = _.extend({}, this.regularInfos);
const kanban = await createLunchKanbanView({
@@ -233,30 +234,49 @@ QUnit.module('LunchKanbanView', {
assert.step(route);
if (route.startsWith('/lunch')) {
+ if (route === '/lunch/user_location_set') {
+ locationId = args.location_id;
+ return Promise.resolve(true);
+ }
return mockLunchRPC({
infos: regularInfos,
userLocation: locationId,
}).apply(this, arguments);
}
if (args.method === 'search_panel_select_multi_range') {
- assert.deepEqual(args.kwargs.search_domain, [["is_available_at", "in", [locationId]]],
+ assert.deepEqual(args.kwargs.search_domain, [["is_available_at", "in", [expectedLocation]]],
'The initial domain of the search panel must contain the user location');
}
if (route === '/web/dataset/search_read') {
- assert.deepEqual(args.domain, [["is_available_at", "in", [locationId]]],
+ assert.deepEqual(args.domain, [["is_available_at", "in", [expectedLocation]]],
'The domain for fetching actual data should be correct');
}
return this._super.apply(this, arguments);
- }
+ },
});
+
+ expectedLocation = 2;
+ await testUtils.fields.many2one.clickOpenDropdown('locations');
+ await testUtils.fields.many2one.clickItem('locations', "Office 2");
+
assert.verifySteps([
+ // Initial state
'/lunch/user_location_get',
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/search_read',
'/lunch/infos',
'/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
- ])
+ // Click m2o
+ '/web/dataset/call_kw/lunch.location/name_search',
+ // Click new location
+ '/lunch/user_location_set',
+ '/web/dataset/call_kw/product/search_panel_select_multi_range',
+ '/web/dataset/call_kw/product/search_panel_select_multi_range',
+ '/web/dataset/search_read',
+ '/lunch/infos',
+ '/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
+ ]);
kanban.destroy();
});