[FIX][IMP] mail, rating, website_forum: inherit message_post using kwargs

Several addons inherit from message_post method. Instead of redefining
the long list of parameters let us just use kwargs and propagate them to
the super call. Only really used parameters are set as explicit.

Purpose is to lessen issues when changing some parameters default value
or when having some API change.
This commit is contained in:
Thibault Delavallée
2018-01-05 10:32:25 +01:00
parent 9ec0455abc
commit d7c24089ee
3 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -240,10 +240,10 @@ class Channel(models.Model):
@api.multi
@api.returns('self', lambda value: value.id)
def message_post(self, body='', subject=None, message_type='notification', subtype=None, parent_id=False, attachments=None, content_subtype='html', **kwargs):
def message_post(self, **kwargs):
# auto pin 'direct_message' channel partner
self.filtered(lambda channel: channel.channel_type == 'chat').mapped('channel_last_seen_partner_ids').write({'is_pinned': True})
message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(body=body, subject=subject, message_type=message_type, subtype=subtype, parent_id=parent_id, attachments=attachments, content_subtype=content_subtype, **kwargs)
message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(**kwargs)
return message
def _alias_check_contact(self, message, message_dict, alias):
+2 -2
View File
@@ -9,9 +9,9 @@ class MailThread(models.AbstractModel):
@api.multi
@api.returns('self', lambda value: value.id)
def message_post(self, body='', subject=None, message_type='notification', subtype=None, parent_id=False, attachments=None, content_subtype='html', **kwargs):
def message_post(self, **kwargs):
rating_value = kwargs.get('rating_value')
message = super(MailThread, self).message_post(body=body, subject=subject, message_type=message_type, subtype=subtype, parent_id=parent_id, attachments=attachments, content_subtype=content_subtype, **kwargs)
message = super(MailThread, self).message_post(**kwargs)
if rating_value:
ir_model = self.env['ir.model'].sudo().search([('model', '=', self._name)])
self.env['rating.rating'].create({
+2 -2
View File
@@ -796,7 +796,7 @@ class Post(models.Model):
@api.multi
@api.returns('self', lambda value: value.id)
def message_post(self, message_type='notification', subtype=None, **kwargs):
def message_post(self, message_type='notification', **kwargs):
question_followers = self.env['res.partner']
if self.ids and message_type == 'comment': # user comments have a restriction on karma
# add followers of comments on the parent post
@@ -816,7 +816,7 @@ class Post(models.Model):
raise KarmaError('Not enough karma to comment')
if not kwargs.get('record_name') and self.parent_id:
kwargs['record_name'] = self.parent_id.name
return super(Post, self).message_post(message_type=message_type, subtype=subtype, **kwargs)
return super(Post, self).message_post(message_type=message_type, **kwargs)
@api.multi
def message_get_message_notify_values(self, message, message_values):