Skip to Content
Menu
This question has been flagged
1860 Views

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,

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 24
64
0
Dec 24
36
1
Dec 24
45
0
Dec 24
54
0
Nov 24
62