diff options
| author | fja-odoo <fja@odoo.com> | 2019-08-09 09:58:32 +0000 |
|---|---|---|
| committer | fja-odoo <fja@odoo.com> | 2019-08-09 15:47:09 +0000 |
| commit | 20efea970af8d74b06d11d709982429678d35e25 (patch) | |
| tree | 9485ada7c3945cbaacf8d49305e3a913182b5ea3 | |
| parent | 79d7904b4f650b38c80239fca38bcec39a373580 (diff) | |
[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>
| -rw-r--r-- | addons/web/static/src/js/chrome/abstract_web_client.js | 3 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 6 | ||||
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 54 | ||||
| -rw-r--r-- | odoo/api.py | 4 | ||||
| -rw-r--r-- | odoo/models.py | 11 |
5 files changed, 65 insertions, 13 deletions
diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js index 2d94501deed..cd1109a98ce 100644 --- a/addons/web/static/src/js/chrome/abstract_web_client.js +++ b/addons/web/static/src/js/chrome/abstract_web_client.js @@ -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); } }, /** 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 de915c82152..00a1be6c228 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -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) { diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index bc47d849258..4370f4034e0 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -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", } }); } diff --git a/odoo/api.py b/odoo/api.py index 87534567cfe..f4eeae44516 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -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:: diff --git a/odoo/models.py b/odoo/models.py index 07b2fd7a341..2c4ad698b27 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -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 |
