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 authored and maq-adhoc committed Feb 12, 2025
1 parent 4751a1d commit 6f74986
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 0 deletions.
63 changes: 63 additions & 0 deletions mail_ux/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. |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
=======

* 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
49 changes: 49 additions & 0 deletions mail_ux/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
##############################################################################
#
# 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': [
'views/res_users_views.xml',
],
'demo': [
],
'test': [
],
'installable': True,
'auto_install': False,
'application': False,
}
7 changes: 7 additions & 0 deletions mail_ux/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import mail_compose_message
from . import res_users
from . import ir_http
13 changes: 13 additions & 0 deletions mail_ux/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models


class IrHttp(models.AbstractModel):
_inherit = 'ir.http'

def session_info(self):
res = super().session_info()
res['send_message_delay'] = self.env.user.send_message_delay
return res
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=self.env.user.send_message_delay)
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
7 changes: 7 additions & 0 deletions mail_ux/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import models, fields


class ResUsers(models.Model):
_inherit = 'res.users'

send_message_delay = fields.Integer()
61 changes: 61 additions & 0 deletions mail_ux/static/src/core/common/composer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 { session } from "@web/session";

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 (!session.send_message_delay){
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() + session.send_message_delay);

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,
'is_note': postData.isNote,
'partner_ids': params.post_data.partner_ids || [],
'scheduled_date': formattedScheduledDate,
'notification_parameters': JSON.stringify(params.post_data),
}])
}
}
})
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>
23 changes: 23 additions & 0 deletions mail_ux/views/res_users_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<odoo>
<record id="view_users_form_simple_modif" model="ir.ui.view">
<field name="name">res.users.preferences.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="mail.view_users_form_simple_modif_mail"/>
<field name="arch" type="xml">
<field name="notification_type" position="after">
<field name="send_message_delay"/>
</field>
</field>
</record>

<record id="view_users_form_mail" model="ir.ui.view">
<field name="name">res.users.form.mail</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="mail.view_users_form_mail"/>
<field name="arch" type="xml">
<field name="notification_type" position="after">
<field name="send_message_delay"/>
</field>
</field>
</record>
</odoo>

0 comments on commit 6f74986

Please sign in to comment.