diff options
| author | Denis Ledoux <dle@odoo.com> | 2019-12-24 13:01:23 +0000 |
|---|---|---|
| committer | Denis Ledoux <dle@odoo.com> | 2020-02-03 16:16:01 +0000 |
| commit | 355cb456034981f9b4bf24c47f63589593c40779 (patch) | |
| tree | b4dbff81f5c4fb876a129a44534496a365169c39 /addons/base_automation/static/src | |
| parent | dc1402c79bc23c5303e190808075b708986689cd (diff) | |
[IMP] base_automation, web: give possibility to disable/edit failing automated actions
If an automated action raises an exception, in the traceback modal:
- For admins, display Disable & Edit automated action buttons
to be able to directly know with wihch automated action the error occurred,
and to give the possibility to edit or disable it quickly,
- For regular users, just add a paragraph to tell with which automated action the error occurred,
so they can give this useful information to their administrator
This is specially useful for databases which have just been
upgraded to a newer version, and for which the server action
is failing because its code is no longer supported.
closes odoo/odoo#44513
X-original-commit: 8f3940c132bbbc99e47fa3f0cba0e768159d9af2
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
Diffstat (limited to 'addons/base_automation/static/src')
| -rw-r--r-- | addons/base_automation/static/src/js/base_automation_error_dialog.js | 78 | ||||
| -rw-r--r-- | addons/base_automation/static/src/xml/base_automation_error_dialog.xml | 36 |
2 files changed, 114 insertions, 0 deletions
diff --git a/addons/base_automation/static/src/js/base_automation_error_dialog.js b/addons/base_automation/static/src/js/base_automation_error_dialog.js new file mode 100644 index 00000000000..3fa4cf0cc06 --- /dev/null +++ b/addons/base_automation/static/src/js/base_automation_error_dialog.js @@ -0,0 +1,78 @@ +odoo.define('base_automation.BaseAutomatioErrorDialog', function (require) { + "use strict"; + + const CrashManager = require('web.CrashManager'); + const ErrorDialog = CrashManager.ErrorDialog; + const ErrorDialogRegistry = require('web.ErrorDialogRegistry'); + const session = require('web.session'); + + const BaseAutomationErrorDialog = ErrorDialog.extend({ + xmlDependencies: (ErrorDialog.prototype.xmlDependencies || []).concat( + ['/base_automation/static/src/xml/base_automation_error_dialog.xml'] + ), + template: 'CrashManager.BaseAutomationError', + events: { + 'click .o_disable_action_button': '_onDisableAction', + 'click .o_edit_action_button': '_onEditAction', + }, + /** + * Assign the `base_automation` object based on the error data, + * which is then used by the `CrashManager.BaseAutomationError` template + * and the events defined above. + * @override + * @param {Object} error + * @param {string} error.data.context.base_automation.id the ID of the failing automated action + * @param {string} error.data.context.base_automation.name the name of the failing automated action + */ + init: function (parent, options, error) { + this._super.apply(this, arguments); + this.base_automation = error.data.context.base_automation; + this.is_admin = session.is_admin; + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * This method is called when the user clicks on the 'Disable action' button + * displayed when a crash occurs in the evaluation of an automated action. + * Then, we write `active` to `False` on the automated action to disable it. + * + * @private + * @param {MouseEvent} ev + */ + _onDisableAction: function (ev) { + ev.preventDefault(); + this._rpc({ + model: 'base.automation', + method: 'write', + args: [[this.base_automation.id], { + active: false, + }], + }).then(this.destroy.bind(this)); + }, + /** + * This method is called when the user clicks on the 'Edit action' button + * displayed when a crash occurs in the evaluation of an automated action. + * Then, we redirect the user to the automated action form. + * + * @private + * @param {MouseEvent} ev + */ + _onEditAction: function (ev) { + ev.preventDefault(); + this.do_action({ + name: 'Automated Actions', + res_model: 'base.automation', + res_id: this.base_automation.id, + views: [[false, 'form']], + type: 'ir.actions.act_window', + view_mode: 'form', + }); + }, + }); + + ErrorDialogRegistry.add('base_automation', BaseAutomationErrorDialog); + +}); diff --git a/addons/base_automation/static/src/xml/base_automation_error_dialog.xml b/addons/base_automation/static/src/xml/base_automation_error_dialog.xml new file mode 100644 index 00000000000..e45c59117ec --- /dev/null +++ b/addons/base_automation/static/src/xml/base_automation_error_dialog.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<templates> + <t t-name="CrashManager.BaseAutomationError" t-extend="CrashManager.error"> + <t t-jquery=".alert.alert-warning" t-operation="append"> + <t t-if="widget.base_automation.id"> + <p> + The error occurred during the execution of the automated action + "<t t-esc="widget.base_automation.name"/>" + (ID: <t t-esc="widget.base_automation.id"/>). + <br/> + </p> + <p t-if="!widget.is_admin"> + You can ask an administrator to disable or correct this automated action. + </p> + <p t-if="widget.is_admin"> + You can disable this automated action or edit it to solve the issue.<br/> + Disabling this automated action will enable you to continue your workflow + but any data created after this could potentially be corrupted, + as you are effectively disabling a customization that may set + important and/or required fields. + </p> + </t> + </t> + <t t-jquery=".alert.alert-warning button" t-operation="after"> + <t t-if="widget.base_automation.id && widget.is_admin"> + <button class="btn btn-secondary mt4 o_disable_action_button"> + <i class="fa fa-ban mr8"/>Disable Action + </button> + <button class="btn btn-secondary mt4 o_edit_action_button"> + <i class="fa fa-edit mr8"/>Edit action + </button> + </t> + </t> + </t> +</templates> |
