Skip to content

Instantly share code, notes, and snippets.

@ovnicraft
Created August 4, 2020 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovnicraft/f0e50ab6e0c5548c71886b3f1398ed49 to your computer and use it in GitHub Desktop.
Save ovnicraft/f0e50ab6e0c5548c71886b3f1398ed49 to your computer and use it in GitHub Desktop.
@api.one
def add_attachment(self, content):
"""
TODO
"""
buf = StringIO() # from io import StringIO
buf.write(content)
document = base64.encodebytes(buf.getvalue().encode())
buf.close()
attach = self.env["ir.attachment"].create(
{
"name": "nombre.zip",
"datas": document,
"datas_fname": "nombre.zip",
# "res_model": self._name,
# "res_id": self.id,
"type": "binary",
}
)
return attach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment