Ir al contenido
Menú
Se marcó esta pregunta
3846 Vistas

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,

})

]})

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
feb 23
5340
0
mar 22
1308
3
jun 23
12313
0
mar 22
1889
0
jun 20
5399