summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorHiral Bhavsar <hbh@odoo.com>2019-08-23 10:23:29 +0000
committerHiral Bhavsar <hbh@odoo.com>2019-08-29 12:56:24 +0000
commit1d2559ce64085eb9fbd8422f8d88e18bc3dce344 (patch)
tree43d09355b770bd58739fdbcebd6c1da51fe50b0b /addons/web/static/src/js
parent4242ddd7a8e5b979a3dc679dacd8e5c29edb4c2b (diff)
[IMP] sale_expense, web: hide 'search more..' from m2o dropdown
Purpose ======== In expense, we now allow any simple employee (no sales access rights) to select sales order. Technically, the name_search is done in sudo mode, to allow simply fetching the name_get of record. The problem is that the m2o field widget displays the "search more" option and click on that will open a modal executing a "search_read" which is causing access error as the user doesn't have read access on SO. As we want to restrict the visible information from the SO(only name_get) to all user, we can't hack the search_read too. Specification ============= To prevent user frustration, we need to remove the "search more" option. Thus, make a private function which one have 'search more..' option related stuff and create a new widget for sale_expense, override that function which one is returing values as it is without any modification. task-2057714 closes odoo/odoo#36152 Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js81
1 files changed, 47 insertions, 34 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 93863c2f619..f4337d0c8f9 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -402,6 +402,52 @@ var FieldMany2One = AbstractField.extend({
};
},
/**
+ * @private
+ * @param {Object} values
+ * @param {string} search_val
+ * @param {Object} domain
+ * @param {Object} context
+ * @returns {Object}
+ */
+ _manageSearchMore: function (values, search_val, domain, context) {
+ var self = this;
+ values = values.slice(0, this.limit);
+ values.push({
+ label: _t("Search More..."),
+ action: function () {
+ var prom;
+ if (search_val !== '') {
+ prom = self._rpc({
+ model: self.field.relation,
+ method: 'name_search',
+ kwargs: {
+ name: search_val,
+ args: domain,
+ operator: "ilike",
+ limit: self.SEARCH_MORE_LIMIT,
+ context: context,
+ },
+ });
+ }
+ Promise.resolve(prom).then(function (results) {
+ var dynamicFilters;
+ if (results) {
+ var ids = _.map(results, function (x) {
+ return x[0];
+ });
+ dynamicFilters = [{
+ description: _.str.sprintf(_t('Quick search: %s'), search_val),
+ domain: [['id', 'in', ids]],
+ }];
+ }
+ self._searchCreatePopup("search", false, {}, dynamicFilters);
+ });
+ },
+ classname: 'o_m2o_dropdown_option',
+ });
+ return values;
+ },
+ /**
* Listens to events 'field_changed' to keep track of the last event that
* has been trigerred. This allows to detect that all changes have been
* acknowledged by the environment.
@@ -552,40 +598,7 @@ var FieldMany2One = AbstractField.extend({
// search more... if more results than limit
if (values.length > self.limit) {
- values = values.slice(0, self.limit);
- values.push({
- label: _t("Search More..."),
- action: function () {
- var prom;
- if (search_val !== '') {
- prom = self._rpc({
- model: self.field.relation,
- method: 'name_search',
- kwargs: {
- name: search_val,
- args: domain,
- operator: "ilike",
- limit: self.SEARCH_MORE_LIMIT,
- context: context,
- },
- });
- }
- Promise.resolve(prom).then(function (results) {
- var dynamicFilters;
- if (results) {
- var ids = _.map(results, function (x) {
- return x[0];
- });
- dynamicFilters = [{
- description: _.str.sprintf(_t('Quick search: %s'), search_val),
- domain: [['id', 'in', ids]],
- }];
- }
- self._searchCreatePopup("search", false, {}, dynamicFilters);
- });
- },
- classname: 'o_m2o_dropdown_option',
- });
+ values = self._manageSearchMore(values, search_val, domain, context);
}
var create_enabled = self.can_create && !self.nodeOptions.no_create;
// quick create