Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
6876 Zobrazení

Hello. I created a button in model product.product. I have a binary pdf file on my disk. How to open this file when clicking on the button? (The path to the file will be different depending on the selected product.) How to use widget pdf_viewer?


<?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>



@api.multi
def open_pdf(self):
some_code
Avatar
Zrušit

Binary Fields in Odoo: https://goo.gl/2JAxhD

Nejlepší odpověď

widget="pdf_viewer"

Avatar
Zrušit
Nejlepší odpověď

Hi,

i dont understand why are you given button?

you can simply do this.

1) create a binary field in product.ptoduct

2) add field to view of product and set widget as pdf_viewer.

you can add file from your disk in binary field. It will also store in product record.


If you just want to load file from disk and view (no need to store in product record) then create new wizard and return wizard from button method that you have developed. in wizard add binary field in py and xml view.

i hope it will clear to you

Avatar
Zrušit
Nejlepší odpověď

attachment_ids = self.env['ir.attachment'].search([('res_model', '=', 'product.product'), ('res_id', '=', my_product.id)])
if attachment_ids:
    my_product.my_data_field = attachment_ids[0].datas


Avatar
Zrušit
Autor Nejlepší odpověď

Haresh Kansara thx! That file store in ir_attachment, but I dont understand how I can read field 'datas' (dont see database). But I see 'fname_pass' in hdd

Avatar
Zrušit

How many attachments can there be. How do you know which one to choose?

Autor

There may be several attachments for each product. By button I want to open the last downloaded

Autor

Zbik thank you very much! I have button and function with binary field. How I can bind that to widget pdf_viewer (xml file)?