Hello everyone,
I'm working on a module to allow printing more than one barcode label for each product. The idea is that the user opens a wizard from the action menu when viewing a product / product template. That wizard has a field to set the number of labels to print. And then a pdf report should be generated showing that labels.
Well, I've got the first part. The wizard appears asking for the number of labels, but then I really don't know how to pass the product info together with the number of labels to print.
And what I'm trying only gives me an error (TypeError: product.template is not JSON serializable) so far.
So this is my wizard:
class Wizard(models.TransientModel):
_name = "labels.wizard" labels_number = fields.Integer("Labels to print", required=True)
@api.multi
def print_report(self):
product = self.env['product.template'].browse(self._context.get('active_ids'))labels_to_print = self.labels_number
docs = {product, labels_to_print}
return self.env['report'].get_action(self, 'mymodule.report_report_product_all_labels', docs)
And this is my report template (for testing I'm just trying to print the number of labels from the previous step, not the label. Once I can access to the number of labels I think I'll be able to complete the rest by myself):
<template id="report_report_product_all_labels">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="product">
<div class="page"><span t-field="product.labels_to_print"/>
</div>
</t>
</t>
</template>
I have the feeling that the XML part is completely wrong - but I'm really struggling with the Odoo API here, specially with all these XML logic that I can't debug (which is driving me crazy). I've taken at the docs but couldn't figure out how to do this, and after searching for a while all the results I've found are either incomplete or using the old API.
So... Can anybody help?
Thank you!