Browse Source

[ADD] Add mail_reference module

pull/371/head
George Daramouskas 6 years ago
parent
commit
67a91ac89c
No known key found for this signature in database GPG Key ID: 5B4EF742F8CD859C
  1. 4
      mail_reference/__init__.py
  2. 20
      mail_reference/__manifest__.py
  3. 4
      mail_reference/models/__init__.py
  4. 46
      mail_reference/models/mail_reference_mention.py
  5. 6
      mail_reference/readme/CONFIGURE.rst
  6. 8
      mail_reference/readme/CONTRIBUTORS.rst
  7. 9
      mail_reference/readme/CREDITS.rst
  8. 0
      mail_reference/readme/DESCRIPTION.rst
  9. 7
      mail_reference/readme/INSTALL.rst
  10. 5
      mail_reference/readme/ROADMAP.rst
  11. 9
      mail_reference/readme/USAGE.rst
  12. BIN
      mail_reference/static/description/icon.png
  13. 0
      mail_reference/static/src/css/mail_reference.css
  14. 71
      mail_reference/static/src/js/mail_reference.js
  15. 4
      mail_reference/tests/__init__.py
  16. 9
      mail_reference/tests/test_mail_reference.py
  17. 12
      mail_reference/views/assets.xml
  18. 33
      mail_reference/views/mail_reference_mention.xml
  19. 17
      mail_reference/views/menus.xml

4
mail_reference/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models

20
mail_reference/__manifest__.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "mail_reference",
"version": "10.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "",
"summary": "",
"depends": [
'mail',
],
"data": [
'views/mail_reference_mention.xml',
'views/menus.xml',
'views/assets.xml',
],
"application": False,
}

4
mail_reference/models/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import mail_reference_mention

46
mail_reference/models/mail_reference_mention.py

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class MailReferenceMention(models.Model):
_name = 'mail.reference.mention'
name = fields.Char()
delimiter = fields.Char(
help='The string that when input on the chatter '
'will signify a reference.')
@api.model
def _default_model_ids(self):
return [(6, 0, self._get_mail_thread_inheritants())]
def _domain_model_ids(self):
""" We are only interested in the models that actually have a chatter
along with a name field for us to search for.
"""
model_names = [x for x in self.env[
'mail.thread'].pool.descendants(
['mail.thread'],
'_inherit')]
model_ids = self.env['ir.model'].search([
('model', 'in', model_names),
('field_id.name', 'in', ['name', 'x_name'])]).ids
return [('id', 'in', model_ids)]
model_ids = fields.Many2many(
'ir.model',
default=_default_model_ids,
string='Models',
domain=_domain_model_ids,
help='The models that this delimiter will appear on',
)
@api.depends('model_ids')
def _compute_model_names(self):
for rec in self:
rec.model_names = ','.join(rec.model_ids.mapped('model'))
model_names = fields.Char(compute='_compute_model_names', store=True)

6
mail_reference/readme/CONFIGURE.rst

@ -0,0 +1,6 @@
Configuration
=============
To configure this module, you need to:
#. go to ...

8
mail_reference/readme/CONTRIBUTORS.rst

@ -0,0 +1,8 @@
Contributors
------------
* George Daramouskas <gdaramouskas@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.

9
mail_reference/readme/CREDITS.rst

@ -0,0 +1,9 @@
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

0
mail_reference/readme/DESCRIPTION.rst

7
mail_reference/readme/INSTALL.rst

@ -0,0 +1,7 @@
Installation
============
To install this module, you need to:
#. do this ...

5
mail_reference/readme/ROADMAP.rst

@ -0,0 +1,5 @@
Known issues / Roadmap
======================
* ...

9
mail_reference/readme/USAGE.rst

@ -0,0 +1,9 @@
Usage
=====
To use this module, you need to:
#. go to ...
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/10.0

BIN
mail_reference/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

0
mail_reference/static/src/css/mail_reference.css

71
mail_reference/static/src/js/mail_reference.js

@ -0,0 +1,71 @@
//Copyright 2019 Therp BV <https://therp.nl>
//License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
odoo.define('mail_reference.basic_composer', function(require) {
var BasicComposer = require('mail.composer').BasicComposer;
var data = require('web.data');
var Model = require('web.Model');
var ajax = require('web.ajax');
BasicComposer.include({
init: function (parent, options) {
this._super.apply(this, arguments);
this.register_custom_mentions();
},
/**
* Called when the user enters a character after the delimitor and for
* every delimitor.
*
* Performs a search_read on the model defined on `this.model` and
* searches for the records based on their `name` field.
*
* */
mention_execute_action: function (mention_word) {
domain = [
['name', 'ilike', mention_word],
]
fields = ['id', 'name']
return this.mention_fetch_throttled(
new Model(this.context.default_model),
'search_read',
{domain: domain, fields: fields, limit: 8}).then(
function (result) {
return result
})
},
/**
* Called when the user clicks `New message` or `Log an internal note`
* and it's purpose is to see which delimiters are supported for this
* model and at which model do they point to.
*
* */
register_custom_mentions: function () {
var self = this;
var query = new data.Query(
new Model(
'mail.reference.mention',
{},
[['model_names', 'like', this.context.default_model]]),
['delimiter'],
);
query.all().then(function (res){
res.forEach(function (mention) {
self.mention_manager.register({
delimiter: mention.delimiter,
generate_links: true,
model: self.context.default_model,
fetch_callback:
self.mention_execute_action.bind(
self),
suggestion_template:
'mail.MentionChannelSuggestions',
});
});
});
}
});
});

4
mail_reference/tests/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_mail_reference

9
mail_reference/tests/test_mail_reference.py

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class TestMailReference(TransactionCase):
def test_mail_reference(self):
pass

12
mail_reference/views/assets.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr=".">
<script
type="text/javascript"
src="/mail_reference/static/src/js/mail_reference.js"/>
</xpath>
</template>
</odoo>

33
mail_reference/views/mail_reference_mention.xml

@ -0,0 +1,33 @@
<odoo>
<record id="mail_reference_mention_form" model="ir.ui.view">
<field name="name">Mail Reference Mention Form</field>
<field name="model">mail.reference.mention</field>
<field name="arch" type="xml">
<form string="Mentions">
<group>
<field name="name" required="1"/>
<field name="delimiter" required="1"/>
<field name="model_ids" string="Models" required="1"/>
</group>
</form>
</field>
</record>
<record id="mail_reference_mention_tree" model="ir.ui.view">
<field name="name">Mail Reference Mention Tree</field>
<field name="model">mail.reference.mention</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="delimiter"/>
<field name="model_ids">
<field name="name"/>
<field name="model"/>
</field>
</tree>
</field>
</record>
</odoo>

17
mail_reference/views/menus.xml

@ -0,0 +1,17 @@
<odoo>
<record id="action_view_mail_reference_mentions" model="ir.actions.act_window">
<field name="name">Mail References</field>
<field name="res_model">mail.reference.mention</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem
name="Mail Reference Mentions"
id="menu_mail_reference_mentions"
parent="base.menu_email"
sequence="99"
action="action_view_mail_reference_mentions"/>
</odoo>
Loading…
Cancel
Save