Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to display in Odoo 9 a pdf already stored in ir.attachment DB model?

By
Javier
on 12/8/15, 9:54 PM 1,022 views

Hello all,


I have a PDF file stored in table ir.attachment which looks like this in table's sql query:

"id";"create_date";"write_date";"res_model";"write_uid";"res_name";"db_datas";"file_size";"create_uid";"company_id";"index_content";"type";"public";"store_fname";"description";"res_field";"mimetype";"name";"url";"res_id";"checksum";"datas_fname"



575;"2015-12-07 17:56:51.769814";"2015-12-07 17:56:51.769814";"purchase.order";1;"PO00008...";"";25095;1;1;"(u'application',)";"binary";f;"89/8954bbeec7fda48248aa40600162dbb43adac851";"";"";"application/pdf";"salida.pdf";"";8;"8954bbeec7fda48248aa40600162dbb43adac851";"salida.pdf"



I am looking for a way to display it (ie. in a new window) when the user clicks on a button in a screen.  For that i did the following:

1. I extended purchase.order model and added do_print_stored_po as shown below:

# -*- coding: utf-8 -*-

from openerp import models, fields, api

class TodoTask(models.Model):

_inherit = 'purchase.order'

@api.one

def do_print_stored_po(self):

my_PO = self.env['ir.attachment'].search([('datas_fname', 'like', 'salida.pdf')])

return {

"type": "ir.actions.client",

"Content-Type: application/pdf\n": my_PO.db_datas

}



2. I inherited also  from purchase.purchase_order_form in the following way:

<openerp>

<data>

<record id="Purchase_Order_Extended" model="ir.ui.view">

<field name="name">Purchase Order - User extension</field>

<field name="model">purchase.order</field>

<field name="inherit_id" ref="purchase.purchase_order_form"/>

<field name="arch" type="xml">

<field name="date_order" position="after">

<button name="do_print_stored_po" type="object" string="Print stored PO" class="oe_highlight" />

</field>

</field>

</record>

</data>

</openerp>

<openerp>

<data>

<record id="Purchase_Order_Extended" model="ir.ui.view">

<field name="name">Purchase Order - User extension</field>

<field name="model">purchase.order</field>

<field name="inherit_id" ref="purchase.purchase_order_form"/>

<field name="arch" type="xml">

<field name="date_order" position="after">

<button name="do_print_stored_po" type="object" string="Print stored PO" class="oe_highlight" />

</field>

</field>

</record>

</data>

</openerp>


When app executed, it does not appear any kind of error or warning, however the screen only  trembles, but nothing happens. I expected the PDF contents would be displayed, but it isn't so.


Can anybody provide any guidance on what  should be done in this case?

I am new at developing with Odoo and may be my question is very basic, if so, I apologize in advance.


Thanks.

@Javier, could this be a solution for you? https://www.odoo.com/apps/modules/8.0/attachment_preview/ This shows a small icon next to an attachment and when you click on it it opens a PDF in a new tab with a nice preview.

Yenthe
on 12/9/15, 2:49 AM
0
Javier
On 12/9/15, 9:39 AM

Yenthe, thanks for your reply. I will test it with v9 and come back to comment on results.

I appreciate your help.

 


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/8/15, 9:54 PM
Seen: 1022 times
Last updated: 12/9/15, 9:39 AM