diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/base_automation/static | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/base_automation/static')
3 files changed, 186 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 00000000..3fa4cf0c --- /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 00000000..e45c5911 --- /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> diff --git a/addons/base_automation/static/tests/base_automation_error_dialog.js b/addons/base_automation/static/tests/base_automation_error_dialog.js new file mode 100644 index 00000000..af2e9ff6 --- /dev/null +++ b/addons/base_automation/static/tests/base_automation_error_dialog.js @@ -0,0 +1,72 @@ +odoo.define('base_automation.BaseAutomatioErrorDialogTests', function (require) { +'use strict'; + + const CrashManager = require('web.CrashManager').CrashManager; + const session = require('web.session'); + + QUnit.module('base_automation', {}, function () { + + QUnit.module('Error Dialog'); + + QUnit.test('Error due to an automated action', async function (assert) { + assert.expect(4); + + let baseAutomationName = 'Test base automation error dialog'; + let error = { + type: 'Odoo Client Error', + message: 'Message', + data: { + debug: 'Traceback', + context: { + exception_class: 'base_automation', + base_automation: { + id: 1, + name: baseAutomationName, + }, + }, + }, + }; + // Force the user session to be admin, to display the disable and edit action buttons, + // then reset back to the origin value after the test. + let isAdmin = session.is_admin; + session.is_admin = true; + + let crashManager = new CrashManager(); + let dialog = crashManager.show_error(error); + + await dialog._opened; + + assert.containsOnce(document.body, '.modal .o_clipboard_button'); + assert.containsOnce(document.body, '.modal .o_disable_action_button'); + assert.containsOnce(document.body, '.modal .o_edit_action_button'); + assert.ok(dialog.$el.text().indexOf(baseAutomationName) !== -1); + + session.is_admin = isAdmin; + crashManager.destroy(); + }); + + QUnit.test('Error not due to an automated action', async function (assert) { + assert.expect(3); + + let error = { + type: 'Odoo Client Error', + message: 'Message', + data: { + debug: 'Traceback', + }, + }; + let crashManager = new CrashManager(); + let dialog = crashManager.show_error(error); + + await dialog._opened; + + assert.containsOnce(document.body, '.modal .o_clipboard_button'); + assert.containsNone(document.body, '.modal .o_disable_action_button'); + assert.containsNone(document.body, '.modal .o_edit_action_button'); + + crashManager.destroy(); + }); + + }); + +}); |
