I have the following method on my model:
from openerp import models, fields, api, SUPERUSER_ID
class Loan(models.Model):
_name = 'loan'
@api.model
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
This is my email template:
<?xml version="1.0" ?>
<openerp>
<data noupdate="1">
<!--Email template -->
<record id="email_template_loan" model="mail.template">
<field name="name">Loan - Send by Email</field>
<field name="email_from">${(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} Invoice (Ref ${object.number or 'n/a'})</field>
<!--<field name="partner_to">${object.partner_id.id}</field>-->
<field name="model_id" ref="base.model_res_company"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.env.user.lang}</field>
<field name="body_html"><![CDATA[
]]></field>
</record>
</data>
</openerp>
Now, since this method should an email from frontpage (a website page) I've made this javascript function:
odoo.define('opencloud_cashflows.loan_send', 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('loan');
$('#send_mail_function_model').click(function(){
model.call('send_mail_function_model',[])
})
});
});
Then I call this from website page like this:
<script type="text/javascript" src="/opencloud_cashflows/static/src/js/email.js"/>
And in the button which should trigger the javascript:
<center><input id="loan_send" class="btn btn-primary btn-lg" name="loan_send" value="Pedir préstamo al Banco" type="submit" style="background-color:#e67e22;"/></center>
But it doesn't do anything, any ideas on what could be wrong here please?