Skip to Content
Menu
This question has been flagged

I'm wondering, if I add a button to send an email from a website page in my Odoo module.

If it's "pure" javascript, something like this:

<textarea id="myText">
Lorem ipsum...
</textarea>
<button onclick="sendMail(); return false">Send</button>
function sendMail() {
var link = "mailto:me@example.com"
         + "?cc=myCCaddress@example.com"
         + "&subject=" + escape("This is my subject")
         + "&body=" + escape(document.getElementById('myText').value)
;

window.location.href = link;
}

Suppose the email, should be a field I set up on res_company for that, let's say loan_email, just for example.

Is there a way I could access that field from javascript on a Odoo website page?

I mean, instead of just sending the email as this example does, to actually send it, from the email field set up on res_company ?

I hope I've explained myself, if You have doubts please let me know.

Avatar
Discard
Best Answer

You can acces any records in a model using this

odoo.define('your_module_name.name', function (require) {
var Model = require('web.Model');


var any_variable = new Model(your.model')
       .query(['field_1','field_2'])
          .filter([['any_filter', '=', 'true']])
          .all()
           .then(function (result) {
                          // result will have the records in the model with given filter
                         // here you can access only field_1 and field_2 in that model
           });


Avatar
Discard
Author

Thank You, just one question, should I call this from, let's say a button on website, with the .name on odoo.define? like id="name" name="name"?

odoo.define is used so odoo can find your code.

write var any_variable= new Model.(....) in your button click function to access that model

In odoo 12 javascript how to access records of the model. I thin 'web.Model' is not supported in odoo 12

Related Posts Replies Views Activity
2
Dec 22
4461
0
Nov 24
74
0
Nov 24
132
1
Jun 24
820
0
Jan 24
5881