Odoo11 Custom Report with Wizard

632 views Asked by At

I would like to print some product barcodes with the custom configuration.

Now, the problem is, I have created the wizard but when I click the print button there is no data is transferred to the report.

class BarcodeConfig(models.Model):
_name = 'report.barcode.print'

@api.model
def _default_product_line(self):
    active_ids = self._context.get('active_ids', [])
    products = self.env['product.product'].browse(active_ids)
    return [(0, 0, {'product_id': x.id, 'qty': 1}) for x in products]

product_line = fields.One2many('product.print.wizard', 'barcode_id', string="Products",
                               default=_default_product_line)

@api.multi
def print_report(self):
    data = self.read()[0]
    ids = [x.product_id.id for x in self.product_line]
    config = self.env['barcode.config'].get_values()
    data.update({
        'config': config
    })
    datas = {'ids': ids,
             'form': data
             }
    return self.env.ref('odoo_barcode.barcode_report').report_action(self,data=datas)

In the above code, I had ids as well for product.product model.

<template id="report_barcode_temp">
<t t-call="web.html_container">
    <t t-call="web.internal_layout">
        <div class="page">
            <h2>Report title</h2>
            <strong t-esc="docs"/>
            <strong t-esc="doc_ids"/>
            <span t-esc="data"/>
            <t t-foreach="docs" t-as="o">
                <span t-esc="o"/>
                <p>This object's name is
                    <span t-field="o.name"/>
                </p>
            </t>
        </div>
    </t>
</t>

In the above code, I'm just trying to print what the data's I've, but I've nothing in docs.

<strong t-esc="docs"/>

this line print product.product model as well. but ids not here, That's the problem I have.

Can anyone help me to tell why this happens? Or is there any other way to achieve this?

1

There are 1 answers

0
Prabakaran R On

I have solved this by get_report_values method.

class classname(models.AbstractModel):
_name = 'report.modulename.templatename'

@api.model
def get_report_values(self, docids, data=None):
    # docids: pass from the wizard print button.
    records = self.env[objectname].browse(docids)
    return {
        'doc_ids': docids,
        'doc_model': objectname,
        'docs': records,
        'data': data,}