Search code examples
javascriptodoo-13qweb

Modify Crash_manager on Odoo_13


Hello guys I'm trying to modify the error window that odoo shows when an error occurs to only shows the button see details and copy to clipboard to specific user groups, I tried to change the crash_manager.xml on web module, but the changes made only can be seen when I'm in developer mode in odoo, and I don't have good knowledge in JavaScript to change the crash_manager.js but if you can give me an insight of how achieve this, you will help me a lot.


Solution

  • To patch the crash_manager class, you will need to understand how Odoo manage assets.

    You have to include the script in the web.assets_backend which contains the code specific to the web client.

    <template id="assets_backend" name="My assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/<Module name>/static/src/js/crash_manager.js"></script>
        </xpath>
    </template>
    

    In the following code, we will define a new widget attribute visibilitythat we can use later in the template to control the visibility of the buttons:

    odoo.define('<Module name>.CrashManager', function (require) {
    "use strict";
        var ErrorDialog = require('web.CrashManager').ErrorDialog;
        var session = require('web.session');
        ErrorDialog.include({
            init: function (parent, options, error) {
                var self = this;
                this._super.apply(this, [parent, options, error]);
                // this.visibility = session.is_system?'visible': "hidden";
                session.user_has_group('base.group_system').then(function(has_group){
                    self.visibility = has_group?'visible': "hidden";
                });
            },
        });
    });
    

    Hiding Details and Copy buttons will make the message obsolete, so you need to change it.

    In the following example, we alter the CrashManager.error template to define a style attribute for the Copy the full error to clipboard and See details buttons:

    <t t-extend="CrashManager.error">
        <t t-jquery="div.float-right" t-operation="attributes">
            <attribute name="t-att-style">'visibility: ' + widget.visibility</attribute>
        </t>
        <t t-jquery="button" t-operation="attributes">
            <attribute name="t-att-style">'visibility: ' + widget.visibility</attribute>
        </t>
    </t>