콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
9403 화면

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()
아바타
취소
베스트 답변

To call a py method in openerp web_addon, first get the dataset od that object and then call the method. For ex, in this case it can be like :

load_start: function () {

//ids = get the id of the current record
   // context : get the context 
var ds = new instance.web.DataSet(this, 'web.example', context);
ds.call('button_function', [ids]).done(function(r) {
    //process the value returned from 'button_function' as per your requirement.
})

}

아바타
취소
관련 게시물 답글 화면 활동
1
3월 15
8325
4
5월 19
4115
1
1월 24
12357
1
12월 23
23161
2
7월 25
1300