Odoo Help

3

2
12 Answers
3
Alexander Moldavia
6/7/13, 6:13 AM

Hi, try to use something like this:

py file:

_columns = {
    'vcard_stream': fields.binary('File Stream', readonly=True),
    'vcard_name': fields.char('File name', 40, readonly=True),
}

_defaults = {
    'vcard_name': 'your_filname.vcard',
}

xml file:

<field name="vcard_stream" string="File Stream" filename="vcard_name"/>
4 Comments
Prakash India
12/10/13, 3:38 AM

Hi Alexandar, I followed the same steps in my custom module but download file name always shows Model name used in the xml File For example Download file name shows "model_name" <field name="model">model.name</field> Not downloaded with defined _defaults file name. Any idea? How to fix this issue. Thanks

Alexander Moldavia
12/10/13, 3:56 AM

Hi. Can you show your source code? Perhaps you missed something.

Prakash India
12/10/13, 4:51 AM

Updated the source code

Abhishek H Menon India
7/1/16, 10:30 AM

I have also done the same thing above, but I did not get the result. The name is shown as a pdf extension but, it is downloaded/opened as binary file which has no extension. How we can embedd the extension along with the file generation?

2
Sarender Reddy India
12/18/17, 8:55 AM

Use like below in xml file.

as per Odoo11 


<field widget="binary" name="datas" filename="datas_fname"/>

                  <field name="datas_fname" readonly = "1" invisible="1"  force_save="1"/>


Get the uploaded file in py file.


curr_obj = self  

        if not curr_obj.datas:

            raise UserError(_('Please Choose The File!'))

        file_name = curr_obj.datas_fname

        print "curr_obj.datas_fname here",curr_obj.datas_fname

        print "file namr here",file_name

        fname = str(file_name.split('.')[1])

        if fname != 'xls':

            raise UserError(_('Please Choose The File With .xls extension and proper format!'))

        try:

            val=base64.decodestring(curr_obj.datas)

            fp = StringIO.StringIO()

            fp.write(val)     

            wb = xlrd.open_workbook(file_contents=fp.getvalue())

            wb.sheet_names()

            sheet_name=wb.sheet_names()

            sh = wb.sheet_by_index(0)

            sh = wb.sheet_by_name(sheet_name[0])

            n_rows = sh.nrows

0
Aurelien United States
5/14/15, 2:25 AM

Hi Vitaly!

The answer posted by Prakash should work fine, i would just change this part 

<group>

<field name="edi_filename"/>

<field name="edi_data" filename="edi_filename"/>

</group>

to  

<group>

<field name="edi_filename" invisible='1'/>

<field name="edi_data" filename="edi_filename"/>

</group>


Because filename already shows up following Download in your view and as this is "readonly" you do really need to display it two times.

But with the code you're showing above i am not sure if the previous answers reached your expectation.

I advise you to go to have a look on the ir.attachment model in the Base module of odoo. You will find all the answer you want to find there.

However, you will indeed need a field filename in order to have a name (plus an extension?) to your downloaded file. 

0
Avatar

Prakash India

--Prakash--

11631
| 6 7 9
Bikaner, India
--Prakash--

OpenERP Developer at SunARC Technology

Prakash India
12/10/13, 4:50 AM

In Wizard using the below code

Python File

_columns = {
        'edi_data': fields.binary('File Stream', readonly=True),
        'edi_filename': fields.char('File Name', size=32, readonly=True),
        }



_defaults = {
   'edi_filename': 'Invoice.txt',
 }

XML File

<field name="arch" type="xml">
            <form string="Form">
                <group>
                    <field name="edi_filename"/>
                    <field name="edi_data" filename="edi_filename"/>
             </group>
4 Comments
Alexander Moldavia
12/10/13, 5:32 AM

As far as I know "name" is something like function word. Try to rename fields. Also _defaults = { 'name': 'Invoice.txt', } should be in py file.

Alexander Moldavia
12/10/13, 9:35 AM

I don't know. My example works. Try to use it without any changes first. Maybe _stream and _name are "magic" words.

Prakash India
1/23/14, 8:09 AM

Can you please post your web\controllers\main.py File saveas_ajax Method code i think in my case issues in that file. I am using latest version 7 but still issues. Thanks

Abhishek H Menon India
7/1/16, 10:32 AM

In my case, it is a wizard which has a readonly binary field for storing file, and I am getting the file, but when I suppose to download it, it is getting downloaded as a binary file which has no specific extension. I need the file in pdf. Can anyone please suggest a way to do that?

Ask a Question
Writer
Tags
Keep Informed
0 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now