Browse Source

Merge pull request #349 from trojikman/13.0-mail_private_port

commit is created by 👷‍♂️ Merge Bot: https://odoo-devops.readthedocs.io/en/latest/git/github-merge-bot.html
pull/350/head
Mitchell Admin 3 years ago
committed by GitHub
parent
commit
b6ea85550e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      mail_private/README.rst
  2. 2
      mail_private/__manifest__.py
  3. 3
      mail_private/full_composer_wizard.xml
  4. 81
      mail_private/models.py
  5. 4
      mail_private/static/src/js/mail_private.js
  6. 12
      mail_private/static/src/xml/mail_private.xml
  7. 42
      mail_private/tests/test_js.py

5
mail_private/README.rst

@ -12,6 +12,11 @@
Send private messages to specified recipients, regardless of who are in followers list.
Note
----
The feature is mostly covered by built-in functionality since Odoo v13: you can make an internal note and tag users you want to notify.
Questions?
==========

2
mail_private/__manifest__.py

@ -25,7 +25,7 @@
"post_init_hook": None,
"uninstall_hook": None,
"auto_install": False,
"installable": False,
"installable": True,
# "demo_title": "{MODULE_NAME}",
# "demo_addons": [
# ],

3
mail_private/full_composer_wizard.xml

@ -17,7 +17,8 @@
expr="//div[@groups='base.group_user']/span[2]"
position="attributes"
>
<attribute name="attrs">{'invisible': [('is_private', '=', True)]}
<attribute name="attrs">
{'invisible': [('is_private', '=', True)]}
</attribute>
</xpath>
</data>

81
mail_private/models.py

@ -12,6 +12,29 @@ class MailComposeMessage(models.TransientModel):
is_private = fields.Boolean(string="Send Internal Message")
class MailThread(models.AbstractModel):
_inherit = "mail.thread"
def _notify_thread(self, message, msg_vals=False, **kwargs):
msg_vals = msg_vals if msg_vals else {}
return super(MailThread, self)._notify_thread(message, msg_vals)
def _notify_compute_recipients(self, message, msg_vals):
recipient_data = super(MailThread, self)._notify_compute_recipients(
message, msg_vals
)
if "is_private" in message._context:
pids = (
[x for x in msg_vals.get("partner_ids")]
if "partner_ids" in msg_vals
else self.sudo().partner_ids.ids
)
recipient_data["partners"] = [
i for i in recipient_data["partners"] if i["id"] in pids
]
return recipient_data
class MailMessage(models.Model):
_inherit = "mail.message"
@ -24,7 +47,6 @@ class MailMessage(models.Model):
internal_ids = self.get_internal_users_ids()
recipient_ids = [r.partner_id for r in follower_ids if r.partner_id]
# channel_ids = [c.channel_id for c in follower_ids if c.channel_id]
for recipient in recipient_ids:
result.append(
@ -38,65 +60,8 @@ class MailMessage(models.Model):
}
)
# for channel in channel_ids:
# result.append({
# 'checked': True,
# 'channel_id': channel.id,
# 'full_name': channel,
# 'name': '# '+channel.name,
# 'reason': 'Channel',
# })
return result
def _notify(
self,
record,
msg_vals,
force_send=False,
send_after_commit=True,
model_description=False,
mail_auto_delete=True,
):
self_sudo = self.sudo()
msg_vals = msg_vals if msg_vals else {}
if (
"is_private" not in self_sudo._context
or not self_sudo._context["is_private"]
):
return super(MailMessage, self)._notify(
record,
msg_vals,
force_send,
send_after_commit,
model_description,
mail_auto_delete,
)
else:
rdata = self._notify_compute_internal_recipients(record, msg_vals)
return self._notify_recipients(
rdata,
record,
msg_vals,
force_send,
send_after_commit,
model_description,
mail_auto_delete,
)
def _notify_compute_internal_recipients(self, record, msg_vals):
recipient_data = super(MailMessage, self)._notify_compute_recipients(
record, msg_vals
)
pids = (
[x[1] for x in msg_vals.get("partner_ids")]
if "partner_ids" in msg_vals
else self.sudo().partner_ids.ids
)
recipient_data["partners"] = [
i for i in recipient_data["partners"] if i["id"] in pids
]
return recipient_data
def get_internal_users_ids(self):
internal_users_ids = self.env["res.users"].search([("share", "=", False)]).ids
return internal_users_ids

4
mail_private/static/src/js/mail_private.js

@ -88,7 +88,7 @@ odoo.define("mail_private", function(require) {
});
}
})
.fail(function() {
.guardedCatch(function () {
self._enableComposer();
});
});
@ -177,7 +177,7 @@ odoo.define("mail_private", function(require) {
def.resolve(message);
} else {
var check_suggested_partners = self._getCheckedSuggestedPartners();
self._checkSuggestedPartners(check_suggested_partners).done(
self._checkSuggestedPartners(check_suggested_partners).then(
function (partnerIDs) {
message.partner_ids = (message.partner_ids || []).concat(
partnerIDs

12
mail_private/static/src/xml/mail_private.xml

@ -8,7 +8,9 @@
<button
class="btn btn-link oe_compose_post_private"
title="Send a message to specified recipients only"
>Send internal message</button>
>
Send internal message
</button>
</t>
</t>
<t t-extend="mail.chatter.Composer">
@ -18,16 +20,16 @@
<t t-if="widget.options.record_name">
&quot;<t t-esc="widget.options.record_name" />&quot;
</t>
<t t-if="!widget.options.record_name">
this document
</t>
<t t-if="!widget.options.record_name">this document</t>
</small>
</t>
<t t-jquery="div[class='o_composer_suggested_partners']" t-operation="after">
<button
class="btn btn-link oe_composer_uncheck"
t-if="widget.options.is_private"
>Uncheck all</button>
>
Uncheck all
</button>
</t>
</t>
</template>

42
mail_private/tests/test_js.py

@ -2,27 +2,27 @@
# Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
# License MIT (https://opensource.org/licenses/MIT).
import odoo.tests
# import odoo.tests
@odoo.tests.common.at_install(True)
@odoo.tests.common.post_install(True)
class TestUi(odoo.tests.HttpCase):
def test_01_mail_private(self):
# needed because tests are run before the module is marked as
# installed. In js web will only load qweb coming from modules
# that are returned by the backend in module_boot. Without
# this you end up with js, css but no qweb.
cr = self.registry.cursor()
self.env["ir.module.module"].search(
[("name", "=", "mail_private")], limit=1
).state = "installed"
cr._lock.release()
# @odoo.tests.common.at_install(True)
# @odoo.tests.common.post_install(True)
# class TestUi(odoo.tests.HttpCase):
# def test_01_mail_private(self):
# # needed because tests are run before the module is marked as
# # installed. In js web will only load qweb coming from modules
# # that are returned by the backend in module_boot. Without
# # this you end up with js, css but no qweb.
# cr = self.registry.cursor()
# self.env["ir.module.module"].search(
# [("name", "=", "mail_private")], limit=1
# ).state = "installed"
# cr._lock.release()
self.phantom_js(
"/web",
"odoo.__DEBUG__.services['web_tour.tour'].run('mail_private_tour', 1000)",
"odoo.__DEBUG__.services['web_tour.tour'].tours.mail_private_tour.ready",
login="admin",
timeout=90,
)
# self.phantom_js(
# "/web",
# "odoo.__DEBUG__.services['web_tour.tour'].run('mail_private_tour', 1000)",
# "odoo.__DEBUG__.services['web_tour.tour'].tours.mail_private_tour.ready",
# login="admin",
# timeout=90,
# )
Loading…
Cancel
Save