I'm trying to create a XML file and add it as a attachment to the record. It generates the xml as a string and saves it into 'ir.attachment' but I don't know how to add it to the models record so I could download it from the custom modules form view.
@api.model
def attach_xml_file(self, docids):
import base64
xml_string = self.generate_xml()
file_name = 'myfile-1.xml'
attach_name = file_name
attach_id = self.env['ir.attachment'].create({'name': attach_name,
'datas': base64.encodestring(xml_string),
'datas_fname': file_name,
'res_model': 'this.model.name',
'res_id': docids[0]})
Do I have to inherit the ir.attchment in my custom model? How can I attach the file to the specific instance of the model? Is there a odoo base addon that does this and I could use it as example?