Odoo机会新消息取消选中收件人
Odoo opportunity new message uncheck recipient
在 Odoo 中,当我打开来自 "My pipeline" 的商机并在该商机上按下按钮 "New message" 时,该商机的客户(以及该商机的关注者)将作为该消息的接收者出现:
在该消息的收件人列表中,该客户姓名附近有一个选中的复选框。
这是因为文件 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>
将鼠标悬停在不需要的收件人之一上会显示以下消息 "Adds as recipient and follower (reason: Customer)"。
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_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_add_suggested_recipient(在crm_lead.py
)为
合作伙伴包含 "checked" = False。
修改message_get_suggested_recipients(在chatter.js
)进行检查
默认情况下,参数 recipient
的值而不是 true
(checked: true
).
在 /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 进行了测试。
修改 CZoellner 先生提供的 之后。谢谢!:)
我想出了一个解决方案:只是不知道如何将其打包为插件。
查看已更改的注释行。
改变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...
}
static/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],
});
}
});
});
}
});
});
views/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/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
安装此插件后,我可以观察到 javascript(来自插件)在 Odoo 网站打开时加载,但断点没有找到正确的位置(发出 "New message" 时),即表示已加载 javascript 无效。
怎么了?
在 Odoo 中,当我打开来自 "My pipeline" 的商机并在该商机上按下按钮 "New message" 时,该商机的客户(以及该商机的关注者)将作为该消息的接收者出现:
在该消息的收件人列表中,该客户姓名附近有一个选中的复选框。
这是因为文件 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>
将鼠标悬停在不需要的收件人之一上会显示以下消息 "Adds as recipient and follower (reason: Customer)"。
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_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_add_suggested_recipient(在
crm_lead.py
)为 合作伙伴包含 "checked" = False。修改message_get_suggested_recipients(在
chatter.js
)进行检查 默认情况下,参数recipient
的值而不是true
(checked: true
).
在 /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 进行了测试。
修改 CZoellner 先生提供的
我想出了一个解决方案:只是不知道如何将其打包为插件。
查看已更改的注释行。
改变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...
}
static/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],
});
}
});
});
}
});
});
views/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/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
安装此插件后,我可以观察到 javascript(来自插件)在 Odoo 网站打开时加载,但断点没有找到正确的位置(发出 "New message" 时),即表示已加载 javascript 无效。
怎么了?