'hit save as template button: current form value will be a new
template attached to the current document.'

@api.multi
def save_as_template(self):

    for record in self:
        models = self.env['ir.model'].search([('model', '=', (record.model or 'mail.message'))])
        model_name = ''
        if models:
            model_name = models.name
        template_name = ('%s:    %s' % (model_name, tools.ustr(record.subject)))
        values = {'name': template_name, 'subject': (record.subject or False), 'body_html': (record.body or False), 'model_id': (models.id or False), 'attachment_ids': [(6, 0, [att.id for att in record.attachment_ids])]}
        template = self.env['mail.template'].create(values)
        record.write({'template_id': template.id})
        record.onchange_template_id_wrapper()
        return _reopen(self, record.id, record.model, context=self._context)
