Skip to content

Commit

Permalink
[ADD] mail_ux: new module with new features
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasperalta1 committed Jan 23, 2025
1 parent 4751a1d commit 8163c5f
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 0 deletions.
65 changes: 65 additions & 0 deletions mail_ux/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/ingadhoc/miscellaneous/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.
5 changes: 5 additions & 0 deletions mail_ux/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import models
48 changes: 48 additions & 0 deletions mail_ux/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}
6 changes: 6 additions & 0 deletions mail_ux/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions mail_ux/models/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions mail_ux/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -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()
59 changes: 59 additions & 0 deletions mail_ux/static/src/core/common/composer.js
Original file line number Diff line number Diff line change
@@ -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': '{}',
}])
}
}
})
27 changes: 27 additions & 0 deletions mail_ux/static/src/core/common/composer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="mail.Composer.scheduleButton">
<button class="o-mail-Composer-send btn"
t-att-class="{
'btn-primary btn-sm': extended,
'btn-link p-1 rounded-pill': !extended,
'me-2': env.inDiscussApp,
'border-start-0': env.inDiscussApp and !props.composer.message,
'border-0': props.composer.message,
}"
t-on-click="sendScheduleMessage"
t-att-disabled="isSendButtonDisabled"
t-att-aria-label="SEND_TEXT"
>
<t t-if="thread and thread.model !== 'discuss.channel'" t-out="SEND_TEXT"/>
<t t-else=""><i class="fa fa-fw fa-paper-plane-o"/></t>
</button>
</t>


<t t-inherit="mail.Composer.sendButton" t-inherit-mode="extension">
<button position='attributes'>
<attribute name="t-on-click">sendScheduleMessage</attribute>
</button>
</t>
</templates>
25 changes: 25 additions & 0 deletions mail_ux/views/ir_actions_act_window_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_window_action_form" model="ir.ui.view">
<field name="name">ir.actions.act_window.form</field>
<field name="model">ir.actions.act_window</field>
<field name="inherit_id" ref="base.view_window_action_form"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="binding_model_id" invisible="1"/>
</field>
<group position="before">
<div class="d-flex align-item-end justify-content-end mt8">
<button name="create_action" string="Add in the 'Action' menu" type="object"
invisible="not res_model or binding_model_id"
help="Display an option on related documents to open this action"/>
<button name="unlink_action" string="Remove from the 'Action' menu" type="object"
invisible="not binding_model_id"
help="Remove the contextual action related this action"/>
</div>
</group>
</field>
</record>

</odoo>

0 comments on commit 8163c5f

Please sign in to comment.