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

Is there a way to receive an event in odoo 17?

In my xml i have a button with a t-on-click="buttonOnclickPartner"

And this my my js file with my odoo.define:

odoo.define('sale_order_punch.geoloc', [], async function buttonOnclickPartner() { console.log('Button clicked');

});

This works, but i would like to do something similar to this code of odoo 15 in odoo 17:

odoo.define('sale_order_punch.geoloc', function (require){ 

​"use strict";

​var fromController = require('web.FormController');

​var fromRender = require('web.FormRenderer');

​var FormView = require('web.FormView');

​var rpc = require('web.rpc');

​fromController.include({

​ ​_onButtonClicked: function (event) {

​ ​ ​console.log(event.data.record);

​ ​}

​});

});

아바타
취소
베스트 답변

Hi,

To receive events in Odoo 17 using JavaScript, try using the below code,

XML:
<t t-on-click="(ev) => this._onButtonClicked(event)"/>

JS:
    /** @odoo-module */
    import { FormView } from "@web/views/form/form_view";
import { FormController } from "@web/views/form/form_controller";
    import { FormView } from "@web/views/form/form_view";
    import { useService } from "@web/core/utils/hooks";

patch(FormController.prototype, {
        setup(){
            super.setup();
            this.rpc = useService("rpc");
        },
        _onButtonClicked(event) {
            console.log(event);
        }
    });


Hope it helps

아바타
취소

are you really cybrosys? you are using patch without importing it. you import class that you never use. you pass wrong argument. and fatally, Odoo 17 prohibits directives using t-on-click yet you give this answer

관련 게시물 답글 화면 활동
3
12월 23
30336
1
12월 19
9707
0
3월 17
8092
0
10월 18
3724
0
10월 18
7064