我需要覆盖以下功能ASC到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();
}
答案 0 :(得分:0)
您需要替换该函数,然后调用_super()。在实现此函数的类中包含您的方法。类似的问题已发布HERE,其中包含已经过测试的特定实施。我的下面的例子还没有完全测试过。请务必安装您的插件并对其进行更新以查看更改。
}
'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,
}));
},
});
});
确保在__openerp__.py
文件中包含声明js的文件。