Odoo Help

0

0
1 Answer
0
Samo Arko
2019/04/29 7:35

It's possible, but you need to know what file you will be reading to know what libs to use. You'll need to decode it from base64 and probably save it into a StringIO.

You can make a method that you then execute on button click and it reads the file from field. 

from xlrd import open_workbook
import base64
import StringIO

class ExcelImport(models.TransientModel): _name = 'excell.import.wizard' excel_file_for_import = fields.Binary(string='File for upload') def import_data_form_file(self): try: inputx = StringIO.StringIO() inputx.write(base64.decodestring(self.excel_file_for_import)) book = open_workbook(file_contents=inputx.getvalue()) except TypeError as e: raise ValidationError(u'ERROR: {}'.format(e)) sheet = book.sheets()[0] for i in range(sheet.nrows): if i == 0: continue if i == 1: name = sheet.cell(i, 0).value vat = sheet.cell(i, 5).value



 

5 Comments
Mian Kamran
2019/05/14 5:40

It worked. Thanks brother that was a great help

Tabla d.o.o., Samo Arko
2019/05/14 7:25

No problem... when I wrote the answer I was programming this, so it was just copy&paste from my code.

Mian Kamran
2019/05/14 8:13

Great. Thanks for the help. Another question: is it possible that we can know the physical address of the file on computer, the file which is attached in the binary field. I want to read the file through pandas but it is not working on field name or something like that.

Tabla d.o.o., Samo Arko
2019/05/14 9:43

There's no physical location. The file is saved in the database. I never used pandas, but you probably need to get the file in binary and decode it from base64.

Mian Kamran
2019/05/15 2:00

OK. Great

Ask a Question
Writer
Keep Informed
1 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