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.

2

Upload files to OpenERP through custom module

By
Joaquin
on 5/15/13, 1:41 PM 10,406 views

Hello. I need to know how to make a file upload to the server OpenERP. I'm creating a module which has to allow me to do an upload of a file to the server, then do a treatment for their content. I have done the treatment but n ose content as I can make a system call OpenERP to Upload File.

Please elaborate. Do you mean uploading some sort of python script or csv? Not sure where you're trying to go with this, there's already importing, file attachments, etc.

Brett Lehrer
on 5/15/13, 2:19 PM

Hi Brett.What I want is to upload a file, it can be a txt, csv or xls from a custom module, and that module should read the contents of that file and processing it, analyzing those contents and insert those contained in the custom tables.

Joaquin
on 5/15/13, 2:23 PM
4

Borni DHIFI

--Borni DHIFI--
5102
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 5/15/13, 2:24 PM

Hi,

you can use fields.binary. you can save your file in database.

in your file.py

 'data': fields.binary('File'),

in your file.xml:

<field name="data" />
 and 
<button name="import_file" string="Import" type="object"  class="oe_highlight" />

if you clik in button Import it call function import_file

in your function :

create a temp file for treatment content data.

 def import_file(self, cr, uid, ids, context=None):
    fileobj = TemporaryFile('w+')
    fileobj.write(base64.decodestring(data)) 

    # your treatment
    return

Thanks.

I need a button on my form that allows me to look at the client workstation, the file you want to upload to the server, and already once uploaded to launch the program evaluate the content of the file. After parsing the file's contents, if correct, shall be recorded in the custom tables, but never before.

Joaquin
on 5/15/13, 2:27 PM

yes retrieve contents of file to download to a temporary file then do tests on this file if correct save this object in your database else display a warning for example.

Borni DHIFI
on 5/15/13, 2:36 PM

That is: in my custom program (my. py file), I introduce the sentence: 'data': fields.binary ('File') Along with the content of the file. Xml, this creates a button on the form. Is it right? Once this is when my role would create the temporary file, and then proceed to treatment. Is it right?

Joaquin
on 5/15/13, 2:44 PM

I edit my answer .it is now clear?

Borni DHIFI
on 5/15/13, 3:10 PM

Sorry, but my English is not very fluid, so I asked confirmation, would not bother or offend. I apologize. Now if I understood your answer. The try tomorrow. Thank you. Best regards from Spain.

Joaquin
on 5/15/13, 4:51 PM

In your function you try to write data to a temporary file, but data is not defined in this function. How you get data?

Stefan Reisich
on 1/30/14, 10:32 AM

@Joaquin i want to import sale order line from import button like i want add sale order line three(3) way 1-> add sale order line as current working oi's ok 2-> add sale oder line from my CSV/Excel file when i click on import button in sale order form view 3-> add sale order line both like 1, 2 how it is possible ?

sarkar
on 1/10/16, 11:51 PM
1
Evans Bernier
On 8/13/15, 4:44 PM

Hi,

How can we do this without storing the file in the database? I would like to store the file in filepath on server.

Thanks

You can use ir.attachment with the filestore

Jérémy Kersten (jke)
on 8/13/15, 5:13 PM
0
Edy Kendengis
On 8/14/15, 1:41 AM

Storing field data to filestore (file store on folder data/filestore)

images= fields.Many2one(comodel_name="ir.attachment", string="Images")

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

3 follower(s)

Stats

Asked: 5/15/13, 1:41 PM
Seen: 10406 times
Last updated: 1/10/16, 9:16 PM