From d7c24089ee6cee6f728553cd61143c034e4f08d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 4 Jan 2018 13:09:35 +0100 Subject: [PATCH] [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. --- addons/mail/models/mail_channel.py | 4 ++-- addons/rating/models/mail_thread.py | 4 ++-- addons/website_forum/models/forum.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index f4e79cbf8eb..fefa20c53c1 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -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): diff --git a/addons/rating/models/mail_thread.py b/addons/rating/models/mail_thread.py index 89ba8badf89..66ca2139465 100644 --- a/addons/rating/models/mail_thread.py +++ b/addons/rating/models/mail_thread.py @@ -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({ diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index b9da18ffee3..93c3144bbd0 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -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):