İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
21983 Görünümler

How can I access all the files from attachment_ids in my method parse_xml?

I want to process the files.


class XMLImporter(models.Model):

    _name = 'ia.xml.importer' 

    _description = 'Helper class to import xml files'

    attachment_ids = fields.Many2many('ir.attachment', 'class_ir_attachments_rel', 'class_id', 'attachment_id', 'Attachments')


@api.multi

def parse_xml(self):


 

Avatar
Vazgeç
En İyi Yanıt

Hope this helps you

attachment_ids = fields.Many2many('ir.attachment', 'class_ir_attachments_rel', 'class_id', 'attachment_id', 'Attachments')
@api.multi
def your_button_click(self):
for attachment in self.attachment_ids:
    decoded_data = base64.b64decode(attachment)
    # you logic goes here


Avatar
Vazgeç
Üretici

thanks for your post.

this works:

for xml_file in self.attachment_ids:

decoded_data = base64.b64decode(xml_file.datas)

root = ElementTree.fromstring(decoded_data)

Confirmed that you need to use the ".datas" property to access the actual file binary data.

En İyi Yanıt

Try this:

for att in self.attachment_ids:
    xml = att.datas.decode('base64')
    xml_filename = att.datas_fname

Avatar
Vazgeç
Üretici

thanks. I tried but does not work... LookupError: 'base64' is not a text encoding; use codecs.decode() to handle arbitrary codecs

for xml_file in self.attachment_ids:

deco_data = xml_file.datas.decode('base64')

tree = ElementTree.parse(deco_data)

root = tree.getroot()

do u know why?

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Mar 22
5493
1
Kas 19
5097
0
Tem 15
3759
2
Haz 20
11333
2
Kas 18
6050