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.

0

How to get Bytea field contents with python code

By
Javier
on 2/17/16, 12:19 AM 312 views

Hello

I created a model with field named 'data_xml' which is a Many2many field to ir.attachment model and I have been able to insert an encoded XML file in ir.attachment by using the code shown below and everything works perfect (i.e the file can be opened in the user interface by clicking on the corresponding file inside the 'data_xml' field). Now, I need to open files uploaded that way in order to process them with python code, however I am experiencing trouble when trying to restore contents of db_datas field (I undestand it is difficult to get the contents since it is a Bytea field).

I tried suggestions in

https://www.odoo.com/es_ES/forum/help-1/question/solved-convert-picture-bytea-to-binary-in-a-python-file-30561, however I haven't been able get the XML content inside the field. Can any body provide suggestions on how I should proceed to be able to restore the XML content?

Thanks in advance for your help.

------------------------------------------------------------

xml_binary = base64.b64encode(xml_FILE)

recordnumber = self.number

ir_att_date_time=fields.Datetime.now()

ir_att_name_file=recordnumber.replace("/","-")

ir_att_name_file='FILE-XML ' + ir_att_name_file + '.xml'

ir_att_datas_fname = ir_att_name_file

ir_att_res_model = 'office.model'

ir_att_res_name=record.number + ' ...'

ir_att_mimetype='application/xml'

ir_att_Index_content = '(u\'application\',)'

ir_att_file_size = 1000

self.update({'data_xml':[(0,0,{'name': ir_att_name_file,

'type': 'binary',

'res_model': ir_att_res_model,

'datas_fname': ir_att_datas_fname,

'res_name': ir_att_res_name,

'mimetype': ir_att_mimetype,

'index_content': ir_att_Index_content,

'company_id': self.company_id,

'create_date': ir_att_date_time,

'write_date': ir_att_date_time,

'db_datas': xml_binary,

'write_uid': self.env.uid,

'create_uid': self.env.uid,

'public': False,

'file_size': ir_att_file_size,

})

]})

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)

Stats

Asked: 2/17/16, 12:19 AM
Seen: 312 times
Last updated: 2/17/16, 12:31 AM