我在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 <%s>' % (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" ]
最佳答案
也许您可以在send_mail_function_model func中进行调试!并尝试:email_template_obj.send_mail(self._cr,self._uid,template_id,ids [0],True,context = self._context)或self.pool('email.template')代替self.env
关于javascript - 无法从网站发送电子邮件-Odoo v9社区,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44006465/