[FIX] web: prevent translation alert from flickering

Before this commit, the translation alert might briefly appear in
form views displayed in dialogs (on new records), just before the
dialog closes.

Task 2639227

closes odoo/odoo#77002

X-original-commit: c9aa20160cd8b1bc9c9bdcd34bb996b8dfefc291
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Prakash Prajapati
2021-09-23 07:17:47 +00:00
committed by Aaron Bohy
parent 36988d0edc
commit a61c2ec715
2 changed files with 41 additions and 2 deletions
@@ -130,8 +130,10 @@ var FormRenderer = BasicRenderer.extend({
* @param {Object} alertFields
*/
updateAlertFields: function (alertFields) {
this.alertFields[this.state.res_id] = _.extend(this.alertFields[this.state.res_id] || {}, alertFields);
this.displayTranslationAlert();
if (this.state.res_id) {
this.alertFields[this.state.res_id] = _.extend(this.alertFields[this.state.res_id] || {}, alertFields);
this.displayTranslationAlert();
}
},
/**
* Show a warning message if the user modified a translated field. For each
@@ -14,6 +14,7 @@ var mixins = require('web.mixins');
var pyUtils = require('web.py_utils');
var RamStorage = require('web.RamStorage');
var testUtils = require('web.test_utils');
var ViewDialogs = require('web.view_dialogs');
var widgetRegistry = require('web.widget_registry');
const widgetRegistryOwl = require('web.widgetRegistry');
var Widget = require('web.Widget');
@@ -7088,6 +7089,42 @@ QUnit.module('Views', {
_t.database.multi_lang = multi_lang;
});
QUnit.test('check the translate alert in the wizard', async function (assert) {
assert.expect(1);
// Check whether it is alert before the dialog closes
testUtils.mock.patch(ViewDialogs.FormViewDialog, {
close() {
assert.containsNone(this.$el, '.o_notification_box');
this._super(...arguments);
},
});
this.data.product.fields.name.translate = true;
const multi_lang = _t.database.multi_lang;
_t.database.multi_lang = true;
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: `<form><field name="product_id"/></form>`,
archs: {
'product,false,form': `<form><field name="name"/></form>`,
},
res_id: 1,
});
await testUtils.form.clickEdit(form);
await testUtils.fields.many2one.createAndEdit('product_id', "Ralts");
await testUtils.dom.click($('.modal-footer button.btn-primary'));
form.destroy();
testUtils.mock.unpatch(ViewDialogs.FormViewDialog);
_t.database.multi_lang = multi_lang;
});
QUnit.test('buttons are disabled until status bar action is resolved', async function (assert) {
assert.expect(9);