Browse Source

[PORT] update mail_move_message for 10.0

pull/57/head
Ivan Yelizariev 8 years ago
parent
commit
db946c1872
  1. 16
      mail_move_message/controllers/main.py
  2. 35
      mail_move_message/mail_move_message_models.py
  3. 14
      mail_move_message/mail_move_message_views.xml

16
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)

35
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()

14
mail_move_message/mail_move_message_views.xml

@ -35,14 +35,16 @@
</div>
<label for="filter_by_partner"/>
<div>
<field name="filter_by_partner"/>
<field name="partner_id" style="width:50%"/>
<button string="Create Partner" attrs="{'invisible':[('partner_id','!=',False)]}" class="oe_highlight" special="quick_create" field="partner_id" context="{'force_email':True,'default_email':message_email_from,'default_name':message_name_from, 'update_message_author':True}"/>
<field name="filter_by_partner" class="oe_inline"/>
<field name="partner_id" class="oe_inline"/>
<button string="Create Partner" attrs="{'invisible':[('partner_id','!=',False)]}"
class="oe_highlight oe_inline ml32"
special="quick_create" field="partner_id" context="{'force_email':True,'default_email':message_email_from,'default_name':message_name_from, 'update_message_author':True}" />
</div>
<label for="res_id"/>
<div>
<field name="res_id" context="{'extended_name_with_contact':1}" widget="many2one" attrs="{'readonly': [('model','=',False)]}" style="width:50%"/>
<button string="Create new record" name="create_record" type="object" class="oe_highlight" attrs="{'invisible':['|',('model','=',False)]}" special="quick_create" field="res_id" use_for_mail_move_message="True"/>
<field name="res_id" context="{'extended_name_with_contact':1}" widget="many2one" attrs="{'readonly': [('model','=',False)]}" class="oe_inline"/>
<button string="Create new record" name="create_record" type="object" class="oe_highlight oe_inline ml32" attrs="{'invisible':['|',('model','=',False)]}" special="quick_create" field="res_id" use_for_mail_move_message="True"/>
</div>
<label for="move_back" attrs="{'invisible':[('message_is_moved','=',False)]}"/>
<div attrs="{'invisible':[('message_is_moved','=',False)]}">
@ -78,7 +80,7 @@
<button special="cancel" string="Close" class="oe_link"/>
<button name="delete" string="Delete message" type="object" class="oe_highlight oe_right" confirm="Do you really want to delete this message?" attrs="{'invisible':[('uid','!=',1)]}"/>
<button name="delete" string="Delete message" type="object" class="oe_highlight pull-right" confirm="Do you really want to delete this message?" attrs="{'invisible':[('uid','!=',1)]}"/>
</footer>
</form>
</field>

Loading…
Cancel
Save