无法从网站发送电子邮件 - Odoo v9社区

时间:2017-05-16 16:07:27

标签: javascript python openerp odoo-9

我在cashflow_report模型上有这个方法:

class cashflow_report(models.Model):
    _name = 'cashflow.report'
    _description = 'Cashflow Report'
    _order = "date asc, id asc"
    @api.one
    def send_mail_function_model(self):
        template_id = self.env.ref('opencloud_cashflows.email_template_loan')
        if template_id:
            template_id.send_mail(self.id, force_send=True)
        return True

然后,我的电子邮件模板:

<?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="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>

然后这个javascript方法,该文件名为email.js

odoo.define('opencloud_cashflows.cashflow_report', function (require) {
"use strict";
var ajax = require('web.ajax');
var core = require('web.core');
var session = require('web.session');
var base = require('web_editor.base');
var _t = core._t;
base.url_translations = '/website/translations';
var _t = core._t;
var Model = require('web.DataModel');
$(document).ready(function(){
    var model = new Model('cashflow_report');
    $('send_mail_function_model').click(function(){

    model.call('send_mail_function_model',[])

    })
});
});

所以,从Odoo的网站页面我调用文件:

    <template id="assets_frontend_website_page_cashflows" inherit_id="website.assets_frontend" name="Assets Dashboard Website Page">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/opencloud_cashflows/static/src/js/highcharts.js"/>
            <script type="text/javascript" src="/opencloud_cashflows/static/src/js/exporting.js"/>
            <script type="text/javascript" src="/opencloud_cashflows/static/src/js/email.js"/>
            <style type="text/css">
                ${demo.css}
            </style> ...

然后,在一个按钮上,我从javascript调用该函数,该函数最初在模型文件中声明:

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

我不知道它是按钮类型(提交),还是电子邮件模板上缺少某些内容?

我在Odoo的后端配置了外发电子邮件,但每次点击此按钮都不会发送任何内容。

此外,命令行上没有跟踪。什么都没有。

有什么想法吗?

修改

检查firefox上的按钮显示:

Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead[Learn More]  es5-shim.min.js:2
warning: Some modules could not be started 
Missing dependencies:    Array [ "web.DataModel" ] 
Rejected modules:        Array [ "website_portal",    "website_forum.website_forum", "website_forum.share", "website_payment.website_payment", "website_sale.website_sale", "website_blog.editor" ] 
Non loaded modules:      Array [ "opencloud_cashflows.cashflow_report" ]

1 个答案:

答案 0 :(得分:1)

也许你可以在send_mail_function_model函数中调试!并尝试:email_template_obj.send_mail(self._cr,self._uid,template_id,ids [0],True,context = self._context)或self.pool(&#39; email.template&#39;)而不是self.env