Browse Source

Merge pull request #57 from yelizariev/10.0-new-api

[PORT] update mail_move_message for 10.0
pull/64/head
Ivan Yelizariev 8 years ago
committed by GitHub
parent
commit
d98643b591
  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
  4. 2
      oca_dependencies.txt

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): def _poll(self, dbname, channels, last, options):
if request.session.uid: 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'))
channels.append((request.db, 'mail_move_message.delete_message')) channels.append((request.db, 'mail_move_message.delete_message'))
return super(MailChatController, self)._poll(dbname, channels, last, options) return super(MailChatController, self)._poll(dbname, channels, last, options)
class DataSetCustom(DataSet): class DataSetCustom(DataSet):
def _extend_name(self, model, records): 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 contact_field = False
for n, f in fields.iteritems(): for n, f in fields.iteritems():
if f['type'] == 'many2one' and f['relation'] == 'res.partner': if f['type'] == 'many2one' and f['relation'] == 'res.partner':
@ -33,7 +30,7 @@ class DataSetCustom(DataSet):
break break
partner_info = {} partner_info = {}
if contact_field: 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]) partner_info = dict([(p['id'], p[contact_field]) for p in partner_info])
res = [] res = []
for r in records: for r in records:
@ -48,16 +45,15 @@ class DataSetCustom(DataSet):
context = kwargs.get('context') context = kwargs.get('context')
if context and context.get('extended_name_with_contact'): if context and context.get('extended_name_with_contact'):
# add order by ID desc # 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 []) search_args = list(kwargs.get('args') or [])
limit = int(kwargs.get('limit') or 100) limit = int(kwargs.get('limit') or 100)
operator = kwargs.get('operator') operator = kwargs.get('operator')
name = kwargs.get('name') name = kwargs.get('name')
if Model._rec_name and (not name == '' and operator == 'ilike'): if Model._rec_name and (not name == '' and operator == 'ilike'):
search_args += [(Model._rec_name, operator, name)] 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._extend_name(model, res)
return self._call_kw(model, method, args, kwargs) return self._call_kw(model, method, args, kwargs)

35
mail_move_message/mail_move_message_models.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 import email_split
from openerp.tools.translate import _ from openerp.tools.translate import _
@ -49,7 +49,8 @@ class wizard(models.TransientModel):
res['filter_by_partner'] = True res['filter_by_partner'] = True
if message.author_id and res.get('model'): if message.author_id and res.get('model'):
res_id = self.env[res['model']].search([], order='id desc', limit=1) 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'] config_parameters = self.env['ir.config_parameter']
res['move_followers'] = config_parameters.get_param('mail_relocation_move_followers') res['move_followers'] = config_parameters.get_param('mail_relocation_move_followers')
@ -136,19 +137,16 @@ class wizard(models.TransientModel):
@api.one @api.one
def check_access(self): def check_access(self):
cr = self._cr
uid = self.env.user.id
operation = 'write' operation = 'write'
context = self._context
if not (self.model and self.res_id): if not (self.model and self.res_id):
return True 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'): 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: 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 @api.multi
def open_moved_by_message_id(self): 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['parent_id'] = r.moved_from_parent_id.id
r_vals['res_id'] = r.moved_from_res_id r_vals['res_id'] = r.moved_from_res_id
r_vals['model'] = r.moved_from_model r_vals['model'] = r.moved_from_model
print 'update message', r, r_vals
if move_followers: if move_followers:
r.sudo().move_followers(r_vals.get('model'), r_vals.get('res_id')) r.sudo().move_followers(r_vals.get('model'), r_vals.get('res_id'))
r.sudo().write(r_vals) 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) 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'): 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 = [] res = []
for record in reads: for record in reads:
name = record['record_name'] or '' name = record['record_name'] or ''
@ -342,11 +338,6 @@ class mail_message(models.Model):
res.append((record['id'], name + extended_name)) res.append((record['id'], name + extended_name))
return res 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 @api.multi
def message_format(self): def message_format(self):
message_values = super(mail_message, self).message_format() message_values = super(mail_message, self).message_format()

14
mail_move_message/mail_move_message_views.xml

@ -35,14 +35,16 @@
</div> </div>
<label for="filter_by_partner"/> <label for="filter_by_partner"/>
<div> <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> </div>
<label for="res_id"/> <label for="res_id"/>
<div> <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> </div>
<label for="move_back" attrs="{'invisible':[('message_is_moved','=',False)]}"/> <label for="move_back" attrs="{'invisible':[('message_is_moved','=',False)]}"/>
<div 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 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> </footer>
</form> </form>
</field> </field>

2
oca_dependencies.txt

@ -1,4 +1,4 @@
OCA_web https://github.com/OCA/web
OCA_web https://github.com/it-projects-llc/web.git
access-addons https://github.com/it-projects-llc/access-addons.git access-addons https://github.com/it-projects-llc/access-addons.git
misc-addons https://github.com/it-projects-llc/misc-addons misc-addons https://github.com/it-projects-llc/misc-addons
website-addons https://github.com/it-projects-llc/website-addons website-addons https://github.com/it-projects-llc/website-addons
Loading…
Cancel
Save