Skip to Content
Menu
This question has been flagged
1 Reply
1317 Views

I like to create a small automated action with this code:


attachment = env['ir.attachment'].search_read([['res_id', '=', record.id]])
pdf = attachment[0].get("datas")
file = open("/odoo/sample.pdf", "wb")
file.write(pdf)
file.close()


but i get the error "open is not defined". Why could i not use the build-in open() function?

Avatar
Discard
Best Answer

Only the following libraries are available in Automated Actions:

  • datetime

  • time

  • timezone

  • dateutil

  • math

open is a built-in Python function, but not one that can be used in the automation framework.  

To use it you need to build your own module and use it inside a public model method that you can then call with the automation framework.

Avatar
Discard