This question has been flagged
3 Replies
2673 Views

Hello. I created a button on the form:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="button_for_pdf" model="ir.ui.view">
<field name="name">Product Product Inherit Button</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<header>
<button name="open_pdf" type="object" string="Open PDF" style="width:200px"/>
</header>
</field>
</record>
</data>
</odoo>
This button should open the pdf file in the browser
class customize_template_for_product(models.Model):
_inherit = 'product.product'

@api.multi
def open_pdf(self):

param = [self.display_name, 'application/pdf']
sql = 'Select checksum from ir_attachment where res_name=%s and mimetype=%s'
self._cr.execute(sql, param)
checksum = self._cr.fetchall()

#if binary[0][0] is None:
# return

path = self.env['ir.attachment']._get_path('', checksum[0][0])

webbrowser.register('Chrome', None, webbrowser.BackgroundBrowser('C:\Program Files ('
'x86)\Google\Chrome\Application\chrome.exe'))
webbrowser.get('Chrome').open_new(path[1])
But this browser only opens on the computer where the server is installed with Odoo :(( 
How to make it open only at the client who called it?(Pressed the button) Thx...

... or open with widget="pdf_viewer" ?

Avatar
Discard
Best Answer

Hi, 
Since you want to display the report in the browser, i would suggest that you change the report_type into HTML. But if you want to directly display it in Odoo, then consider adding the widget pdf_viewer.


Hope this helps.

Avatar
Discard
Author Best Answer

Zbik Thx! I need example... How to bind a button click to this widget?

Avatar
Discard
Best Answer

Using widget="pdf_viewer" is the right solution for you.

Avatar
Discard