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

I wanna call report which is used to print barcode via button. But barcode can't display in report.What am I doing wrong?

I have a model called product.management, and a wizard called product.label.wizard . What I want to do is to print product label l which is a report via wizard.The barcode can display well if the report is call by report menu,but is can't display when report is called by button.Any help would be appreciated!
Here is the wizard code:


class ProductLabelWizard(models.TransientModel):
 _name = 'product.label.wizard'
code_type = fields.Selection([('EAN13', 'EAN13'), ('QR', u'二维码')],string = u'条码类型', default = 'EAN13', required = True)
 quantity = fields.Integer(string = u'数量', required = True, default = 3)
price = fields.Float(string = u'价格', required = True, default = lambda self:self._set_default_price())
 @api.model
def _set_default_price(self):
product_obj = self.env['product.management']
product_ids = product_obj.browse(self._context.get('active_ids', [])
  return product_ids[0].sale_pric  
@api.multi
def btn_print(self):
self.ensure_one()
product_obj = self.env['product.management']
product_ids = product_obj.browse(self._context.get('active_ids', []))
context = {
'code_type': self.code_type,
'quantity': self.quantity,
'price': self.price,
}
datas = {}
if product_ids:
datas = {
'ids': product_ids.ids,
'model': product_obj._name,
'form': product_ids.read()[0],
}
 return {
'type': 'ir.actions.report.xml',
'report_name': 'basic_information_management.report_product_management_template',
'datas': datas,
'context': context
}
Here is my report code:
<report id="report_product_management_action" string="产品标签" model="product.management" report_type="qweb-pdf"        name="basic_information_management.report_product_management_template" menu="False" />
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_product_management_template">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<div class="page">
                    <t t-set="quantity" t-value="o._context['quantity']" />
                    <t t-set="price" t-value="o._context['price']" />
                    <t t-set="code_type" t-value="o._context['code_type']" />
                    <t t-foreach="range(1, quantity+1)" t-as="qty">
                        <div align="center" class="col-xs-6" style="padding:0;">
                            <table style="border-spacing:0;margin-bottom:0;height: 187px; width: 319px; border: 2px solid black;" class="table">
                                <thead>
                                    <tr style="width: 3in;">
                                        <td style="width: 2.63in; font-size: 19px; text-align: left; background-color: #fff; margin-top: 10px;" class="col-xs-8 danger">
                                            <strong style="text-transform: uppercase;">
                                                <t t-esc="o.product_name"/>
                                            </strong>
                                        </td>
                                        <td style="width: 2.63in; font-size: 19px; text-align: right; background-color: #fff; margin-top: 10px;" class="col-xs-8 danger">
                                            <strong>¥</strong>
                                            <strong>
                                                <t t-esc="price"/>
                                            </strong>
                                        </td>
                                    </tr>
                                </thead>
                            <tbody>
                                <tr style="width: 1in;">
                                    <td colspan="2" width="50%" style="text-align: center;border-top: 0px solid #fff;padding: 5px; position: relative;">
                                        <div align="center" style="position:absolute; bottom: 20px; right:10px; left: 10px">
                                            <img t-if="o.product_code" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' %('Code128', o.product_code, 650, 150)" style="height: 70px; width: 100%;"/>
                                            <t t-if="code_type == 'EAN13'">
                                                <span style="font-size: 14px">
                                                    <t t-esc="o.qr_code"/>
                                                </span>
                                            </t>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </t>
            </div>
        </t>
    </t>
</template>
</data>
</openerp>
Avatar
Discard
Best Answer
You can return report like this you will get barcode in you report may this will help you
return self.env['report'].get_action(docids=self.ids, report_name=report_name)
Avatar
Discard