'Tool to convert a comment (mail.message) into an answer (forum.post).
The original comment is unlinked and a new answer from the comment\'s author
is created. Nothing is done if the comment\'s author already answered the
question.'

@api.model
def convert_comment_to_answer(self, message_id, default=None):

    comment = self.env['mail.message'].sudo().browse(message_id)
    post = self.browse(comment.res_id)
    if ((not comment.author_id) or (not comment.author_id.user_ids)):
        return False
    karma_convert = (((comment.author_id.id == self.env.user.partner_id.id) and post.forum_id.karma_comment_convert_own) or post.forum_id.karma_comment_convert_all)
    can_convert = (self.env.user.karma >= karma_convert)
    if (not can_convert):
        raise KarmaError('Not    enough    karma    to    convert    a    comment    to    an    answer')
    question = (post.parent_id if post.parent_id else post)
    post_create_uid = comment.author_id.user_ids[0]
    if any(((answer.create_uid.id == post_create_uid.id) for answer in question.child_ids)):
        return False
    post_values = {'forum_id': question.forum_id.id, 'content': comment.body, 'parent_id': question.id}
    new_post = self.sudo(post_create_uid.id).create(post_values)
    comment.unlink()
    return new_post
