diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-10-09 02:08:17 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-10-09 02:08:17 +0200 |
| commit | d74b4518052066446e2a1975a91ce53c745ca75a (patch) | |
| tree | c08180f88a512d15e37fbec628931f02b3825f65 /addons/web/static/src/js/views/basic | |
| parent | ec162dd0cb5622ab6e56db1a63dab5f531a96f4a (diff) | |
| parent | f4105eb9c7010f8693e5d2fd20c0bd9d9cc2e483 (diff) | |
[MERGE] forward port branch 13.0 up to f4105eb9c70
Diffstat (limited to 'addons/web/static/src/js/views/basic')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_controller.js | 16 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 18 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_view.js | 27 |
3 files changed, 40 insertions, 21 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index be0b9a00bf3..7639d2dea99 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -404,10 +404,13 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { options = options || {}; return this.canBeDiscarded(recordID) .then(function (needDiscard) { - if (options.noAbandon || (options.readonlyIfRealDiscard && !needDiscard)) { + if (options.readonlyIfRealDiscard && !needDiscard) { return; } self.model.discardChanges(recordID); + if (options.noAbandon) { + return; + } if (self.model.canBeAbandoned(recordID)) { self._abandonRecord(recordID); return; @@ -702,21 +705,25 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * re-render (reload the whole form by default) * @param {string[]} [ev.data.fieldNames] list of the record's fields to * reload + * @param {Function} [ev.data.onSuccess] callback executed after reload is resolved + * @param {Function} [ev.data.onFailure] callback executed when reload is rejected */ _onReload: function (ev) { ev.stopPropagation(); // prevent other controllers from handling this request var data = ev && ev.data || {}; var handle = data.db_id; + var prom; if (handle) { // reload the relational field given its db_id - this.model.reload(handle).then(this._confirmSave.bind(this, handle)); + prom = this.model.reload(handle).then(this._confirmSave.bind(this, handle)); } else { // no db_id given, so reload the main record - this.reload({ + prom = this.reload({ fieldNames: data.fieldNames, keepChanges: data.keepChanges || false, }); } + prom.then(ev.data.onSuccess).guardedCatch(ev.data.onFailure); }, /** * Resequence records in the given order. @@ -833,7 +840,8 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { userLanguageValue: ev.target.value || '', dataPointID: record.id, isComingFromTranslationAlert: ev.data.isComingFromTranslationAlert, - isText: record.fields[ev.data.fieldName].type === 'text', + isText: result.context.translation_type === 'text', + showSrc: result.context.translation_show_src, }); return this.translationDialog.open(); }, diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 4b4d02c2755..d4e966440cb 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -94,6 +94,9 @@ var viewUtils = require('web.viewUtils'); var _t = core._t; +// field types that can be aggregated in grouped views +const AGGREGATABLE_TYPES = ['float', 'integer', 'monetary']; + var x2ManyCommands = { // (0, virtualID, {values}) CREATE: 0, @@ -3353,7 +3356,15 @@ var BasicModel = AbstractModel.extend({ var viewType = view ? view.type : fieldInfo.viewType; var toFetch = {}; - _.each(list.data, function (dataPoint) { + + // flattens the list.data ids in a grouped case + let dataPointIds = list.data; + for (let i = 0; i < list.groupedBy.length; i++) { + dataPointIds = dataPointIds.reduce((acc, groupId) => + acc.concat(this.localData[groupId].data), []); + } + + dataPointIds.forEach(function (dataPoint) { var record = self.localData[dataPoint]; if (typeof record.data[fieldName] === 'string'){ // in this case, the value is a local ID, which means that the @@ -4451,8 +4462,9 @@ var BasicModel = AbstractModel.extend({ _.each(groups, function (group) { var aggregateValues = {}; _.each(group, function (value, key) { - if (_.contains(fields, key) && key !== groupByField) { - aggregateValues[key] = value; + if (_.contains(fields, key) && key !== groupByField && + AGGREGATABLE_TYPES.includes(list.fields[key].type)) { + aggregateValues[key] = value; } }); // When a view is grouped, we need to display the name of each group in diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js index 38d2f220c2f..5cb293e866b 100644 --- a/addons/web/static/src/js/views/basic/basic_view.js +++ b/addons/web/static/src/js/views/basic/basic_view.js @@ -282,29 +282,28 @@ var BasicView = AbstractView.extend({ }); } + attrs.views = attrs.views || {}; + + // Keep compatibility with 'tree' syntax + attrs.mode = attrs.mode === 'tree' ? 'list' : attrs.mode; + if (!attrs.views.list && attrs.views.tree) { + attrs.views.list = attrs.views.tree; + } + if (field.type === 'one2many' || field.type === 'many2many') { if (attrs.Widget.prototype.useSubview) { - if (!attrs.views) { - attrs.views = {}; - } var mode = attrs.mode; if (!mode) { - if (attrs.views.tree && attrs.views.kanban) { - mode = 'tree'; - } else if (!attrs.views.tree && attrs.views.kanban) { + if (attrs.views.list && !attrs.views.kanban) { + mode = 'list'; + } else if (!attrs.views.list && attrs.views.kanban) { mode = 'kanban'; } else { - mode = 'tree,kanban'; + mode = 'list,kanban'; } } if (mode.indexOf(',') !== -1) { - mode = config.device.isMobile ? 'kanban' : 'tree'; - } - if (mode === 'tree') { - mode = 'list'; - if (!attrs.views.list && attrs.views.tree) { - attrs.views.list = attrs.views.tree; - } + mode = config.device.isMobile ? 'kanban' : 'list'; } attrs.mode = mode; if (mode in attrs.views) { |
