From 6602e1cf2dccbd0cbdcdf3e5e4547dbc6f0c5b6d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 23 Aug 2019 08:40:16 +0000 Subject: [FIX] web: grouped list with node and onchange MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's assume an editable grouped list view with a node containing subfields, and an onchange. Edit a row to trigger the onchange. Before this rev., it crashed because the onchange specs was incorrect: it followed the relation of the many2one and thus included its subfields (whereas it should only follow the relation for x2many fields). For example, go to Accounting > Accounting > Sales and edit the label of a move line. Task 2044187 closes odoo/odoo#36001 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/js/views/basic/basic_model.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 3bd11a9722a..eca8388aaa4 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2001,9 +2001,11 @@ var BasicModel = AbstractModel.extend({ if (field.onChange) { hasOnchange = true; } - _.each(fieldInfo.views, function (view) { - generateSpecs(view.fieldsInfo[view.type], view.fields, key + '.'); - }); + if (field.type === 'one2many' || field.type === 'many2many') { + _.each(fieldInfo.views, function (view) { + generateSpecs(view.fieldsInfo[view.type], view.fields, key + '.'); + }); + } }); } return hasOnchange ? specs : false; -- cgit v1.2.3 From 029dd1a214f727e25b479610df96b7ee94dd8127 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Tue, 20 Aug 2019 07:46:52 +0000 Subject: [IMP] web: edit translations in new dialog Before this commit, translations were edited in a list view with a filter on the field that needed to be translated. After this commit, the translations for each fields are translated in a dedicated dialog. The changes done to the current language are taken into account immediately, both ways, from the dialog to the form and from the form to the dialog. Translating terms is also available in create mode, the user will be prompted to save before editing a translation Task ID: 2028152 closes odoo/odoo#36185 Signed-off-by: VincentSchippefilt --- .../static/src/js/views/basic/basic_controller.js | 53 ++++++++++++++++------ 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 2163f074cb0..be0b9a00bf3 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -12,6 +12,7 @@ var core = require('web.core'); var Dialog = require('web.Dialog'); var FieldManagerMixin = require('web.FieldManagerMixin'); var Pager = require('web.Pager'); +var TranslationDialog = require('web.TranslationDialog'); var _t = core._t; @@ -331,6 +332,23 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var state = this.model.get(this.handle); return this.renderer.confirmChange(state, id, fields, e); }, + /** + * Ask the user to confirm he wants to save the record + * @private + */ + _confirmSaveNewRecord: function () { + var self = this; + var def = new Promise(function (resolve, reject) { + var message = _t("You need to save this new record before editing the translation. Do you want to proceed?"); + var dialog = Dialog.confirm(self, message, { + title: _t("Warning"), + confirm_callback: resolve.bind(self, true), + cancel_callback: reject, + }); + dialog.on('closed', self, reject); + }); + return def; + }, /** * Delete records (and ask for confirmation if necessary) * @@ -789,28 +807,35 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * @private * @param {OdooEvent} ev */ - _onTranslate: function (ev) { + _onTranslate: async function (ev) { ev.stopPropagation(); - var self = this; - var record = this.model.get(ev.data.id, {raw: true}); - this._rpc({ + + if (this.model.isNew(ev.data.id)) { + await this._confirmSaveNewRecord(); + var updatedFields = await this.saveRecord(ev.data.id, { stayInEdit: true }); + await this._confirmChange(ev.data.id, updatedFields, ev); + } + var record = this.model.get(ev.data.id, { raw: true }); + var result = await this._rpc({ route: '/web/dataset/call_button', params: { model: 'ir.translation', method: 'translate_fields', args: [record.model, record.res_id, ev.data.fieldName], - kwargs: {context: record.getContext()}, + kwargs: { context: record.getContext() }, } - }).then(function (result) { - self.do_action(result, { - on_reverse_breadcrumb: function () { - if (!_.isEmpty(self.renderer.alertFields)) { - self.renderer.displayTranslationAlert(); - } - return false; - }, - }); }); + + this.translationDialog = new TranslationDialog(this, { + domain: result.domain, + searchName: result.context.search_default_name, + fieldName: record.fieldsInfo[record.viewType][ev.data.fieldName].name, + userLanguageValue: ev.target.value || '', + dataPointID: record.id, + isComingFromTranslationAlert: ev.data.isComingFromTranslationAlert, + isText: record.fields[ev.data.fieldName].type === 'text', + }); + return this.translationDialog.open(); }, }); -- cgit v1.2.3 From 39e5d93c97e96514a3b48ab8c35f24b4400a200e Mon Sep 17 00:00:00 2001 From: RomainLibert Date: Mon, 9 Sep 2019 12:45:16 +0000 Subject: [FIX] web: use New as default value for breadcrumb Before this commit if `display_name` was in the view, the breadcrumb when creating a new record, the breadcrumb would display either `Unnamed`, either the last value of `_title` in `action_mixin`. The default value when creating a record should be `New`, but the return was ignored because `display_name` was found in the view closes odoo/odoo#36565 Signed-off-by: Yannick Tivisse (yti) --- addons/web/static/src/js/views/basic/basic_model.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 f7005a11b9a..614602a5791 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -678,13 +678,14 @@ var BasicModel = AbstractModel.extend({ */ getName: function (id) { var record = this.localData[id]; + var returnValue = ''; if (record._changes && 'display_name' in record._changes) { - return record._changes.display_name; + returnValue = record._changes.display_name; } - if ('display_name' in record.data) { - return record.data.display_name; + else if ('display_name' in record.data) { + returnValue = record.data.display_name; } - return _t("New"); + return returnValue || _t("New"); }, /** * Returns true if a record is dirty. A record is considered dirty if it has -- cgit v1.2.3