Odoo Help


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.


Change filename on field.binary()

Francisco Castro
on 5/15/14, 11:03 AM 6,721 views


I'm with some troubles when I'm downloading some files. The name I set to the file is for example "123456.xml" and when I download it the file name is the name of my model....

I store the name and the filedata on a database to set as default on the new wizard after I click on a button (I have some images to help you understand :) )

My .py 

I create the columns 

class Saft_Export_Transporte(osv.osv_memory):
    _name = 'saft.export.transporte'
    _description = 'Saft Export'

    def get_filedata_transporte(self, cr, uid, context=None):
      cr.execute("SELECT filedata from Saft_Export_Transporte where id=1")
      return output

    def get_name_transporte(self, cr, uid,context=None):
      cr.execute("SELECT name from Saft_Export_Transporte")
      return output

    _columns = {
             'name': fields.char('Nome',size=25, readonly=True),
              'filedata': fields.binary('Texto',filters='*.xml'),
    _defaults = {
            'filedata': get_filedata_transporte,
            'name': get_name_transporte

My .xml

<record id="saft_export_transporte" model="ir.ui.view">
            <field name="name">Saft Export Transporte</field>
            <field name="model">saft.export.transporte</field>
            <field name="arch" type="xml">
                <form string="Saft Export Transporte" version="7.0">
                    <group col="1">
                    <separator string="Concluido"/>
                    <field name="name" invisible="1"/>
                    <label string="Guarde o ficheiro resumido saft"/>
                    <field name="filedata" nolabel="1" readonly="1" filename="name"/>
                        <button string="Fechar" class="oe_link" special="cancel"/>

        <record id="saft_export_action" model="ir.actions.act_window">
            <field name="name">saft.export</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">saft.export.transporte</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="target">new</field>




Can you help me?

Clément THOMAS
On 8/21/14, 4:15 AM

An example with contract_file and contract_file_name (file name depends on code of contracts throw a function for this example).

in python class :

_columns = {

'contract_file':fields.binary("Contract file (PDF)"),

'contract_file_name': fields.function(_get_contract_file_name, type="char", size=255, readonly=True, method=True),


contract_file_name can be a simple char field


in xml : 

<field name="contract_file" filename="contract_file_name"/> 
<field name="contract_file_name" invisible="1"/>

don't set invisible="1" if you want a field to set explicitly the file name



| 5 2 8
Ahmadabad, India
On 5/15/14, 11:46 PM


Refer the following link for filename. It may help you. 

Francisco Castro
On 5/16/14, 12:29 PM

it raises an error your solution

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)


Asked: 5/15/14, 11:03 AM
Seen: 6721 times
Last updated: 1/4/16, 11:19 PM