From db946c187264802ff76e69b7bc3966a6c032e872 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Mon, 3 Oct 2016 16:39:48 +0500 Subject: [PATCH 1/2] [PORT] update mail_move_message for 10.0 --- mail_move_message/controllers/main.py | 16 ++++----- mail_move_message/mail_move_message_models.py | 35 +++++++------------ mail_move_message/mail_move_message_views.xml | 14 ++++---- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/mail_move_message/controllers/main.py b/mail_move_message/controllers/main.py index 94a6634..166f914 100644 --- a/mail_move_message/controllers/main.py +++ b/mail_move_message/controllers/main.py @@ -13,19 +13,16 @@ class MailChatController(openerp.addons.bus.controllers.main.BusController): def _poll(self, dbname, channels, last, options): if request.session.uid: - registry, cr, uid, context = request.registry, request.cr, request.session.uid, request.context channels.append((request.db, 'mail_move_message')) channels.append((request.db, 'mail_move_message.delete_message')) return super(MailChatController, self)._poll(dbname, channels, last, options) - class DataSetCustom(DataSet): def _extend_name(self, model, records): - cr, uid, context = request.cr, request.uid, request.context - Model = request.registry[model] - fields = Model.fields_get(cr, uid, False, context) + Model = request.env[model] + fields = Model.fields_get() contact_field = False for n, f in fields.iteritems(): if f['type'] == 'many2one' and f['relation'] == 'res.partner': @@ -33,7 +30,7 @@ class DataSetCustom(DataSet): break partner_info = {} if contact_field: - partner_info = Model.read(cr, uid, [r[0] for r in records], [contact_field], context) + partner_info = Model.browse([r[0] for r in records]).read([contact_field]) partner_info = dict([(p['id'], p[contact_field]) for p in partner_info]) res = [] for r in records: @@ -48,16 +45,15 @@ class DataSetCustom(DataSet): context = kwargs.get('context') if context and context.get('extended_name_with_contact'): # add order by ID desc - cr, uid = request.cr, request.uid - Model = request.registry[model] + Model = request.env[model] search_args = list(kwargs.get('args') or []) limit = int(kwargs.get('limit') or 100) operator = kwargs.get('operator') name = kwargs.get('name') if Model._rec_name and (not name == '' and operator == 'ilike'): search_args += [(Model._rec_name, operator, name)] - ids = Model.search(cr, uid, search_args, limit=limit, order='id desc', context=context) - res = Model.name_get(cr, uid, ids, context) + records = Model.search(search_args, limit=limit, order='id desc') + res = records.name_get() return self._extend_name(model, res) return self._call_kw(model, method, args, kwargs) diff --git a/mail_move_message/mail_move_message_models.py b/mail_move_message/mail_move_message_models.py index 73138ac..da526c4 100644 --- a/mail_move_message/mail_move_message_models.py +++ b/mail_move_message/mail_move_message_models.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from openerp import api, models, fields, SUPERUSER_ID +from openerp import api, models, fields from openerp.tools import email_split from openerp.tools.translate import _ @@ -49,7 +49,8 @@ class wizard(models.TransientModel): res['filter_by_partner'] = True if message.author_id and res.get('model'): res_id = self.env[res['model']].search([], order='id desc', limit=1) - res['res_id'] = res_id and res_id[0].id + if res_id: + res['res_id'] = res_id[0].id config_parameters = self.env['ir.config_parameter'] res['move_followers'] = config_parameters.get_param('mail_relocation_move_followers') @@ -136,19 +137,16 @@ class wizard(models.TransientModel): @api.one def check_access(self): - cr = self._cr - uid = self.env.user.id operation = 'write' - context = self._context if not (self.model and self.res_id): return True - model_obj = self.pool[self.model] - mids = model_obj.exists(cr, uid, [self.res_id]) + model_obj = self.env[self.model] + mids = model_obj.browse(self.res_id).exists() if hasattr(model_obj, 'check_mail_message_access'): - model_obj.check_mail_message_access(cr, uid, mids, operation, context=context) + model_obj.check_mail_message_access(mids.ids, operation) else: - self.pool['mail.thread'].check_mail_message_access(cr, uid, mids, operation, model_obj=model_obj, context=context) + self.env['mail.thread'].check_mail_message_access(mids.ids, operation, model_name=self.model) @api.multi def open_moved_by_message_id(self): @@ -308,7 +306,7 @@ class mail_message(models.Model): r_vals['parent_id'] = r.moved_from_parent_id.id r_vals['res_id'] = r.moved_from_res_id r_vals['model'] = r.moved_from_model - print 'update message', r, r_vals + if move_followers: r.sudo().move_followers(r_vals.get('model'), r_vals.get('res_id')) r.sudo().write(r_vals) @@ -327,14 +325,12 @@ class mail_message(models.Model): } self.env['bus.bus'].sendone((self._cr.dbname, 'mail_move_message'), notification) - def name_get(self, cr, uid, ids, context=None): + @api.multi + def name_get(self): + context = self.env.context 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) + return super(mail_message, self).name_get() + reads = self.read(['record_name', 'model', 'res_id']) res = [] for record in reads: name = record['record_name'] or '' @@ -342,11 +338,6 @@ class mail_message(models.Model): res.append((record['id'], name + extended_name)) return res - def _message_read_dict(self, cr, uid, message, parent_id=False, context=None): - res = super(mail_message, self)._message_read_dict(cr, uid, message, parent_id, context) - res['is_moved'] = message.is_moved - return res - @api.multi def message_format(self): message_values = super(mail_message, self).message_format() diff --git a/mail_move_message/mail_move_message_views.xml b/mail_move_message/mail_move_message_views.xml index 475f7d7..7695d8c 100644 --- a/mail_move_message/mail_move_message_views.xml +++ b/mail_move_message/mail_move_message_views.xml @@ -35,14 +35,16 @@