简体   繁体   English

从 Odoo12 中的 Jquery 调用 python function?

[英]Call python function from Jquery in Odoo12?

Ive created a button named update in the frontend.我在前端创建了一个名为update的按钮。

I need to run the function that I wrote in the python file while clicking the button using jquery .我需要运行我在 python 文件中编写的 function ,同时使用 jquery 单击按钮

xml : xml

<t>
<button id="update_health_profile_front" 
        class="btn btn-primary" 
        type="button">Update
</button>
</t>

py : py


 @api.multi
    def update_health_profile(self):
        # partner = self.partner_id
        #some_method

js : js


$('#update_health_profile_front').click(function(event){
            var rpc = require('web.rpc');
            rpc.query({
            model: 'health.profile',
            method: 'update_health_profile',
        })
        .then(function(result){
            for (i= 0; i< result.length; i++){
                    console.log("result",result[i]);
             }

          },);

Its not working and I don't think this is the right way either, Can anybody share some knowledge?它不起作用,我认为这也不是正确的方法,有人可以分享一些知识吗?

Well you can try this, I think it should work.那么你可以试试这个,我认为它应该工作。

$('#update_health_profile_front').click(function(event){
            var rpc = require('web.rpc');
            rpc.query({
            model: 'this.name',
            method: 'update_health_profile'
        })
        .then(function(result){
            for (i= 0; i< result.length; i++){
                    console.log("result",result[i]);
             }

          },);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM