diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-05-20 15:10:54 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-07-02 10:39:25 +0000 |
| commit | 566244b47ba32f7d509fcb2ef15dcbed51009a0e (patch) | |
| tree | 588485eef127fecd4b558b8621b1f833a5658461 /addons/mail/wizard | |
| parent | 657adbe482604f822d6628ed30b349a2237faea4 (diff) | |
[REF] mail, sms: perform some guidelining (file move) and rename SMS composer model
Purpose is to prepare future improvements in mail and SMS module. In this
commit we apply some guidelines on XML Ids and file naming.
In mail cancel wizard code is separated from the resend one as they have
nothing in common.
More importantly ``sms.send_sms`` model is renamed to ``sms.composer`` to
avoid underscores (which is really really bad, take a look at
ir.config_parameter) and have a meaningful name.
Related to task 1922163
Linked to PR #34516
Co-Authored-By: Thibault Delavallee <tde@odoo.com>
Co-Authored-By: Pierre Rousseau <pro@odoo.com>
Diffstat (limited to 'addons/mail/wizard')
| -rw-r--r-- | addons/mail/wizard/__init__.py | 1 | ||||
| -rw-r--r-- | addons/mail/wizard/mail_resend_cancel.py | 39 | ||||
| -rw-r--r-- | addons/mail/wizard/mail_resend_cancel_views.xml | 27 | ||||
| -rw-r--r-- | addons/mail/wizard/mail_resend_message.py | 39 | ||||
| -rw-r--r-- | addons/mail/wizard/mail_resend_message_views.xml | 27 |
5 files changed, 70 insertions, 63 deletions
diff --git a/addons/mail/wizard/__init__.py b/addons/mail/wizard/__init__.py index e6ba124f4ae..7e0df4a2d19 100644 --- a/addons/mail/wizard/__init__.py +++ b/addons/mail/wizard/__init__.py @@ -3,6 +3,7 @@ from . import invite from . import mail_compose_message +from . import mail_resend_cancel from . import mail_resend_message from . import email_template_preview from . import base_module_uninstall diff --git a/addons/mail/wizard/mail_resend_cancel.py b/addons/mail/wizard/mail_resend_cancel.py new file mode 100644 index 00000000000..277ed8b96db --- /dev/null +++ b/addons/mail/wizard/mail_resend_cancel.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import _, api, fields, models + + +class MailCancelResend(models.TransientModel): + _name = 'mail.resend.cancel' + _description = 'Dismiss notification for resend by model' + + model = fields.Char(string='Model') + help_message = fields.Char(string='Help message', compute='_compute_help_message') + + @api.multi + @api.depends('model') + def _compute_help_message(self): + for wizard in self: + wizard.help_message = _("Are you sure you want to discard %s mail delivery failures. You won't be able to re-send these mails later!") % (wizard._context.get('unread_counter')) + + @api.multi + def cancel_resend_action(self): + author_id = self.env.user.partner_id.id + for wizard in self: + self._cr.execute(""" + SELECT notif.id, mes.id + FROM mail_message_res_partner_needaction_rel notif + JOIN mail_message mes + ON notif.mail_message_id = mes.id + WHERE notif.email_status IN ('bounce', 'exception') + AND mes.model = %s + AND mes.author_id = %s + """, (wizard.model, author_id)) + res = self._cr.fetchall() + notif_ids = [row[0] for row in res] + messages_ids = list(set([row[1] for row in res])) + if notif_ids: + self.env["mail.notification"].browse(notif_ids).sudo().write({'email_status': 'canceled'}) + self.env["mail.message"].browse(messages_ids)._notify_failure_update() + return {'type': 'ir.actions.act_window_close'} diff --git a/addons/mail/wizard/mail_resend_cancel_views.xml b/addons/mail/wizard/mail_resend_cancel_views.xml new file mode 100644 index 00000000000..c8cc6632c75 --- /dev/null +++ b/addons/mail/wizard/mail_resend_cancel_views.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo><data> + <record id="mail_resend_cancel_view_form" model="ir.ui.view"> + <field name="name">mail.resend.cancel.view.form</field> + <field name="model">mail.resend.cancel</field> + <field name="groups_id" eval="[(4,ref('base.group_user'))]"/> + <field name="arch" type="xml"> + <form string="Cancel notification in failure"> + <field name="model" invisible='1'/> + <field name="help_message"/> + <p>If you want to re-send them, click Cancel now, then click on the notification and review them one by one by clicking on the red envelope next to each message.</p> + <img src="/mail/static/img/red_envelope.png" alt="Envelope Example"/> + <footer> + <button string="Discard delivery failures" name="cancel_resend_action" type="object" class="btn-primary" /> + <button string="Cancel" class="btn-secondary" special="cancel" /> + </footer> + </form> + </field> + </record> + <record id="mail_resend_cancel_action" model="ir.actions.act_window"> + <field name="name">Discard mail delivery failures</field> + <field name="res_model">mail.resend.cancel</field> + <field name="type">ir.actions.act_window</field> + <field name="view_mode">form</field> + <field name="target">new</field> + </record> +</data></odoo> diff --git a/addons/mail/wizard/mail_resend_message.py b/addons/mail/wizard/mail_resend_message.py index bcff9dc9840..e5e4c069df1 100644 --- a/addons/mail/wizard/mail_resend_message.py +++ b/addons/mail/wizard/mail_resend_message.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import _, api, fields, models -from ast import literal_eval +from odoo import api, fields, models from odoo.exceptions import UserError + class MailResendMessage(models.TransientModel): _name = 'mail.resend.message' _description = 'Email resend wizard' @@ -100,38 +100,3 @@ class PartnerResend(models.TransientModel): resend = fields.Boolean(string="Send Again", default=True) resend_wizard_id = fields.Many2one('mail.resend.message', string="Resend wizard") message = fields.Char(string="Help message") - - -class MailCancelResend(models.TransientModel): - _name = 'mail.resend.cancel' - _description = 'Dismiss notification for resend by model' - - model = fields.Char(string='Model') - help_message = fields.Char(string='Help message', compute='_compute_help_message') - - @api.multi - @api.depends('model') - def _compute_help_message(self): - for wizard in self: - wizard.help_message = _("Are you sure you want to discard %s mail delivery failures. You won't be able to re-send these mails later!") % (wizard._context.get('unread_counter')) - - @api.multi - def cancel_resend_action(self): - author_id = self.env.user.partner_id.id - for wizard in self: - self._cr.execute(""" - SELECT notif.id, mes.id - FROM mail_message_res_partner_needaction_rel notif - JOIN mail_message mes - ON notif.mail_message_id = mes.id - WHERE notif.email_status IN ('bounce', 'exception') - AND mes.model = %s - AND mes.author_id = %s - """, (wizard.model, author_id)) - res = self._cr.fetchall() - notif_ids = [row[0] for row in res] - messages_ids = list(set([row[1] for row in res])) - if notif_ids: - self.env["mail.notification"].browse(notif_ids).sudo().write({'email_status': 'canceled'}) - self.env["mail.message"].browse(messages_ids)._notify_failure_update() - return {'type': 'ir.actions.act_window_close'} diff --git a/addons/mail/wizard/mail_resend_message_views.xml b/addons/mail/wizard/mail_resend_message_views.xml index 1ab5ea047f7..118660e232e 100644 --- a/addons/mail/wizard/mail_resend_message_views.xml +++ b/addons/mail/wizard/mail_resend_message_views.xml @@ -2,7 +2,7 @@ <odoo> <data> <record id="mail_resend_message_view_form" model="ir.ui.view"> - <field name="name">mail.resend.message.form</field> + <field name="name">mail.resend.message.view.form</field> <field name="model">mail.resend.message</field> <field name="groups_id" eval="[(4,ref('base.group_user'))]"/> <field name="arch" type="xml"> @@ -31,23 +31,6 @@ </form> </field> </record> - <record id="mail_resend_cancel_view_form" model="ir.ui.view"> - <field name="name">mail.resend.cancel.form</field> - <field name="model">mail.resend.cancel</field> - <field name="groups_id" eval="[(4,ref('base.group_user'))]"/> - <field name="arch" type="xml"> - <form string="Cancel notification in failure"> - <field name="model" invisible='1'/> - <field name="help_message"/> - <p>If you want to re-send them, click Cancel now, then click on the notification and review them one by one by clicking on the red envelope next to each message.</p> - <img src="/mail/static/img/red_envelope.png" alt="Envelope Example"/> - <footer> - <button string="Discard delivery failures" name="cancel_resend_action" type="object" class="btn-primary" /> - <button string="Cancel" class="btn-secondary" special="cancel" /> - </footer> - </form> - </field> - </record> <record id="mail_resend_message_action" model="ir.actions.act_window"> <field name="name">Resend mail</field> <field name="res_model">mail.resend.message</field> @@ -55,13 +38,5 @@ <field name="view_mode">form</field> <field name="target">new</field> </record> - <record id="mail_resend_cancel_action" model="ir.actions.act_window"> - <field name="name">Discard mail delivery failures</field> - <field name="res_model">mail.resend.cancel</field> - <field name="type">ir.actions.act_window</field> - <field name="view_mode">form</field> - <field name="target">new</field> - </record> - </data> </odoo> |
