Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
7619 Vistas

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
Descartar

Odoo Reporting Tips:

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

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

Mejor respuesta

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
Descartar
Autor

Thanks it's working fine, now problem solved.

Publicaciones relacionadas Respuestas Vistas Actividad
5
dic 19
10769
4
ene 23
11635
3
abr 19
7092
1
sept 18
7841
1
feb 18
9438