تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
5 الردود
13569 أدوات العرض

I'm trying to add some data that is not in the model. I'm trying to do that with the email_values dict in send_mail method from the mail_template model.

send_mail(self, res_id, force_send=False, raise_exception=False, email_values=None)

But I'm getting failed to render errors and email_values in undefined!

Can someone show me how to use the dict in the template? I'm trying to use it like ${email_values.get('dict_key')}

الصورة الرمزية
إهمال

I would recommand that you add your code here so that the community can check your dict values..

الكاتب

the values are not the problem. I'm using the standard send_mail() method from model mail.template. The xml template definition is a basic email template and I need to know how to reference the dict in the template, because it says the dict is undefined NOT it's values. So there's no need to post any code!

Well in that case, You call your template with reference (self.env.ref('...'))

Since it's this template that you want to change its values : template.write(your val dict)

Finally : template.send_mail(your_record_id, force_send=False, raise_exception=False)

Regards.

الكاتب

I know how to get templates and send them. The correct answer was that I can't do it the way I'm trying.

الكاتب أفضل إجابة

Mail templates can only use data from the specified model and with the models that are related with it. To pass some custom data it needs to be a dict passed trough context. 

template = self.env.ref('module.template_xml_id')
email_values = {'key': u'value'}
template.with_context(email_values).send_mail(self.id, email_values=None, email_from=None)
And getting the values in email template 
${ctx.get('key')}

الصورة الرمزية
إهمال

Then what's the point of `email_values` parameter in `send_mail`? How to use it properly to pass custom values to the template?

الكاتب

don't know. It works with a dict in with_context. Like I wrote in the answer. You can check the method in the mail addon.

المنشورات ذات الصلة الردود أدوات العرض النشاط
3
مارس 23
7452
2
يوليو 25
4709
2
ديسمبر 24
7832
2
نوفمبر 24
28621
2
مايو 24
7545