Skip to Content
Menu
This question has been flagged
1 Reply
6730 Views

Hello,

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 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>
</template>

In above code I'm just try 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 happen. Or is there any other way to achieve this.

 

Avatar
Discard

Odoo Reporting Tips:

1- How to create Qweb reports: https://goo.gl/tg2Zyp

2- How to create custom reports: https://goo.gl/KZEo8X

Best Answer

Hello, 

you need to add the method "get_report_values" into new object. and that object is must be the abstractmodel.

see the example of Accounting report.

the method get_report_values is something like below code.


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,}                                                                    
Avatar
Discard
Author

Thanks it's working fine, now problem solved.

Related Posts Replies Views Activity
5
Dec 19
9130
4
Jan 23
10446
3
Apr 19
6094
1
Sep 18
6539
1
Feb 18
8205