Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
4 Risposte
7162 Visualizzazioni

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
Abbandona

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

Risposta migliore

widget="pdf_viewer"

Avatar
Abbandona
Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Autore Risposta migliore

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
Abbandona

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

Autore

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

Autore

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