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

Hello,

I made a wizard that prints a report from a button. It works well and only uses the backend.

Wizard code :

class SmlPrintProductLabelWizard(models.TransientModel):

_name = 'print.product.label.wizard'

nb_printing = fields.Integer()

def print_product_label(self):
if (self.nb_printing >= 0):
return self.env.ref('colona_custo.action_report_product_label').report_action([], data={'stock_move_line_id': self.env.context.get('active_id'), 'nb_printing': self.nb_printing})
else:
raise UserError("The number of printing is incorrect.")

Now, I would like to do the same, but from a button in the barcode interface, so from a button written in a static xml file.

I created my button, added an event on it with some JavaScript that calls another backend function designed to print a report :

The backend function :

def print_product_label_from_js(self, nb_printing=1, move_line_id=34):
return self.env.ref('colona_custo.action_report_product_label').report_action([], data={'stock_move_line_id': int(move_line_id), 'nb_printing': int(nb_printing)})

I can see that my script calls the right function, if I print something in my "print_product_label_from_js", it will appear in the console.

The problem :

Even if my function seems to be called and print something in the console, the report still not load. 

I tested my python function independently by calling it from the backend, and the report is loaded there.

JavaScript script :

odoo.define("colona_custo.print_product_label", function(require) {
"use strict";

var rpc = require("web.rpc");

function call_print_function(nb_printing, move_line_id)
{
console.log(nb_printing);
console.log(move_line_id);


rpc.query({
model: 'print.product.label.wizard',
method: 'print_product_label_from_js',
args: [[], nb_printing, move_line_id]
});

}

function print_product_label()
{
var move_line_id = $(this).next().text();

// Asking the user how many times he wants to print the label.
$(document.body).append("

How many times do you want to print the product label?

")
$('#close_popup_printing').on('click', function() {
$('#warning_popup').hide();
});

$('#action_print').on('click', function() {
var nb_printing = $('#user_entry').val();
if (nb_printing > 0) {
call_print_function(nb_printing, move_line_id);
}

});
}

$(document).on('click', '.o_button_print_product_label', print_product_label)




});

The function that calls the backend is call_print_function, and my console.log appears.


Can someone tell me why my report doesn't load?


Thank you,

Regards,

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
155
0
thg 8 25
272
1
thg 8 25
678
1
thg 8 25
523
4
thg 7 25
1883