跳至内容
菜单
此问题已终结
4 回复
13138 查看

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


形象
丢弃
最佳答案

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
形象
丢弃
最佳答案

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)

形象
丢弃
编写者 最佳答案

@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

形象
丢弃

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.

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
4
1月 19
31963
0
11月 18
4483
1
9月 16
3918
0
3月 15
3697
4
6月 18
9917