mirror of https://github.com/OCA/social.git
commit
bcb1bb5a13
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es>
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Mail Show Follower",
|
||||||
|
"summary": "Show CC document followers in mails.",
|
||||||
|
"version": "12.0.1.0.0",
|
||||||
|
"category": "Mail",
|
||||||
|
"website": "https://github.com/OCA/social",
|
||||||
|
"author": "Sygel, Odoo Community Association (OCA)",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"application": False,
|
||||||
|
"installable": True,
|
||||||
|
"depends": [
|
||||||
|
"base",
|
||||||
|
"mail"
|
||||||
|
],
|
||||||
|
"data": [
|
||||||
|
"views/res_config_settings.xml",
|
||||||
|
"views/res_users.xml"
|
||||||
|
],
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
from . import mail_mail
|
||||||
|
from . import res_company
|
||||||
|
from . import res_config_settings
|
||||||
|
from . import res_users
|
|
@ -0,0 +1,81 @@
|
||||||
|
from odoo import models, api
|
||||||
|
|
||||||
|
|
||||||
|
class MailMail(models.Model):
|
||||||
|
_inherit = "mail.mail"
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
|
||||||
|
plain_text = (
|
||||||
|
'<div summary="o_mail_notification" style="padding: 0px; '
|
||||||
|
'font-size: 10px;"><b>CC</b>: %s<hr style="background-color:'
|
||||||
|
'rgb(204,204,204);border:medium none;clear:both;display:block;'
|
||||||
|
'font-size:0px;min-height:1px;line-height:0; margin:4px 0 12px 0;"></div>'
|
||||||
|
)
|
||||||
|
group_portal = self.env.ref('base.group_portal')
|
||||||
|
for mail_id in self.ids:
|
||||||
|
mail = self.browse(mail_id)
|
||||||
|
# if the email has a model, id and it belongs to the portal group
|
||||||
|
if mail.model and mail.res_id and group_portal:
|
||||||
|
obj = self.env[mail.model].browse(mail.res_id)
|
||||||
|
# those partners are obtained, who do not have a user and
|
||||||
|
# if they do it must be a portal, we exclude internal
|
||||||
|
# users of the system.
|
||||||
|
if hasattr(obj, "message_follower_ids"):
|
||||||
|
partners_obj = obj.message_follower_ids.mapped('partner_id')
|
||||||
|
# internal partners
|
||||||
|
user_partner_ids = self.env['res.users'].search([
|
||||||
|
('active', 'in', (True, False)),
|
||||||
|
('show_in_cc', '=', False),
|
||||||
|
]).filtered(
|
||||||
|
lambda x: group_portal not in x.groups_id
|
||||||
|
).mapped('partner_id').ids
|
||||||
|
partners_len = len(partners_obj.filtered(
|
||||||
|
lambda x: x.id not in user_partner_ids and (
|
||||||
|
not x.user_ids or group_portal in x.user_ids.groups_id
|
||||||
|
)))
|
||||||
|
if partners_len > 1:
|
||||||
|
# get partners
|
||||||
|
cc_internal = True
|
||||||
|
# else get company in object
|
||||||
|
if hasattr(obj, "company_id") and obj.company_id:
|
||||||
|
cc_internal = obj.company_id.show_internal_users_cc
|
||||||
|
# get company in user
|
||||||
|
elif mail.env and mail.env.user and mail.env.user.company_id:
|
||||||
|
cc_internal = self.env.user.company_id.\
|
||||||
|
show_internal_users_cc
|
||||||
|
if cc_internal:
|
||||||
|
partners = partners_obj.filtered(
|
||||||
|
lambda x: x.id not in user_partner_ids and (
|
||||||
|
not x.user_ids or x.user_ids.show_in_cc
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
partners = partners_obj.filtered(
|
||||||
|
lambda x: x.id not in user_partner_ids and (
|
||||||
|
not x.user_ids or group_portal in
|
||||||
|
x.user_ids.groups_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
partners = partners.filtered(
|
||||||
|
lambda x:
|
||||||
|
not x.user_ids
|
||||||
|
or
|
||||||
|
# otherwise, email is not sent
|
||||||
|
x.user_ids and "email" in x.user_ids.mapped(
|
||||||
|
"notification_type")
|
||||||
|
)
|
||||||
|
# get names and emails
|
||||||
|
final_cc = None
|
||||||
|
mails = ""
|
||||||
|
for p in partners:
|
||||||
|
mails += "%s <%s>, " % (p.name, p.email)
|
||||||
|
# join texts
|
||||||
|
final_cc = plain_text % (mails[:-2])
|
||||||
|
# it is saved in the body_html field so that it does
|
||||||
|
# not appear in the odoo log
|
||||||
|
mail.body_html = final_cc + mail.body_html
|
||||||
|
return super(MailMail, self)._send(
|
||||||
|
auto_commit=auto_commit, raise_exception=raise_exception,
|
||||||
|
smtp_session=smtp_session
|
||||||
|
)
|
|
@ -0,0 +1,10 @@
|
||||||
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class ResCompany(models.Model):
|
||||||
|
_inherit = "res.company"
|
||||||
|
|
||||||
|
show_internal_users_cc = fields.Boolean(
|
||||||
|
string='Show Internal Users CC',
|
||||||
|
default=True
|
||||||
|
)
|
|
@ -0,0 +1,11 @@
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResConfigSettings(models.TransientModel):
|
||||||
|
_inherit = 'res.config.settings'
|
||||||
|
|
||||||
|
show_internal_users_cc = fields.Boolean(
|
||||||
|
string='Show Internal Users CC',
|
||||||
|
related='company_id.show_internal_users_cc',
|
||||||
|
readonly=False
|
||||||
|
)
|
|
@ -0,0 +1,10 @@
|
||||||
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class ResUser(models.Model):
|
||||||
|
_inherit = "res.users"
|
||||||
|
|
||||||
|
show_in_cc = fields.Boolean(
|
||||||
|
string='Show in CC',
|
||||||
|
default=True
|
||||||
|
)
|
|
@ -0,0 +1,4 @@
|
||||||
|
To configure this module, you need to:
|
||||||
|
|
||||||
|
#. Go General settings/Discuss/Show Internal Users CC and set if want to show or not internal users in cc details.
|
||||||
|
#. Go Settings/Users & Company salect any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note.
|
|
@ -0,0 +1,2 @@
|
||||||
|
* Valentin Vinagre <valentin.vinagre@sygel.es>
|
||||||
|
* Lorenzo Battistini
|
|
@ -0,0 +1,5 @@
|
||||||
|
This module extends the functionality of mailing to show the document followers in head of the mails.
|
||||||
|
In the cc, only appear when:
|
||||||
|
|
||||||
|
#. The followers only count if are contacts or external users (Inner Followers will be discriminated)
|
||||||
|
#. The number of followers are more than 1.
|
|
@ -0,0 +1,3 @@
|
||||||
|
To use this module, you need to:
|
||||||
|
|
||||||
|
#. Send an email from any document of odoo.
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">res.config.settings.view.form.inherit.mail.show.follower</field>
|
||||||
|
<field name="model">res.config.settings</field>
|
||||||
|
<field name="inherit_id" ref="mail.res_config_settings_view_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<div id="emails" position="inside">
|
||||||
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
|
<div class="o_setting_left_pane">
|
||||||
|
<field name="show_internal_users_cc"/>
|
||||||
|
</div>
|
||||||
|
<div class="o_setting_right_pane">
|
||||||
|
<label for="show_internal_users_cc"/>
|
||||||
|
<div class="text-muted" id="show_internal_users_cc">
|
||||||
|
Add internal users in cc mails details
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_users_form_mail_show_follower" model="ir.ui.view">
|
||||||
|
<field name="name">view.users.form.mail.show.follower</field>
|
||||||
|
<field name="model">res.users</field>
|
||||||
|
<field name="inherit_id" ref="base.view_users_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='signature']" position="before">
|
||||||
|
<field name="show_in_cc"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../mail_show_follower
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
Loading…
Reference in New Issue