Odoo改变基础javascript方法

时间:2018-04-17 10:10:12

标签: javascript class odoo odoo-10

Odoo中有一个文件:addons/mail/static/src/js/chatter.js。它包含我想要更改的方法:message_get_suggested_recipients

为此我创建了一个包含文件的插件:

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

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无效。

如何更改方法,因为我没有调用我提供的方法(而是调用原始方法)?

1 个答案:

答案 0 :(得分:1)

将chatter.xml文件修改为:

<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)它应该也可以。

重新查看Odoo的源代码后,因为您想要覆盖message_get_suggested_recipients mail.composer.BasicComposer(而不是mail.Chatter)的支柱,我认为您的{{ 1}}应该是:

include