[IMP] *: display some onchange warning with notif

* = base, web, sale, stock, sale_stock, stock_account

Warnings for the onchange now takes a type to know if it needs to be
displayed with a notification. Else it is displayed with a dialog
notification (like before).

Related to https://github.com/odoo/odoo/pull/32132 and
https://github.com/odoo/odoo/pull/35209

Part of https://github.com/odoo/odoo/pull/35342

task-2047628

closes odoo/odoo#35342

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
fja-odoo
2019-08-09 15:47:09 +00:00
parent 79d7904b4f
commit 20efea970a
5 changed files with 65 additions and 13 deletions
@@ -396,7 +396,8 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi
title: data.title,
}, data).open();
} else {
this.call('notification', 'notify', e.data);
data.type = 'warning';
this.call('notification', 'notify', data);
}
},
/**
@@ -4059,11 +4059,7 @@ var BasicModel = AbstractModel.extend({
return;
}
if (result.warning) {
self.trigger_up('warning', {
message: result.warning.message,
title: result.warning.title,
type: 'dialog',
});
self.trigger_up('warning', result.warning);
record._warning = true;
}
if (result.domain) {
+52 -2
View File
@@ -3026,7 +3026,8 @@ QUnit.module('Views', {
value: { int_field: 10 },
warning: {
title: "Warning",
message: "You must first select a partner"
message: "You must first select a partner",
type: 'dialog',
}
});
}
@@ -3055,6 +3056,55 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('display a notificaton if onchange result is a warning with type notification', async function (assert) {
assert.expect(5);
this.data.partner.onchanges = { foo: true };
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<group><field name="foo"/><field name="int_field"/></group>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (args.method === 'onchange') {
return Promise.resolve({
value: { int_field: 10 },
warning: {
title: "Warning",
message: "You must first select a partner",
type: 'notification',
}
});
}
return this._super.apply(this, arguments);
},
intercepts: {
warning: function (event) {
assert.strictEqual(event.data.type, 'notification',
"should have triggered an event with the correct data");
assert.strictEqual(event.data.title, "Warning",
"should have triggered an event with the correct data");
assert.strictEqual(event.data.message, "You must first select a partner",
"should have triggered an event with the correct data");
},
},
});
await testUtils.form.clickEdit(form);
assert.strictEqual(form.$('input[name=int_field]').val(), '9');
await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala');
assert.strictEqual(form.$('input[name=int_field]').val(), '10');
form.destroy();
});
QUnit.test('can create record even if onchange returns a warning', async function (assert) {
assert.expect(2);
@@ -3114,7 +3164,7 @@ QUnit.module('Views', {
value: {},
warning: {
title: "Warning",
message: "You must first select a partner"
message: "You must first select a partner",
}
});
}
+3 -1
View File
@@ -170,8 +170,10 @@ def onchange(*args):
return {
'domain': {'other_id': [('partner_id', '=', partner_id)]},
'warning': {'title': "Warning", 'message': "What is this?"},
'warning': {'title': "Warning", 'message': "What is this?", 'type': 'notification'},
}
If the type is set to notification, the warning will be displayed in a notification.
Otherwise it will be displayed in a dialog as default.
.. warning::
+7 -4
View File
@@ -5388,6 +5388,7 @@ Fields:
result['warnings'].add((
res['warning'].get('title') or _("Warning"),
res['warning'].get('message') or "",
res['warning'].get('type') or "",
))
if onchange in ("1", "true"):
@@ -5611,13 +5612,15 @@ Fields:
# format warnings
warnings = result.pop('warnings')
if len(warnings) == 1:
title, message = warnings.pop()
result['warning'] = dict(title=title, message=message)
title, message, type = warnings.pop()
if not type:
type = 'dialog'
result['warning'] = dict(title=title, message=message, type=type)
elif len(warnings) > 1:
# concatenate warning titles and messages
title = _("Warnings")
message = "\n\n".join(itertools.chain(*warnings))
result['warning'] = dict(title=title, message=message)
message = '\n\n'.join([warn_title + '\n\n' + warn_message for warn_title, warn_message, warn_type in warnings])
result['warning'] = dict(title=title, message=message, type='dialog')
return result