在Odoo中,当我从“我的管道”中打开机会时,我按下“新消息”按钮,然后来自该机会的客户(以及该机会的追随者)作为该消息的接收者:
该消息的收件人列表中该客户名称附近有一个选中的复选框。
这是因为文件jwks
具有:
addons/mail/static/src/xml/chatter.xml
将鼠标悬停在其中一个不受欢迎的收件人上会显示以下消息“添加为收件人和关注者(原因:客户)”。
<!-- List of followers -->
<div class="o_composer_suggested_partners">
<t t-foreach='widget.suggested_partners' t-as='recipient'>
<div t-attf-title="Add as recipient and follower (reason: #{recipient.reason})">
<input type="checkbox"
t-att-checked="recipient.checked ? 'checked' : undefined"
t-att-data-fullname="recipient.full_name"/>
<t t-esc="recipient.name"/>
<t t-if="recipient.email_address">(<t t-esc="recipient.email_address"/>)</t>
</div>
</t>
</div>
addons/crm/models/crm_lead.py
并在@api.multi
def _message_add_suggested_recipient(self, result, partner=None, email=None, reason=''):
""" Called by message_get_suggested_recipients, to add a suggested
recipient in the result dictionary. The form is :
partner_id, partner_name<partner_email> or partner_name, reason """
self.ensure_one()
if email and not partner:
# get partner info from email
partner_info = self.message_partner_info_from_emails([email])[0]
if partner_info.get('partner_id'):
partner = self.env['res.partner'].sudo().browse([partner_info['partner_id']])[0]
if email and email in [val[1] for val in result[self.ids[0]]]: # already existing email -> skip
return result
if partner and partner in self.message_partner_ids: # recipient already in the followers -> skip
return result
if partner and partner.id in [val[0] for val in result[self.ids[0]]]: # already existing partner ID -> skip
return result
if partner and partner.email: # complete profile: id, name <email>
result[self.ids[0]].append((partner.id, '%s<%s>' % (partner.name, partner.email), reason))
elif partner: # incomplete profile: id, name
result[self.ids[0]].append((partner.id, '%s' % (partner.name), reason))
else: # unknown partner, we are probably managing an email address
result[self.ids[0]].append((False, email, reason))
return result
@api.multi
def message_get_suggested_recipients(self):
""" Returns suggested recipients for ids. Those are a list of
tuple (partner_id, partner_name, reason), to be managed by Chatter. """
result = dict((res_id, []) for res_id in self.ids)
if 'user_id' in self._fields:
for obj in self.sudo(): # SUPERUSER because of a read on res.users that would crash otherwise
if not obj.user_id or not obj.user_id.partner_id:
continue
obj._message_add_suggested_recipient(result, partner=obj.user_id.partner_id, reason=self._fields['user_id'].string)
return result
addons/mail/static/src/js/chatter.js
有没有办法在这里为客户默认选中复选框?
这是对的吗?
修改_message_add_suggested_recipient(在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: true,
partner_id: recipient[0],
full_name: recipient[1],
name: parsed_email[0],
email_address: parsed_email[1],
reason: recipient[2],
});
}
});
});
},
中)到
包含“已检查”=对于合作伙伴为假。
修改message_get_suggested_recipients(在crm_lead.py
中)以进行检查
参数chatter.js
的值,而不是默认情况下recipient
(true
)。
答案 0 :(得分:1)
在/static/src/xml/chatter.xml
的模块中创建一个文件,其中包含以下内容:
<templates>
<t t-name="mail.chatter.ChatComposer" t-extend="mail.chatter.ChatComposer">
<t
t-jquery="input[type='checkbox'][t-att-data-fullname='recipient.full_name']"
t-operation="replace">
<input type="checkbox" t-att-data-fullname="recipient.full_name" />
</t>
</t>
</templates>
然后在清单中调用此文件:
{
# name, author, ...
'qweb': [
'static/src/xml/chatter.xml'
],
}
注意:这将改变Odoo中所有聊天的行为。它仅针对v10进行了测试。
答案 1 :(得分:0)
在修补CZoellner先生提供的solution之后。谢谢!:)
我提出了一个解决方案:不知道如何将其打包成插件。
查看已注释的行已更改。
更改addons/mail/static/src/js/chatter.js
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: true,
checked: recipient[3] || true,
partner_id: recipient[0],
full_name: recipient[1],
name: parsed_email[0],
email_address: parsed_email[1],
reason: recipient[2],
});
}
});
});
},
addons/mail/models/mail_thread.py
@api.multi
def _message_add_suggested_recipient(self, result, partner=None, email=None, reason=''):
""" Called by message_get_suggested_recipients, to add a suggested
recipient in the result dictionary. The form is :
partner_id, partner_name<partner_email> or partner_name, reason """
self.ensure_one()
if email and not partner:
# get partner info from email
partner_info = self.message_partner_info_from_emails([email])[0]
if partner_info.get('partner_id'):
partner = self.env['res.partner'].sudo().browse([partner_info['partner_id']])[0]
if email and email in [val[1] for val in result[self.ids[0]]]: # already existing email -> skip
return result
if partner and partner in self.message_partner_ids: # recipient already in the followers -> skip
return result
if partner and partner.id in [val[0] for val in result[self.ids[0]]]: # already existing partner ID -> skip
return result
if partner and partner.email: # complete profile: id, name <email>
#result[self.ids[0]].append((partner.id, '%s<%s>' % (partner.name, partner.email), reason))
result[self.ids[0]].append((partner.id, '%s<%s>' % (partner.name, partner.email), reason, False))
elif partner: # incomplete profile: id, name
result[self.ids[0]].append((partner.id, '%s' % (partner.name), reason))
else: # unknown partner, we are probably managing an email address
result[self.ids[0]].append((False, email, reason))
return result
这很有效!
为了将其作为Odoo中的插件,我创建了以下内容的插件:
<强>清单强>的.py
# -*- coding: utf-8 -*-
{
...omitted for brewity...
'depends': ['base','crm','mail'],
'data': [
'views/chatter.xml'
]
...omitted for brewity...
}
静态/ SRC / JS / chatter.js
odoo.define('addon1.chatter', function(require){
'use strict';
var composer = require('mail.composer');
composer.BasicComposer.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],
});
}
});
});
}
});
});
视图/ 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>
模型/ models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api, tools
from odoo.addons.mail.models.mail_thread import MailThread
class addon1(models.AbstractModel):
_inherit = 'mail.thread'
@api.multi
def _message_add_suggested_recipient(self, result, partner=None, email=None, reason=''):
result = super(MailThread, self)._message_add_suggested_recipient(self, result, partner, email, reason)
if partner and partner.email: # complete profile: id, name <email>
result[self.ids[0]].append((partner.id, '%s<%s>' % (partner.name, partner.email), reason, False))
return result
在安装了这个插件之后,我可以观察到当Odoo网站打开时,javascript(来自插件)会加载,但断点不会抓住正确的位置(当发出&#34;新消息&#34;)时,意味着加载的javascript无效。
有什么问题?