diff --git a/mail_ux/README.rst b/mail_ux/README.rst new file mode 100644 index 00000000..fbad4bad --- /dev/null +++ b/mail_ux/README.rst @@ -0,0 +1,65 @@ +.. |company| replace:: ADHOC SA + +.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png + :alt: ADHOC SA + :target: https://www.adhoc.com.ar + +.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png + +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +======= +Mail UX +======= + +Several Improvements: + * Only internal user can be mentioned in notes + * Always send email with delay + + +Installation +============ + +Only install the module. + +Configuration +============= + +There is nothing to configure. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: http://runbot.adhoc.com.ar/ + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* |company| |icon| + +Contributors +------------ + +Maintainer +---------- + +|company_logo| + +This module is maintained by the |company|. + +To contribute to this module, please visit https://www.adhoc.com.ar. diff --git a/mail_ux/__init__.py b/mail_ux/__init__.py new file mode 100644 index 00000000..d0337769 --- /dev/null +++ b/mail_ux/__init__.py @@ -0,0 +1,5 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import models diff --git a/mail_ux/__manifest__.py b/mail_ux/__manifest__.py new file mode 100644 index 00000000..d3dd0b40 --- /dev/null +++ b/mail_ux/__manifest__.py @@ -0,0 +1,48 @@ +############################################################################## +# +# Copyright (C) 2019 ADHOC SA (http://www.adhoc.com.ar) +# All Rights Reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Mail UX', + 'version': "18.0.1.0.0", + 'category': 'Base', + 'sequence': 14, + 'summary': '', + 'author': 'ADHOC SA', + 'website': 'www.adhoc.com.ar', + 'license': 'AGPL-3', + 'images': [ + ], + 'assets': { + 'web.assets_backend': [ + 'mail_ux/static/src/core/common/**/*', + ], + }, + 'depends': [ + 'mail', + ], + 'data': [ + ], + 'demo': [ + ], + 'test': [ + ], + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/mail_ux/models/__init__.py b/mail_ux/models/__init__.py new file mode 100644 index 00000000..2f743725 --- /dev/null +++ b/mail_ux/models/__init__.py @@ -0,0 +1,6 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import res_partner +from . import mail_compose_message diff --git a/mail_ux/models/mail_compose_message.py b/mail_ux/models/mail_compose_message.py new file mode 100644 index 00000000..5e7f9ee9 --- /dev/null +++ b/mail_ux/models/mail_compose_message.py @@ -0,0 +1,30 @@ +from odoo import models, fields, api +from datetime import datetime, timedelta +from odoo.exceptions import UserError + +class MailComposeMessage(models.TransientModel): + _inherit = 'mail.compose.message' + + def _action_send_mail(self, auto_commit=False): + """ + Heredado para incluir un retraso de 30 segundos al enviar mensajes. + """ + scheduled_date = datetime.now() + timedelta(seconds=30) + result_mails_su, result_messages = super(MailComposeMessage, self)._action_send_mail(auto_commit=auto_commit) + if self.composition_mode != 'mass_mail': + for wizard in self: + res_ids = wizard._evaluate_res_ids() + for res_id in res_ids: + self.env['mail.scheduled.message'].create({ + 'attachment_ids': [(6, 0, wizard.attachment_ids.ids)], + 'author_id': self.env.user.partner_id.id, + 'body': wizard.body, + 'model': wizard.model, + 'res_id': res_id, + 'partner_ids': [(6, 0, wizard.partner_ids.ids)], + 'scheduled_date': scheduled_date, + 'subject': wizard.subject, + 'notification_parameters': '{}', + }) + + return result_mails_su, result_messages diff --git a/mail_ux/models/res_partner.py b/mail_ux/models/res_partner.py new file mode 100644 index 00000000..eda60a0d --- /dev/null +++ b/mail_ux/models/res_partner.py @@ -0,0 +1,27 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo import models, fields, api +from odoo.addons.mail.tools.discuss import Store +from odoo.osv import expression + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + active = fields.Boolean(tracking=True) + + @api.model + def get_mention_suggestions(self, search, limit=8): + """ + Incluye solo usuarios internos al momento de mencionar usuarios en notas. + """ + internal_group = self.env.ref('base.group_user') + internal_users = self.env['res.users'].search([ + ('groups_id', 'in', internal_group.id), + ]).mapped('partner_id.id') + domain = self._get_mention_suggestions_domain(search) + domain = expression.AND([domain, [('id', 'in', internal_users)]]) + partners = self._search_mention_suggestions(domain, limit) + return Store(partners).get_result() diff --git a/mail_ux/static/src/core/common/composer.js b/mail_ux/static/src/core/common/composer.js new file mode 100644 index 00000000..d9d23795 --- /dev/null +++ b/mail_ux/static/src/core/common/composer.js @@ -0,0 +1,59 @@ +import { Composer } from "@mail/core/common/composer"; +import { patch } from "@web/core/utils/patch"; +import { useService } from "@web/core/utils/hooks"; +import { user } from "@web/core/user"; + +import { + toRaw, +} from "@odoo/owl"; + +patch(Composer.prototype, { + + setup() { + super.setup(); + this.actionService = useService("action"); + this.orm = useService("orm"); + }, + async sendScheduleMessage() { + const composer = toRaw(this.props.composer); + if (composer.message) { + this.editMessage(); + return; + } + await this.processMessage(async (value) => { + await this._sendScheduleMessage(value, this.postData, this.extraData); + }); + }, + async _sendScheduleMessage(value, postData, extraData) { + if (postData.isNote){ + return await this._sendMessage(value, postData, extraData); + } + + const thread = toRaw(this.props.composer.thread); + const postThread = toRaw(this.thread); + if (postThread.model === "discuss.channel") { + // feature of (optimistic) temp message + return await this._sendMessage(value, postData, extraData); + } else { + postData.attachments = postData.attachments ? [...postData.attachments] : []; // to not lose them on composer clear + const { attachments, parentId, mentionedChannels, mentionedPartners } = postData; + const body = value; + const params = await this.store.getMessagePostParams({ body, postData, thread: thread }); + const scheduledDate = new Date(); + scheduledDate.setSeconds(scheduledDate.getSeconds() + 30); + + const formattedScheduledDate = scheduledDate.toISOString().slice(0, 19).replace("T", " "); + await this.orm.call("mail.scheduled.message", 'create', [ + { + 'attachment_ids': attachments.map(attachment => attachment.id), + 'author_id': user.partnerId, + 'body': body, + 'model': postThread.model, + 'res_id': postThread.id, + 'partner_ids': params.post_data.partner_ids || [], + 'scheduled_date': formattedScheduledDate, + 'notification_parameters': '{}', + }]) + } + } +}) diff --git a/mail_ux/static/src/core/common/composer.xml b/mail_ux/static/src/core/common/composer.xml new file mode 100644 index 00000000..eaab8790 --- /dev/null +++ b/mail_ux/static/src/core/common/composer.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/mail_ux/views/ir_actions_act_window_view.xml b/mail_ux/views/ir_actions_act_window_view.xml new file mode 100644 index 00000000..8938011e --- /dev/null +++ b/mail_ux/views/ir_actions_act_window_view.xml @@ -0,0 +1,25 @@ + + + + + ir.actions.act_window.form + ir.actions.act_window + + + + + + +
+
+
+
+
+ +