Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5810 Lượt xem

In Odoo 15 below, this bellow code works properly:


odoo.define('module_name.print_button', function(require){
"use strict";

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

FormController.include({
_onButtonClicked: function(event){
console.log(event);

if(event.data.attrs.custom == "print"){
var printer_data = event.data.record.data.printer_data;
if (!printer_data){
alert('No printer data! Please click the Refresh Printer Data button');
return;
}
console.log(printer_data);

var url = "http://localhost:8000/dotmatrix/print";
$.ajax({
type:"POST",
url: url,
data: {
printer_data: printer_data
},
success: function(data){
alert('Print successfull!');
},
error: function(data){
alert('Dotmatrix print failed! Is Proxy Running ?')
console.log(data);
}
});
}

this._super(event);
}
});
});

In Odoo15 and below, the code will send a javascript event on the browser console.


But on Odoo 16, the code above is not readable by Odoo, any code that I enter doesn't show results in the browser console.

e.g. If I create to like this:


FormController.include({
_onButtonClicked: function(event){
console.log('test 123);


The console.log('test 123'); result doesn't appear on the web browser console.


So, what is the conversation of the code in Odoo16, especially in FormController and _onButtonClicked.


Any help, source, or tutorial on how to code the above in Odoo16 will be very appreciated.


Thanks,

Tri

Ảnh đại diện
Huỷ bỏ

@Tri Nanda

any update?

Tác giả

I haven't find the solution @Bhavin

Câu trả lời hay nhất

Hi,

In odoo 16 the FormController is written using OWL framework. so if you have to modify it you have to use the patch function.

/** @odoo-module */

import { patch } from "@web/core/utils/patch";

import FormController from "web.FormController";

patch(FormController.prototype, "file_path or something unique", {
// Here you can add your functions here
})

The _onButtonClicked function is no longer available.

Regards

Ảnh đại diện
Huỷ bỏ

Thank, but I have a button , with event.data.attrs.custom == "print" how this can work, in every button that has this custom. to being called.

Tác giả

Hi Jeffry, do you already found the solution?

Câu trả lời hay nhất

Solution please, i haven't find the solution too :(


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

No I still struggling......

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 23
3240
1
thg 6 24
2405
1
thg 6 24
1491
0
thg 1 24
1094
1
thg 4 24
1598