You can create the xlsx file dynamically and connect via email.
from cStringIO import StringIO import base64 workbook = xlsxwriter.Workbook('demo.xlsx') worksheet = workbook.add_worksheet() worksheet.set_column('A:A', 20) bold = workbook.add_format({'bold': True}) worksheet.write('A1', 'Hello') worksheet.write('A2', 'World', bold) worksheet.write(2, 0, 123) worksheet.write(3, 0, 123.456) fp = StringIO() workbook.save(fp) fp.seek(0) datas = base64.encodestring(fp.read()) file_name = "name_%s" %(time.strftime('%Y%m%d%H%M%S.xlsx')) attachment=[] attachment_data = { 'name':file_name, 'datas_fname':file_name, 'datas':datas, 'res_model':"modelname", } attachment.append(self.env['ir.attachment'].create(attachment_data).id) mail_obj=self.env['mail.mail'] mail_template=self.env.ref('mail_template_id') msg_ids=mail_template.send_mail(id of object) msgs=mail_obj.browse(msg_ids) msgs.write({'attachment_ids': [(6, 0, attachment)]})
In the above code, we create one worksheet entry and then create an attachment entry.
You need to specify the name, datas_fname, datas, res_model to create the mount. You can also give res_id to create an attachment, after which the system will automatically see the visible attachment inside this model and record.
After creating the attachment, you can use it dynamically in the letter.
It might help you.
Emipro Technologies Pvt. Ltd.
source share