Created
August 19, 2015 07:21
-
-
Save funbaker/0b81b2237bd01cc6c656 to your computer and use it in GitHub Desktop.
odoo action email template send
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from openerp import fields, models | |
class {{ CLASS NAME }}(models.Model): | |
_inherit = '{{ INHERITED MODEL }}' | |
def {{ ACTION NAME }}(self, cr, uid, ids, context=None): | |
''' | |
{{ DESCRIPTION }} | |
''' | |
assert len(ids) == 1, 'This option should only be used for a single id at a time.' | |
ir_model_data = self.pool.get('ir.model.data') | |
try: | |
template_id = ir_model_data.get_object_reference(cr, uid, '{{ MODULE NAME }}', '{{ TEMPLATE NAME }}')[1] | |
except ValueError: | |
template_id = False | |
try: | |
compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1] | |
except ValueError: | |
compose_form_id = False | |
ctx = dict() | |
ctx.update({ | |
'default_model': '{{ MODEL NAME }}', | |
'default_res_id': ids[0], | |
'default_use_template': bool(template_id), | |
'default_template_id': template_id, | |
'default_composition_mode': 'comment', | |
'mark_so_as_sent': True | |
}) | |
return { | |
'type': 'ir.actions.act_window', | |
'view_type': 'form', | |
'view_mode': 'form', | |
'res_model': 'mail.compose.message', | |
'views': [(compose_form_id, 'form')], | |
'view_id': compose_form_id, | |
'target': 'new', | |
'context': ctx, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment