콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
13297 화면

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
32172
0
11월 18
4603
1
9월 16
4034
0
3월 15
3856
4
6월 18
10073