Skip to Content
Menu
This question has been flagged
4 Replies
11628 Views

Hello 

I'm going to add some code to my custom module to be able to call email templates and choose related template with my module through a drop down selector list, so any body know how to start to do that?

i already made 2 template to my custom module inside email.template  and i tested with mail.compose.message module and it worked fine

i watched to some similar modules but actually they made me more confused.. so i just want to call my modules own templates with a Many2one field and nothing more no send mail or other extra task... but saving current content can be effective

the field that template should load in that is note and my custom module is res_correspond_int with ResCorrespondINT class
as i got until now i should add a line for my xml file like below 

<field name="template_id" attrs="{'readonly': [ ('state', 'not in', ['draft'])], 'required': True}"/>

and a code for calling related template (not working )

template_id = fields.Many2one(
    'email.template',
    string='Template',
    track_visibility='onchange',
    default=default_template)

@api.multi
def default_template(self):
    note = ''
    default_template_obj = self.env['email.template']
    template_id = default_template_obj.search([('model', '=', 'res.correspond.int')], limit=5)
    if template_id:
     for i in self:
        note += '\n' + i.note
        default_template_obj.note(template_id.id, self._context.get('active_id'), )
     return


Avatar
Discard
Best Answer

I am not sure exactly what you are trying to do but I think you want to show the Email Templates which are related to your model.

Try following code:

template_id = fields.Many2one(
'email.template',
string='Template',
domain=[('model', '=', 'res.correspond.int')],
track_visibility='onchange',
default=default_template)

If you wish send the email from any method, try following code:

@api.multi
def action_send_mail(self):
for rec in self:
rec.template_id.send_mail(rec.id) # Call send_mail method of the mail template obj
return True
Avatar
Discard
Best Answer

This may help you :

# template id is nothing but xml id of that particular template
template = self.env['ir.model.data'].get_object('# object_name',template_id)

# Send out the e-mail template to the user
template_obj = self.env['mail.template'].browse(template.id)
template_obj.send_mail(# record_id)

Avatar
Discard
Author Best Answer

@Nitin Kantak 
Hello Nitin, Can you please tell me what do this "template" field below? coz it does not called any where in code.. it just collect data and stop


template = self.env['ir.model.data'].get_object('# object_name',template_id)


for second line i said in first that i won't send mail this template.. just want to load into "note" field inside my class and save .. so do you know any way to putting it inside a field (note) with selecting that from a Many2one drop down list?



# Send out the e-mail template to the user
template_obj = self.env['mail.template'].browse(template.id)
template_obj.send_mail(# record_id)

**********************************************************

@Sudhir Arya

\\
\\\\

Sudhir AryaSudhir AryaSudhir Arya


No, actually i just want to load email.template data inside a field named "note" thats all

Avatar
Discard

In that case you have to write onchange event of template_id like this

@api.onchange('template_id')

def onchange_template_id(self):

if self.template_id :

self.notes = self.env['mail.template'].render_template(self.template_id.body, 'hr.employee', self.id)

you can hr.employee with your model name.

Best Answer

Hi, I'm using odoo 10, i already installing project_issue, I want to know where can I find project issue email template.


thanks you

Avatar
Discard
Related Posts Replies Views Activity
4
Jan 19
30173
0
Nov 18
3459
1
Sep 16
3075
0
Mar 15
2893
4
Jun 18
8565