简体   繁体   中英

How override in js file odoo 9

I need override in below function ASC to DESC

render: function (messages, options) {
        clearTimeout(this.auto_render_timeout);
        var self = this;
        var msgs = _.map(messages, this._preprocess_message.bind(this));
        if (this.options.display_order === ORDER.ASC) {
            msgs.reverse();
        }

Source code: https://postimg.org/image/9mxw6ksy7/67729f63/

You need to replace the function and then call _super(). Include your method in the class which implements this function. A similar question is posted HERE with a specific implementation which has been tested. My below example has not been tested fully. Remember to install your addon and update it to see your changes.

}
'name': "asc_desc",

'summary': """
    Short (1 phrase/line) summary of the module's purpose, used as
    subtitle on modules listing or apps.openerp.com""",

'description': """
    Long description of module's purpose
""",

'author': "My Company",
'website': "http://www.yourcompany.com",

# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',

# any module necessary for this one to work correctly
'depends': ['base'],

# always loaded
'data': [
    # 'security/ir.model.access.csv',
    'views.xml',
    'templates.xml',
    'javascript_import.xml',
],
# only loaded in demonstration mode
'demo': [
    'demo.xml',
],
}

javascript_import.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <openerp>
     <data>
         <template id="assets_backend_asc_desc" name="assets_backend_asc_desc" inherit_id="web.assets_backend">
             <xpath expr="script[last()]" position="after">
                 <script type="text/javascript" src="/asc_desc/static/src/js/asc.js"></script>
             </xpath>
         </template>
     </data>
 </openerp>

asc.js

odoo.define('asc_desc.ChatThread', function(require){
"use strict"
var core = require('web.core');
var QWeb = core.qweb;
var thread = require('mail.ChatThread');

var ORDER = {
    DESC: -1,
    ASC: 1,
}

thread.include({
    render: function (messages, options) {
        console.log("TEST");
        var msgs = _.map(messages, this._preprocess_message.bind(this));
        if (this.options.display_order === ORDER.DESC) {
            msgs.reverse();
        }
        options = _.extend({}, this.options, options);

        // Hide avatar and info of a message if that message and the previous
        // one are both comments wrote by the same author at the same minute
        var prev_msg;
        _.each(msgs, function (msg) {
            if (!prev_msg || (Math.abs(msg.date.diff(prev_msg.date)) > 60000) || prev_msg.message_type !== 'comment' || msg.message_type !== 'comment' || (prev_msg.author_id[0] !== msg.author_id[0])) {
                msg.display_author = true;
            } else {
                msg.display_author = !options.squash_close_messages;
            }
            prev_msg = msg;
        });

        this.$el.html(QWeb.render('mail.ChatThread', {
            messages: msgs,
            options: options,
            ORDER: ORDER,
        }));
    },

});

});

Ensure you include the file declaring your js in your __openerp__.py file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM