Browse Source

Merge 2a09c92851 into 975b033a76

pull/356/merge
Giovanni Capalbo (Therp) 5 years ago
committed by GitHub
parent
commit
828e7c6c7d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 81
      mail_edit/README.rst
  2. 6
      mail_edit/__init__.py
  3. 28
      mail_edit/__openerp__.py
  4. 90
      mail_edit/i18n/mail_edit.pot
  5. 99
      mail_edit/i18n/nl.po
  6. 6
      mail_edit/models/__init__.py
  7. 52
      mail_edit/models/compose_message.py
  8. 15
      mail_edit/models/res_request_link.py
  9. 27
      mail_edit/security/mail_edit_security.xml
  10. BIN
      mail_edit/static/description/icon.png
  11. 18
      mail_edit/static/src/css/mail_edit.css
  12. 40
      mail_edit/static/src/js/mail_edit.js
  13. 15
      mail_edit/static/src/xml/mail_edit.xml
  14. 5
      mail_edit/tests/__init__.py
  15. 91
      mail_edit/tests/test_mail_edit.py
  16. 17
      mail_edit/views/assets.xml
  17. 42
      mail_edit/views/compose_message.xml
  18. 29
      mail_edit/views/res_request_link.xml

81
mail_edit/README.rst

@ -0,0 +1,81 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
============
Message Edit
============
This module extends the functionality of mail. You can edit message/messages
and move them to any model.
Configuration
=============
To configure this module:
* Activate the 'Move mail message' or 'Edit mail message' permissions for a
user (the admin user has these rights by default)
* Objects that users are allowed to move messages to, can be
configured in Settings - Technical - Database structure -
Referenceable objects.
Usage
=====
To use this module, you need to:
* Go to *Message* *Chatter* in any model, click the Edit (pen) Icon to open up
the 'Edit or Move' wizard.
* To edit, edit the Mail as necessary and click Save.
* To move, select the destination object and click Save.
Known issues / Roadmap
======================
* Does not reload after edit on messaging views. For this we needed to call
controller.reload(), a way to this would be to inherit the ActionManager and
call it from there.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/ social/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 `here <https://github.com/OCA/
social/issues/new?body=module:%20 mail_edit%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`__.
Credits
=======
Images
------
* PICOL Icon Generator `here <http://picol.org/picol_icon_generator>`__.
Contributors
------------
* Dan Kiplangat <dan@sunflowerweb.nl>
* Tom Blauwendraat <tom@sunflowerweb.nl>
* George Daramouskas <gdaramouskas@therp.nl>
* Holger Brunn <hbrunn@therp.nl>
* Giovanni Francesco Capalbo <giovanni@therp.nl>
* Nikos Tsirintanis <ntsirintanis@therp.nl>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

6
mail_edit/__init__.py

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Sunflower IT (http://sunflowerweb.nl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import tests

28
mail_edit/__openerp__.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# © 2016 Sunflower IT (http://sunflowerweb.nl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Message Edit",
"summary": "Adds an option to edit mail to different partners",
"version": "9.0.1.0.0",
"category": "Social Network",
"website": "https://sunflowerweb.nl",
"author": "Sunflower IT, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"mail",
"web",
],
"data": [
"security/mail_edit_security.xml",
"views/assets.xml",
"views/compose_message.xml",
"views/res_request_link.xml",
],
"qweb": [
"static/src/xml/mail_edit.xml",
],
}

90
mail_edit/i18n/mail_edit.pot

@ -0,0 +1,90 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_edit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: mail_edit
#: help:res.request.link,mail_edit:0
msgid "Allow to move mails to this model."
msgstr ""
#. module: mail_edit
#. openerp-web
#: code:addons/mail_edit/static/src/xml/mail_edit.xml:11
#, python-format
msgid "Delete"
msgstr ""
#. module: mail_edit
#: field:mail.message,destination_object_id:0
msgid "Destination object"
msgstr ""
#. module: mail_edit
#. openerp-web
#: code:addons/mail_edit/static/src/xml/mail_edit.xml:8
#, python-format
msgid "Edit Mail"
msgstr ""
#. module: mail_edit
#: model:ir.actions.act_window,name:mail_edit.mail_edit_action
msgid "Edit or Move Message"
msgstr ""
#. module: mail_edit
#: model:res.groups,name:mail_edit.group_mail_edit_superuser
msgid "Edit or Move anyone's mail messages"
msgstr ""
#. module: mail_edit
#: model:res.groups,name:mail_edit.group_mail_edit_editor
msgid "Edit own mail messages"
msgstr ""
#. module: mail_edit
#: field:res.request.link,mail_edit:0
msgid "Mail move"
msgstr ""
#. module: mail_edit
#: model:res.groups,comment:mail_edit.group_mail_edit_editor
msgid "Members of this group are able to edit mail messages."
msgstr ""
#. module: mail_edit
#: model:res.groups,comment:mail_edit.group_mail_edit_mover
msgid "Members of this group are able to move mails."
msgstr ""
#. module: mail_edit
#: model:res.groups,comment:mail_edit.group_mail_edit_superuser
msgid "Members of this group are able to move or edit mails"
msgstr ""
#. module: mail_edit
#: model:ir.model,name:mail_edit.model_mail_message
#: view:mail.message:mail_edit.mail_edit_form
msgid "Message"
msgstr ""
#. module: mail_edit
#: model:res.groups,name:mail_edit.group_mail_edit_mover
msgid "Move own mail messages"
msgstr ""
#. module: mail_edit
#: help:mail.message,destination_object_id:0
msgid "Object where the message will be moved to"
msgstr ""

99
mail_edit/i18n/nl.po

@ -0,0 +1,99 @@
# Translation of Mail edit module.
# This file contains the translation of the following modules:
# * mail_edit
#
# Translators:
# Tom Blauwendraat <tom@sunflowerweb.nl>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-01-19 14:40+0000\n"
"PO-Revision-Date: 2017-08-18 16:51+0000\n"
"Last-Translator: Erwin van der Ploeg <erwin@odooexperts.nl>\n"
"Language-Team: Dutch (http://www.transifex.com/odoo/odoo-8/language/nl/)\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: mail_edit
#: help:res.request.link,mail_edit:0
msgid "Allow to move mails to this model."
msgstr "Sta toe om berichten naar dit model te verplaatsen."
#. module: mail_edit
#. openerp-web
#: code:addons/mail_edit/static/src/xml/mail_edit.xml:11
#, python-format
msgid "Delete"
msgstr ""
#. module: mail_edit
#: field:mail.message,destination_object_id:0
msgid "Destination object"
msgstr "Doelobject"
#. module: mail_edit
#. openerp-web
#: code:addons/mail_edit/static/src/xml/mail_edit.xml:8
#, python-format
msgid "Edit Mail"
msgstr "Bericht wijzigen"
#. module: mail_edit
#: model:ir.actions.act_window,name:mail_edit.mail_edit_action
msgid "Edit or Move Message"
msgstr "Wijzigen of verplaatsen van bericht"
#. module: mail_edit
#: model:res.groups,name:mail_edit.group_mail_edit_superuser
#, fuzzy
msgid "Edit or Move anyone's mail messages"
msgstr "Wijzigen of verplaatsen van bericht"
#. module: mail_edit
#: model:res.groups,name:mail_edit.group_mail_edit_editor
#, fuzzy
msgid "Edit own mail messages"
msgstr "Berichten wijzigen"
#. module: mail_edit
#: field:res.request.link,mail_edit:0
#, fuzzy
msgid "Mail move"
msgstr "Bericht wijzigen"
#. module: mail_edit
#: model:res.groups,comment:mail_edit.group_mail_edit_editor
msgid "Members of this group are able to edit mail messages."
msgstr "Leden van deze groep mogen de inhoud van berichten wijzigen."
#. module: mail_edit
#: model:res.groups,comment:mail_edit.group_mail_edit_mover
msgid "Members of this group are able to move mails."
msgstr "Leden van deze groep mogen berichten verplaatsen."
#. module: mail_edit
#: model:res.groups,comment:mail_edit.group_mail_edit_superuser
#, fuzzy
msgid "Members of this group are able to move or edit mails"
msgstr "Leden van deze groep mogen berichten verplaatsen."
#. module: mail_edit
#: model:ir.model,name:mail_edit.model_mail_message
#: view:mail.message:mail_edit.mail_edit_form
msgid "Message"
msgstr "Bericht"
#. module: mail_edit
#: model:res.groups,name:mail_edit.group_mail_edit_mover
#, fuzzy
msgid "Move own mail messages"
msgstr "Berichten verplaatsen"
#. module: mail_edit
#: help:mail.message,destination_object_id:0
msgid "Object where the message will be moved to"
msgstr "Object waar het bericht naartoe verplaatst zal worden"

6
mail_edit/models/__init__.py

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Sunflower IT (http://sunflowerweb.nl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import compose_message
from . import res_request_link

52
mail_edit/models/compose_message.py

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# © 2016 Sunflower IT (http://sunflowerweb.nl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, fields, models
class MailMessage(models.Model):
_inherit = "mail.message"
@api.model
def _get_model_selection(self):
"""Get allowed models and their names."""
model_objs = self.env["res.request.link"].search(
[("mail_edit", "=", True)],
order="name")
return [(m.object, m.name) for m in model_objs]
@api.one
@api.onchange("destination_object_id")
def change_destination_object(self):
"""Update some fields for the new message."""
# pylint: disable=api-one-deprecated
if self.destination_object_id:
self.model = self.destination_object_id._name
self.res_id = self.destination_object_id.id
model_name = self.env["ir.model"].search([
("model", "=", self.model)]).name
display_name = self.destination_object_id.display_name
if model_name:
display_name = "%s %s" % (model_name, display_name)
self.record_name = display_name
else:
self.model = self.res_id = self.record_name = False
destination_object_id = fields.Reference(
_get_model_selection,
"Destination object",
help="Object where the message will be moved to")
@api.model
def _message_read_dict_postprocess(self, messages, message_tree):
res = super(MailMessage, self)._message_read_dict_postprocess(
messages, message_tree)
for message_dict in messages:
# Check if current user is a superuser
superuser_group = 'mail_edit.group_mail_edit_superuser'
message_dict.update(
{'is_superuser': self.env.user.has_group(superuser_group)})
return res

15
mail_edit/models/res_request_link.py

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# © 2016 Sunflower IT (http://sunflowerweb.nl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models
class ResRequestLink(models.Model):
_inherit = "res.request.link"
mail_edit = fields.Boolean(
string="Mail move",
default=True,
index=True,
help="Allow to move mails to this model.")

27
mail_edit/security/mail_edit_security.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record model="res.groups" id="group_mail_edit_editor" >
<field name="name">Edit own mail messages</field>
<field name="comment">Members of this group are able to edit mail messages.</field>
<field name="category_id" ref="base.module_category_hidden"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record model="res.groups" id="group_mail_edit_mover">
<field name="name">Move own mail messages</field>
<field name="comment">Members of this group are able to move mails.</field>
<field name="category_id" ref="base.module_category_hidden"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record model="res.groups" id="group_mail_edit_superuser">
<field name="name">Edit or Move anyone's mail messages</field>
<field name="comment">Members of this group are able to move or edit mails</field>
<field name="category_id" ref="base.module_category_hidden"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
</openerp>

BIN
mail_edit/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 2.4 KiB

18
mail_edit/static/src/css/mail_edit.css

@ -0,0 +1,18 @@
.openerp .oe_mail .oe_msg .oe_msg_icons .oe_edit:hover a {
color: #1FC0FF;
text-shadow: 0px 1px #184FC5,
0px -1px #184FC5,
-1px 0px #184FC5,
1px 0px #184FC5,
0px 3px 3px rgba(0, 0, 0, 0.1);
}
.openerp .oe_mail .oe_msg .oe_msg_icons .oe_delete:hover a {
color: #ffa1a1;
text-shadow: 0px 1px #ff0000,
0px -1px #ff0000,
-1px 0px #ff0000,
1px 0px #ff0000,
0px 3px 3px rgba(0,0,0,0.1);
}

40
mail_edit/static/src/js/mail_edit.js

@ -0,0 +1,40 @@
/* © 2014-2017 Sunflower IT <www.sunflowerweb.nl>*/
odoo.define('mail_edit.thread', function(require) {
"use strict";
var thread = require('mail.ChatThread');
thread.include({
init: function(){
this._super.apply(this, arguments);
this.events['click .o_edit'] = function (event) {
var context = {};
// save the widget object in a var.
var self = this;
// Get the action data
var message_id = $(event.currentTarget).data('message-id');
var do_action = this.do_action;
this.rpc("/web/action/load", {
"action_id": "mail_edit.mail_edit_action",
})
.done(function(action) {
action.res_id = message_id;
action.flags = {
action_buttons: true,
};
action.context = context;
do_action(action, {
on_close: function () {
// reload view
var parent = self.getParent().getParent().getParent()
if (typeof parent.model !== "undefined"){
parent.reload();
}
},
});
});
};
},
});
});

15
mail_edit/static/src/xml/mail_edit.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<t t-extend="mail.ChatThread.Message">
<t t-jquery='p.o_mail_info>span>i:first-child' t-operation="after">
<span class="oe_edit">
<t t-if="is_author or is_superuser" >
<i title="Edit Mail" class="fa fa-pencil-square-o o_edit"
t-att-data-message-id="message.id">
</i>
</t>
</span>
</t>
</t>
</template>

5
mail_edit/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# flake8: noqa
from . import test_mail_edit

91
mail_edit/tests/test_mail_edit.py

@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class TestMailEdit(TransactionCase):
def setUp(self, *args, **kwargs):
# make sale.order and res_partner allowed to edit
super(TestMailEdit, self).setUp(*args, **kwargs)
self.rrl_partner = self.env['res.request.link'].create({
'name': 'A partner',
'object': 'res.partner',
'priority': 1,
'mail_edit': True,
})
self.rrl_partner_2 = self.env['res.request.link'].create({
'name': 'Another partner',
'object': 'res.partner',
'priority': 2,
'mail_edit': True,
})
self.sender = self.env['res.partner'].create({
'name': 'Test sender',
'email': 'sender@example.com',
'notify_email': 'always',
})
self.recipient = self.env['res.partner'].create({
'name': 'Test recipient',
'email': 'recipient@example.com',
'notify_email': 'always',
})
self.message = self.env['mail.message'].create({
'subject': 'Message test',
'author_id': self.sender.id,
'email_from': self.sender.email,
'message_type': 'comment',
'model': 'res.partner',
'res_id': self.recipient.id,
'partner_ids': [(4, self.recipient.id)],
'body': '<p>This is not a test message</p>',
})
def test_change_destination_object(self):
objects = self.message._get_model_selection()
self.assertEqual(len(objects), 3)
self.assertFalse(self.message.destination_object_id)
self.assertTrue(
self.message.model and
self.message.res_id and
self.message.record_name
)
# call onchange manually to nullify .model, .res_id, .record_name
self.message.change_destination_object()
self.assertFalse(
self.message.model and
self.message.res_id and
self.message.record_name
)
# create an arbitrary object from base
arbitrary_object = self.env['res.request.link'].create({
'name': 'Colombia',
'object': 'res.country',
'priority': 3,
'mail_edit': True,
})
# recalculate selection to include arbitrary_object
self.message._get_model_selection()
# Set a value to reference field
self.message.destination_object_id = "{},{}".format(
arbitrary_object.object, arbitrary_object.id
)
self.assertTrue(self.message.destination_object_id)
# call onchange manually to get values from reference
self.message.change_destination_object()
self.assertTrue(
self.message.model and
self.message.res_id and
self.message.record_name
)
self.assertEqual(self.message.model, 'res.country')
self.assertEqual(self.message.res_id, arbitrary_object.id)
def test_message_read_dict_postprocess(self):
message = [self.message._message_read_dict()]
all_messages = self.env['mail.message'].search([])
message_tree = dict((m.id, m) for m in all_messages)
# do stuff to the message
self.message._message_read_dict_postprocess(message, message_tree)
message_list = self.message.message_format()
self.assertTrue(message_list[0].get('is_superuser', False))

17
mail_edit/views/assets.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="Mail edit assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet"
href="/mail_edit/static/src/css/mail_edit.css"/>
<script type="text/javascript"
src="/mail_edit/static/src/js/mail_edit.js"/>
</xpath>
</template>
</data>
</openerp>

42
mail_edit/views/compose_message.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="mail_edit_form" model="ir.ui.view">
<field name="name">Edit Email Form</field>
<field name="model">mail.message</field>
<field name="arch" type="xml">
<form string="Message" create="false">
<sheet>
<group>
<group>
<field name="subject" groups="mail_edit.group_mail_edit_editor,mail_edit.group_mail_edit_superuser"/>
<field name="date" readonly="1"/>
<field name="message_type" readonly="1"/>
<field name="subtype_id" readonly="1"/>
</group>
<group>
<field name="destination_object_id" required="1" groups="mail_edit.group_mail_edit_mover,mail_edit.group_mail_edit_superuser"/>
<field name="model" invisible="1"/>
<field name="res_id" invisible="1"/>
<field name="parent_id" readonly="1" />
</group>
</group>
<field name="body" groups="mail_edit.group_mail_edit_editor,mail_edit.group_mail_edit_superuser"/>
</sheet>
</form>
</field>
</record>
<record id="mail_edit_action" model="ir.actions.act_window">
<field name="name">Edit or Move Message</field>
<field name="res_model">mail.message</field>
<field name="type">ir.actions.act_window</field>
<field name="view_id" ref="mail_edit_form"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>

29
mail_edit/views/res_request_link.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="res_request_link_view_form" model="ir.ui.view">
<field name="name">Add option to edit mails</field>
<field name="model">res.request.link</field>
<field name="inherit_id" ref="base.res_request_link-view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='priority']" position="after">
<field name="mail_edit"/>
</xpath>
</field>
</record>
<record id="res_request_link_view_tree" model="ir.ui.view">
<field name="name">Add option to edit mails</field>
<field name="model">res.request.link</field>
<field name="inherit_id" ref="base.res_request_link_tree-view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='object']" position="after">
<field name="mail_edit"/>
</xpath>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save