This question has been flagged

I have this model:

@api.one
def send_mail_function_model(self):
    template_id = self.env.ref('opencloud_cashflows.email_template_loan') #self.pool('email.template') self.env.ref
    if template_id:
        template_id.send_mail(self.id, force_send=True) #self.ids[0], force_send=True
    return True

Which I call from this controller:

class Loan(http.Controller):
@http.route(['/request_loan'], type='http', auth='user', website=True)
def send_mail_function(self, **kw):
    if request.env.uid != request.website.user_id.id:
        request.env.user.send_mail_function_model()
    return request.website.render('opencloud_cashflows.request_loan')

This is the javascript file:

odoo.define('opencloud_cashflows.opencloud_cashflows', function (require) { "use strict";
var ajax = require('web.ajax');
var core = require('web.core');
var website = require('website.website');
var _t = core._t;
var Model = require('web.Model');
$('.send_mail_function').on('click', function (){
    var model = new Model('res_users');
    $('send_mail_function_model').click(function(){
        model.call('send_mail_function_model',[])

    })
});
});

The email template:

<?xml version="1.0" ?>
<openerp>
<data noupdate="0">
    <!--Email template -->
    <record id="email_template_loan" model="mail.template">
        <field name="name">Loan - Send by Email</field>
        <field name="email_from"><![CDATA[${object.company_id.name} <${(object.company_id.email or user.email)|safe}>]]></field>
        <field name="email_to">${(object.company_id.loan_email and '%s &lt;%s&gt;' % (object.company_id.name, object.company_id.loan_email) or '')|safe}</field>
        <field name="subject">${object.company_id.name} Pedido de préstamo desde blinking.cl</field>
        <!--<field name="partner_to">${object.partner_id.id}</field>-->
        <field name="model_id" ref="model_cashflow_report"/>
        <field name="auto_delete" eval="True"/>
        <field name="lang">${object.env.user.lang}</field>
        <field name="body_html"><![CDATA[
        <div style="font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
<center><img src="http://www.blinking.cl/images/blinking-img-redes.jpg"></img></center>
<p>Hola ${object.partner_id.bank},</p>
<br/>
<p>Requerimos la siguiente cantidad como préstamo ${object.field_total},</p>
<br/>
<p>Por favor cualquier duda comuniquese con nuestro teléfono ${object.company_id.phone},</p>
<br/>
<p>Muchas Gracias</p>
        ]]></field>
    </record>
</data>
</openerp>

The view I'm calling from the controller:

    </template>
    <template id="request_loan" name="Loan">
        <t t-call="website.layout">
          <div id="wrap">
            <div class="oe_structure"/>
            <div class="container">
                <h1Gracias!</h1>
                <div class="row">
                    <div class="col-md-8">
                        <div class="alert alert-success">
                            Tu pedido se ha enviado satisfactoriamente.
                            <button type="button" class="close" data-dismiss="alert">&amp;times;</button>
                        </div>
                        <!--<p>
                            We will get back to you shortly.
                        </p>--><p class="mt64">
                            If you have an emergency, do not hesitate to contact us by phone:
                        </p>
                        <ul class="list-unstyled">
                            <li><i class="fa fa-phone"></i> : <span t-field="res_company.phone"/></li>
                            <li><i class="fa fa-envelope"></i> : <span t-field="res_company.email"/></li>
                        </ul>
                        <a href="/cashflows/"><span class="btn btn-primary btn-lg" style="margin-left:560px; margin-top:-70px; background-color:#e67e22;">Volver</span></a>
                    </div>
                    <div class="col-md-4">
                        <t t-call="website.company_description"/>
                    </div>
                </div>
            </div>
            <div class="oe_structure"/>
          </div>
        </t>
    </template>

And the button from which I call the function:

<center><a href="/request_loan"><button id="send_mail_function" class="btn btn-primary btn-lg" name="send_mail_function" value="Pedir préstamo al Banco" type="submit" style="background-color:#e67e22;" >Pedir préstamo al Banco</button></a></center>

It seems to be working fine though, besides the fact that it cannot render the email template, every time I click on the button it throws me this:

Traceback (most recent call last):
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/website/models/ir_http.py", line 242, in _handle_exception
response = super(ir_http, self)._handle_exception(exception)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/base/ir/ir_http.py", line 158, in _handle_exception
return request._handle_exception(exception)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 786, in _handle_exception
return super(HttpRequest, self)._handle_exception(exception)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/base/ir/ir_http.py", line 183, in _dispatch
result = request.dispatch()
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 845, in dispatch
r = self._call_function(**self.params)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov9/danisan/opencloud_cashflows/controllers/main.py", line 1017, in send_mail_function
request.env.user.send_mail_function_model()
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 425, in new_api
result = [method(rec, *args, **kwargs) for rec in self]
File "/home/kristian/odoov9/danisan/opencloud_cashflows/models/res_users.py", line 27, in send_mail_function_model
template_id.send_mail(self.id, force_send=True) #self.ids[0], force_send=True
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/mail/models/mail_template.py", line 537, in send_mail
values = self.generate_email(res_id)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/mail/models/mail_template.py", line 470, in generate_email
post_process=(field == 'body_html'))
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/mail/models/mail_template.py", line 367, in render_template
raise UserError(_("Failed to render template %r using values %r")% (template, variables))
UserError: (u"Failed to render template <Template memory:7fb8f2abf050> using values {'format_tz': <function <lambda> at 0x7fb8f03b0668>, 'ctx': {'lang': u'es_CL', 'tz': u'America/Santiago', 'safe': True, 'website_id': 1, 'uid': 1}, 'user': res.users(1,), 'object': cashflow.report(1,)}", None)

I've read somewhere that it has to do with the default language set up in the database, or user, and on some other post someone says that it is due to the gmail smtp server (which I have configured as smtp server in my odoo instance)

Any ideas?


Avatar
Discard