Skip to content

Commit

Permalink
[IMP] Make messages website published only when sent to customers
Browse files Browse the repository at this point in the history
  • Loading branch information
valentincastravete committed Jul 3, 2024
1 parent 5e71181 commit 06443df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mail_private_no_published/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
'name': 'Mail Private No Published',
'summary': 'All messages from the private channel will not be published.',
'author': 'Oscar Soto, SDi Soluciones Informáticas',
'author': 'Oscar Soto, Valentín Georgian Castravete, Sidoo',
'website': 'https://www.sdi.es/odoo-cloud/',
'license': 'AGPL-3',
'category': 'Portal',
Expand Down
16 changes: 13 additions & 3 deletions mail_private_no_published/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###############################################################################
# For copyright and license notices, see __manifest__.py file in root directory
###############################################################################
from odoo import api, models
from odoo import api, models, SUPERUSER_ID

Check failure on line 4 in mail_private_no_published/models/mail_message.py

View workflow job for this annotation

GitHub Actions / flake8_py3

mail_private_no_published/models/mail_message.py#L4

[F401]


class MailMessage(models.Model):
Expand Down Expand Up @@ -38,6 +38,16 @@ def _check_archive(self):
def create(self, vals):
res = super().create(vals)
for rec in res:
if rec.subtype_id == self.env.ref('mail.mt_note'):
rec.website_published = False
if rec.subtype_id != self.env.ref('mail.mt_note'):
continue

partner_ids = rec.partner_ids.ids
user_ids = self.env['res.users'].search([
('partner_id', 'in', partner_ids),
('active', 'in', [True, False]),
])
customer_users = user_ids.filtered(lambda user: user.has_group('base.group_portal'))
if customer_users or (partner_ids and not user_ids):
continue
rec.website_published = False
return res

0 comments on commit 06443df

Please sign in to comment.