From 0fb391c4b5e371376432b3ff62e36320982f9106 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Tue, 3 Feb 2015 13:41:41 +0200 Subject: [PATCH] [IMP] upload mail_move_message --- __init__.py | 1 + __openerp__.py | 20 ++++++ mail_move_message_models.py | 74 +++++++++++++++++++++++ mail_move_message_views.xml | 37 ++++++++++++ static/src/css/mail_move_message.css | 0 static/src/js/mail_move_message.js | 29 +++++++++ static/src/xml/mail_move_message_main.xml | 8 +++ 7 files changed, 169 insertions(+) create mode 100644 __init__.py create mode 100644 __openerp__.py create mode 100644 mail_move_message_models.py create mode 100644 mail_move_message_views.xml create mode 100644 static/src/css/mail_move_message.css create mode 100644 static/src/js/mail_move_message.js create mode 100644 static/src/xml/mail_move_message_main.xml diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..6cd8310 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +import mail_move_message_models diff --git a/__openerp__.py b/__openerp__.py new file mode 100644 index 0000000..37b943d --- /dev/null +++ b/__openerp__.py @@ -0,0 +1,20 @@ +{ + 'name' : 'Move message to thread', + 'version' : '1.0.0', + 'author' : 'Ivan Yelizariev', + 'category' : 'Custom', + 'website' : 'https://it-projects.info', + 'description': """ +Module allows move message to any thread. For example, customer send message to salesperson's alias. Then salesperson is able to move such private message to lead thread. + +Tested on Odoo 8.0 ab7b5d7732a7c222a0aea45bd173742acd47242d + """, + 'depends' : ['mail'], + 'data':[ + 'mail_move_message_views.xml', + ], + 'qweb': [ + 'static/src/xml/*.xml', + ], + 'installable': True +} diff --git a/mail_move_message_models.py b/mail_move_message_models.py new file mode 100644 index 0000000..240bbff --- /dev/null +++ b/mail_move_message_models.py @@ -0,0 +1,74 @@ +from openerp import api, models, fields, SUPERUSER_ID +from openerp.tools.translate import _ + +class wizard(models.TransientModel): + _name = 'mail_move_message.wizard' + + message_id = fields.Many2one('mail.message', string='Message') + message_body = fields.Html(related='message_id.body', string='Message to move', readonly=True) + parent_id = fields.Many2one('mail.message', string='Search by name') + model_id = fields.Many2one('ir.model', string='Record type') + res_id = fields.Integer('Record ID') + record_url = fields.Char('Link to record', readonly=True) + + @api.onchange('parent_id') + def on_change_parent_id(self): + if self.parent_id and self.parent_id.model: + self.model_id = self.env['ir.model'].search([('model', '=', self.parent_id.model)])[0] + self.res_id = self.parent_id.res_id + else: + self.model_id = None + self.res_id = None + + @api.onchange('model_id', 'res_id') + def on_change_res(self): + if not ( self.model_id and self.res_id ): + self.record_url = '' + return + + self.record_url = '/web#id=%s&model=%s' % (self.res_id, self.model_id.model) + + @api.multi + def move(self): + for r in self: + if r.parent_id: + if not (r.parent_id.model == r.model_id.model and + r.parent_id.res_id == r.res_id): + r.parent_id = None + + r.message_id.write({'parent_id': r.parent_id.id, 'res_id': r.res_id, 'model': r.model_id.model}) + if not ( r.model_id and r.res_id ): + obj = self.pool.get('ir.model.data').get_object_reference(self._cr, SUPERUSER_ID, 'mail', 'mail_archivesfeeds')[1] + return { + 'type' : 'ir.actions.client', + 'name' : 'Archive', + 'tag' : 'reload', + 'params' : {'menu_id': obj}, + } + return { + 'name': _('Record'), + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': r.model_id.model, + 'res_id': r.res_id, + 'views': [(False, 'form')], + 'type': 'ir.actions.act_window', + } + +class mail_message(models.Model): + _inherit = 'mail.message' + + def name_get(self, cr, uid, ids, context=None): + if not (context or {}).get('extended_name'): + return super(mail_message, self).name_get(cr, uid, ids, context=context) + if isinstance(ids, (list, tuple)) and not len(ids): + return [] + if isinstance(ids, (long, int)): + ids = [ids] + reads = self.read(cr, uid, ids, ['record_name','model', 'res_id'], context=context) + res = [] + for record in reads: + name = record['record_name'] + extended_name = ' [%s] ID %s' % (record.get('model', 'UNDEF'), record.get('res_id', 'UNDEF')) + res.append((record['id'], name + extended_name)) + return res diff --git a/mail_move_message_views.xml b/mail_move_message_views.xml new file mode 100644 index 0000000..bf2b782 --- /dev/null +++ b/mail_move_message_views.xml @@ -0,0 +1,37 @@ + + + + + + + mail_move_message.wizard.view + mail_move_message.wizard + +
+ + + + + + + +
+ +
+
+
+ +
+
+ +
+
+ diff --git a/static/src/css/mail_move_message.css b/static/src/css/mail_move_message.css new file mode 100644 index 0000000..e69de29 diff --git a/static/src/js/mail_move_message.js b/static/src/js/mail_move_message.js new file mode 100644 index 0000000..c44de1c --- /dev/null +++ b/static/src/js/mail_move_message.js @@ -0,0 +1,29 @@ +openerp.mail_move_message = function (session) { + var _t = session.web._t, + _lt = session.web._lt; + + var mail = session.mail; + + mail.ThreadMessage.include({ + bind_events: function(){ + this._super.apply(this, arguments); + this.$('.oe_move').on('click', this.on_move_message) + }, + on_move_message: function(event){ + var context = { + 'default_message_id': this.id + } + var action = { + type: 'ir.actions.act_window', + res_model: 'mail_move_message.wizard', + view_mode: 'form', + view_type: 'form', + views: [[false, 'form']], + target: 'new', + context: context, + }; + + this.do_action(action); + } + }) +} \ No newline at end of file diff --git a/static/src/xml/mail_move_message_main.xml b/static/src/xml/mail_move_message_main.xml new file mode 100644 index 0000000..4e15559 --- /dev/null +++ b/static/src/xml/mail_move_message_main.xml @@ -0,0 +1,8 @@ + +