Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
22100 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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.

Nejlepší odpověď

Try this:

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

Avatar
Zrušit
Autor

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?

Related Posts Odpovědi Zobrazení Aktivita
1
bře 22
5544
1
lis 19
5140
0
čvc 15
3818
2
čvn 20
11402
2
lis 18
6090