Browse Source

Merge remote-tracking branch 'origin/8.0' into 9.0-dev

pull/2/head
Ivan Yelizariev 9 years ago
parent
commit
314dc3f3d6
  1. 2
      __openerp__.py
  2. 6
      doc/changelog.rst
  3. 5
      i18n/mail_move_message.pot
  4. 44
      mail_move_message_models.py
  5. 7
      mail_move_message_views.xml

2
__openerp__.py

@ -1,6 +1,6 @@
{
'name' : 'Mail relocation',
'version' : '1.0.3',
'version' : '1.0.4',
'author' : 'IT-Projects LLC, Ivan Yelizariev',
'license': 'LGPL-3',
'category' : 'Social Network',

6
doc/changelog.rst

@ -3,6 +3,12 @@
Changelog
=========
`1.0.4`
-------
- FIX: don't allow to relocate message to itself as it cause infinitive loop
- ADD: 'Move Followers' option -- Add followers of current record to a new record.
`1.0.3`
-------

5
i18n/mail_move_message.pot

@ -165,4 +165,9 @@ msgstr ""
#. module: mail_move_message
#: help:mail_move_message.wizard,filter_by_partner:0
msgid "Show only records with the same partner as email author"
msgstr ""
#. module: mail_move_message
#: help:mail_move_message.wizard,move_followers:0
msgid "Add followers of current record to a new record.\nYou must use this option, if new record has restricted access.\nYou can change default value for this option at Settings/System Parameters"
msgstr ""

44
mail_move_message_models.py

@ -50,6 +50,9 @@ class wizard(models.TransientModel):
res_id = self.env[res['model']].search([], order='id desc', limit=1)
res['res_id'] = res_id and res_id[0].id
config_parameters = self.env['ir.config_parameter']
res['move_followers'] = config_parameters.get_param('mail_relocation_move_followers')
res['uid'] = self.env.uid
return res
@ -73,6 +76,11 @@ class wizard(models.TransientModel):
# FIXME message_to_read should be True even if current message or any his childs are unread
message_to_read = fields.Boolean(related='message_id.to_read')
uid = fields.Integer()
move_followers = fields.Boolean(
'Move Followers',
help="Add followers of current record to a new record.\n"
"You must use this option, if new record has restricted access.\n"
"You can change default value for this option at Settings/System Parameters")
@api.depends('message_id')
@api.one
@ -108,7 +116,7 @@ class wizard(models.TransientModel):
@api.onchange('model', 'filter_by_partner', 'partner_id')
def on_change_partner(self):
domain = {'res_id': []}
domain = {'res_id': [('id', '!=', self.message_id.res_id)]}
if self.model and self.filter_by_partner and self.partner_id:
fields = self.env[self.model].fields_get(False)
contact_field = False
@ -117,7 +125,7 @@ class wizard(models.TransientModel):
contact_field = n
break
if contact_field:
domain['res_id'] = [(contact_field, '=', self.partner_id.id)]
domain['res_id'].append((contact_field, '=', self.partner_id.id))
if self.model:
res_id = self.env[self.model].search(domain['res_id'], order='id desc', limit=1)
self.res_id = res_id and res_id[0].id
@ -166,7 +174,7 @@ class wizard(models.TransientModel):
parent = self.env['mail.message'].search([('model','=',r.model), ('res_id','=',r.res_id)], order='id', limit=1)
r.parent_id = parent.id or None
r.message_id.move(r.parent_id.id, r.res_id, r.model, r.move_back)
r.message_id.move(r.parent_id.id, r.res_id, r.model, r.move_back, r.move_followers)
if not ( r.model and r.res_id ):
obj = self.pool.get('ir.model.data').get_object_reference(self._cr, SUPERUSER_ID, 'mail', 'mail_archivesfeeds')[1]
@ -247,8 +255,19 @@ class mail_message(models.Model):
moved_childs = self.search([('moved_by_message_id', '=', self.id)]).ids
self.all_child_ids = ids + moved_childs
@api.multi
def move_followers(self, model, ids):
fol_obj = self.env['mail.followers']
for message in self:
followers = fol_obj.sudo().search([('res_model', '=', message.model),
('res_id', '=', message.res_id)])
for f in followers:
self.env[model].browse(ids).message_subscribe([f.partner_id.id], [s.id for s in f.subtype_ids])
@api.one
def move(self, parent_id, res_id, model, move_back):
def move(self, parent_id, res_id, model, move_back, move_followers=False):
if parent_id == res_id:
return
vals = {}
if move_back:
# clear variables if we move everything back
@ -281,7 +300,13 @@ class mail_message(models.Model):
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)
r.attachment_ids.sudo().write({
'res_id': r_vals.get('res_id'),
'res_model': r_vals.get('model')
})
def name_get(self, cr, uid, ids, context=None):
if not (context or {}).get('extended_name'):
@ -309,9 +334,10 @@ class mail_move_message_configuration(models.TransientModel):
_inherit = 'res.config.settings'
model_ids = fields.Many2many(comodel_name='ir.model', string='Models')
move_followers = fields.Boolean('Move Followers')
@api.model
def get_default_model_ids(self, fields):
def get_default_move_message_configs(self, fields):
config_parameters = self.env['ir.config_parameter']
model_obj = self.env['ir.model']
model_names = config_parameters.get_param('mail_relocation_models')
@ -319,15 +345,19 @@ class mail_move_message_configuration(models.TransientModel):
return {}
model_names = model_names.split(',')
model_ids = model_obj.search([('model', 'in', model_names)])
return {'model_ids': [m.id for m in model_ids]}
return {
'model_ids': [m.id for m in model_ids],
'move_followers': config_parameters.get_param('mail_relocation_move_followers')
}
@api.multi
def set_model_ids(self):
def set_move_message_configs(self):
config_parameters = self.env['ir.config_parameter']
model_names = ''
for record in self:
model_names = ','.join([m.model for m in record.model_ids])
config_parameters.set_param('mail_relocation_models', model_names)
config_parameters.set_param('mail_relocation_move_followers', record.move_followers or '')
class res_partner(models.Model):

7
mail_move_message_views.xml

@ -48,6 +48,10 @@
<div attrs="{'invisible':[('message_is_moved','=',False)]}">
<field name="move_back"/>
</div>
<label for="move_followers"/>
<div>
<field name="move_followers"/>
</div>
</group>
<button name="move" string="Move" type="object" class="oe_highlight" attrs="{'invisible':[('can_move', '=', False)]}"/>
<button string="Close" class="" special="cancel" />
@ -94,6 +98,9 @@
<div name="general">
<separator string="Models"/>
<field name="model_ids" widget="many2many_tags"/>
<separator string="Options"/>
<label for="move_followers"/>
<field name="move_followers"/>
</div>
</form>
</field>

Loading…
Cancel
Save