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.