Odoo change base javascript method

守給你的承諾、 提交于 2019-12-12 00:54:46

问题


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

<?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>

and

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],
                    });
                }
            });
        });
    }
});
});

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.

How to change the method because my provided method isn't called (instead the original is called)?


回答1:


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>

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


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.
);


来源:https://stackoverflow.com/questions/49875355/odoo-change-base-javascript-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!