[IMP] mail_show_follower: black, isort, prettier

This commit is contained in:
Eduardo De Miguel 2022-03-11 12:11:21 +01:00
parent ee07cb3d1b
commit f75e5ef3bc
9 changed files with 67 additions and 57 deletions

View File

@ -11,12 +11,6 @@
"license": "AGPL-3", "license": "AGPL-3",
"application": False, "application": False,
"installable": True, "installable": True,
"depends": [ "depends": ["base", "mail"],
"base", "data": ["views/res_config_settings.xml", "views/res_users.xml"],
"mail"
],
"data": [
"views/res_config_settings.xml",
"views/res_users.xml"
],
} }

View File

@ -1,4 +1,4 @@
from odoo import models, api from odoo import api, models
class MailMail(models.Model): class MailMail(models.Model):
@ -9,10 +9,10 @@ class MailMail(models.Model):
plain_text = ( plain_text = (
'<div summary="o_mail_notification" style="padding: 0px; ' '<div summary="o_mail_notification" style="padding: 0px; '
'font-size: 10px;"><b>CC</b>: %s<hr style="background-color:' 'font-size: 10px;"><b>CC</b>: %s<hr style="background-color:'
'rgb(204,204,204);border:medium none;clear:both;display:block;' "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>' 'font-size:0px;min-height:1px;line-height:0; margin:4px 0 12px 0;"></div>'
) )
group_portal = self.env.ref('base.group_portal') group_portal = self.env.ref("base.group_portal")
for mail_id in self.ids: for mail_id in self.ids:
mail = self.browse(mail_id) mail = self.browse(mail_id)
# if the email has a model, id and it belongs to the portal group # if the email has a model, id and it belongs to the portal group
@ -22,19 +22,29 @@ class MailMail(models.Model):
# if they do it must be a portal, we exclude internal # if they do it must be a portal, we exclude internal
# users of the system. # users of the system.
if hasattr(obj, "message_follower_ids"): if hasattr(obj, "message_follower_ids"):
partners_obj = obj.message_follower_ids.mapped('partner_id') partners_obj = obj.message_follower_ids.mapped("partner_id")
# internal partners # internal partners
user_partner_ids = self.env['res.users'].search([ user_partner_ids = (
('active', 'in', (True, False)), self.env["res.users"]
('show_in_cc', '=', False), .search(
]).filtered( [
lambda x: group_portal not in x.groups_id ("active", "in", (True, False)),
).mapped('partner_id').ids ("show_in_cc", "=", False),
partners_len = len(partners_obj.filtered( ]
lambda x: x.id not in user_partner_ids and ( )
not x.user_ids or .filtered(lambda x: group_portal not in x.groups_id)
group_portal in x.user_ids.mapped("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.mapped("groups_id")
)
)
)
if partners_len > 1: if partners_len > 1:
# get partners # get partners
cc_internal = True cc_internal = True
@ -43,28 +53,28 @@ class MailMail(models.Model):
cc_internal = obj.company_id.show_internal_users_cc cc_internal = obj.company_id.show_internal_users_cc
# get company in user # get company in user
elif mail.env and mail.env.user and mail.env.user.company_id: elif mail.env and mail.env.user and mail.env.user.company_id:
cc_internal = self.env.user.company_id.\ cc_internal = (
show_internal_users_cc self.env.user.company_id.show_internal_users_cc
)
if cc_internal: if cc_internal:
partners = partners_obj.filtered( partners = partners_obj.filtered(
lambda x: x.id not in user_partner_ids and ( lambda x: x.id not in user_partner_ids
not x.user_ids or x.user_ids.show_in_cc and (not x.user_ids or x.user_ids.show_in_cc)
)
) )
else: else:
partners = partners_obj.filtered( partners = partners_obj.filtered(
lambda x: x.id not in user_partner_ids and ( lambda x: x.id not in user_partner_ids
not x.user_ids or group_portal in and (
x.user_ids.mapped("groups_id") not x.user_ids
or group_portal in x.user_ids.mapped("groups_id")
) )
) )
partners = partners.filtered( partners = partners.filtered(
lambda x: lambda x: not x.user_ids
not x.user_ids
or or
# otherwise, email is not sent # otherwise, email is not sent
x.user_ids and "email" in x.user_ids.mapped( x.user_ids
"notification_type") and "email" in x.user_ids.mapped("notification_type")
) )
# get names and emails # get names and emails
final_cc = None final_cc = None
@ -77,6 +87,7 @@ class MailMail(models.Model):
# not appear in the odoo log # not appear in the odoo log
mail.body_html = final_cc + mail.body_html mail.body_html = final_cc + mail.body_html
return super(MailMail, self)._send( return super(MailMail, self)._send(
auto_commit=auto_commit, raise_exception=raise_exception, auto_commit=auto_commit,
smtp_session=smtp_session raise_exception=raise_exception,
smtp_session=smtp_session,
) )

View File

@ -1,10 +1,9 @@
from odoo import models, fields from odoo import fields, models
class ResCompany(models.Model): class ResCompany(models.Model):
_inherit = "res.company" _inherit = "res.company"
show_internal_users_cc = fields.Boolean( show_internal_users_cc = fields.Boolean(
string='Show Internal Users CC', string="Show Internal Users CC", default=True
default=True
) )

View File

@ -2,10 +2,10 @@ from odoo import fields, models
class ResConfigSettings(models.TransientModel): class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings' _inherit = "res.config.settings"
show_internal_users_cc = fields.Boolean( show_internal_users_cc = fields.Boolean(
string='Show Internal Users CC', string="Show Internal Users CC",
related='company_id.show_internal_users_cc', related="company_id.show_internal_users_cc",
readonly=False readonly=False,
) )

View File

@ -1,10 +1,7 @@
from odoo import models, fields from odoo import fields, models
class ResUser(models.Model): class ResUser(models.Model):
_inherit = "res.users" _inherit = "res.users"
show_in_cc = fields.Boolean( show_in_cc = fields.Boolean(string="Show in CC", default=True)
string='Show in CC',
default=True
)

View File

@ -1,17 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="res_config_settings_view_form" model="ir.ui.view"> <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="name"
>res.config.settings.view.form.inherit.mail.show.follower</field>
<field name="model">res.config.settings</field> <field name="model">res.config.settings</field>
<field name="inherit_id" ref="mail.res_config_settings_view_form"/> <field name="inherit_id" ref="mail.res_config_settings_view_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<div id="emails" position="inside"> <div id="emails" position="inside">
<div class="col-12 col-lg-6 o_setting_box"> <div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane"> <div class="o_setting_left_pane">
<field name="show_internal_users_cc"/> <field name="show_internal_users_cc" />
</div> </div>
<div class="o_setting_right_pane"> <div class="o_setting_right_pane">
<label for="show_internal_users_cc"/> <label for="show_internal_users_cc" />
<div class="text-muted" id="show_internal_users_cc"> <div class="text-muted" id="show_internal_users_cc">
Add internal users in cc mails details Add internal users in cc mails details
</div> </div>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="view_users_form_mail_show_follower" model="ir.ui.view"> <record id="view_users_form_mail_show_follower" model="ir.ui.view">
<field name="name">view.users.form.mail.show.follower</field> <field name="name">view.users.form.mail.show.follower</field>
<field name="model">res.users</field> <field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/> <field name="inherit_id" ref="base.view_users_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='signature']" position="before"> <xpath expr="//field[@name='signature']" position="before">
<field name="show_in_cc"/> <field name="show_in_cc" />
</xpath> </xpath>
</field> </field>
</record> </record>

View File

@ -0,0 +1 @@
../../../../mail_show_follower

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)