Odoo更改基本javascript方法 [英] Odoo change base javascript method

查看:141
本文介绍了Odoo更改基本javascript方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Odoo中有一个文件:

There is a file in Odoo: addons/mail/static/src/js/chatter.js . It contains a method I would like to change: message_get_suggested_recipients.

为此,我创建了一个带有文件的插件:

For this I created an addon with files:

chatter.xml

chatter.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!--template id="assets_backend" name="addon1" inherit_id="web.assets_backend"-->
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/addon1/static/src/js/chatter.js"></script>
            </xpath>
        </template>
    </data>
</odoo>

chatter.js

chatter.js

odoo.define('addon1.chatter', function(require){
'use strict';

var OdooChatter = require('mail.Chatter');

OdooChatter.include({
    message_get_suggested_recipients: function () {
    var self = this;
    var email_addresses = _.pluck(this.suggested_partners, 'email_address');
    return this.thread_dataset
        .call('message_get_suggested_recipients', [[this.context.default_res_id], this.context])
        .done(function (suggested_recipients) {
            var thread_recipients = suggested_recipients[self.context.default_res_id];
            _.each(thread_recipients, function (recipient) {
                var parsed_email = utils.parse_email(recipient[1]);
                if (_.indexOf(email_addresses, parsed_email[1]) === -1) {
                    self.suggested_partners.push({
                        checked: recipient[3] || true,
                        partner_id: recipient[0],
                        full_name: recipient[1],
                        name: parsed_email[0],
                        email_address: parsed_email[1],
                        reason: recipient[2],
                    });
                }
            });
        });
    }
});
});

我可以看到在打开Odoo网站时加载了javascript,但是断点没有找到正确的位置,这意味着加载的javascript无效.

I can see that javascript loads when Odoo website is open, but breakpoints don't catch the right place, that means loaded javascript was ineffective.

由于未调用提供的方法(而是调用了原来的方法)而如何更改方法?

推荐答案

将chatter.xml文件修改为:

Modify your chatter.xml file as:

<template id="your_module.assets_backend" inherit_id="web.assets_backend" name="Your custome name">
    <xpath expr="//script[@src='/mail/static/src/js/chatter.js']" position="after">
        <script type="text/javascript" src="/addon1/static/src/js/chatter.js"></script>
    </xpath>
</template>

这在我的Odoo 11上也适用.在您的情况下(Odoo 10),它也应该适用.

This works in my case on Odoo 11. In your case (Odoo 10) it should work as well.

重新查看Odoo的源代码后,因为您想覆盖message_get_suggested_recipients,它是mail.composer.BasicComposer的道具(而不是mail.Chatter),所以我认为您的include应该是:

After re-looking at the Odoo's source code, because you'd like to override the message_get_suggested_recipients which is a prop of mail.composer.BasicComposer (and not mail.Chatter) I think your include should be:

var composer = require('mail.composer');

var ChatterComposer = composer.BasicComposer.include(
    // This goes your work of message_get_suggested_recipients rewrite.
);

这篇关于Odoo更改基本javascript方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆