I'm mew in OpenERP and I'm trying to create a web module "web_example".
<web_example>
+-- __openerp__.py
+-- __init__.py
+-- web_example.py
+-- web_example_view.xml
+-- static/
+-- src/
+-- js/
+--first_module.js
+-- xml/
+--web_example_view.xml
In web_example.py I have a function that returns the content of a file on the server. In static/src/xml/web_exemple.py I have a button which triggers javascript from first_module.js. And in first_module.js I would like to call the function from web_example.py to get the content of the file. How should I do?
Here is my code :
// static/src/js/first_module.js
openerp.web_example = function (instance) {
instance.web.client_actions.add('example.action', 'instance.web_example.Action');
instance.web_example.Action = instance.web.Widget.extend({
template: 'web_example.action',
events: {
'click .oe_web_example_print button' : 'print_start',
'click .oe_web_example_load button' : 'load_start'
},
init: function () {
this._super.apply(this, arguments);
},
print_start: function () {
window.print();
},
load_start: function () {
//CALL THE PYTHON FUNCTION FROM WEB_EXAMPLE.PY
}
});
};
#web_example.py
from osv import fields, osv
import re
class web_example(osv.osv):
_name='web.example'
#_table ='test_printer'
_description = 'Test pour l\'impression de fichiers'
def button_function(self, cr, uid, ids, context=None):
filename = '/home/stage2013/Documents/testlecture'
fichier = open('/home/stage2013/Documents/testlecture', 'r')
toutesleslignes = fichier.readlines()
fichier.close()
return toutesleslignes
web_example()