跳至内容
菜单
此问题已终结
2 回复
6447 查看

Hello,

I am trying to generate a xlsx report using scheduled actions.

The report saves all sale orders confirmed in a week in a xlsx file.

The report could be generated using print button but not from scheduled action.

Can someone help? 

I have written a method as follows - 

class 

def generate_report(self):

            ret =  self.env['report'].get_action(self, 'so_xlsx')

I have defined the action in xml file.

Thanks in advance!


I could run other simple functions from scheduled action like printing in a logfile.

 

形象
丢弃
编写者 最佳答案

Hello Jainesh,

Thank you for your answer. Could you tell me -

1. What is the type of xlsx_report ? ie. What should be returned by  extract_spreadsheet() ?

2.   What exactly happens in following statment ? What is 6 ?
email_template.attachment_ids = [(6, 0, attachment_id.ids)]

Thanks once again!


形象
丢弃

Hello Rainier,

This xlsx_report type is .xlsx and the extract_spreadsheet is the function where you can write your report logic(i.e sales order which is confirmed).

Regarding this statement - email_template.attachment_ids = [(6, 0, attachment_id.ids)], You are able to send email with attachment(your xlsx report) and [(6, 0, ids)] is used for appending attachments in email.

最佳答案

Hello Rainier,


For sending an xlsx report using scheduled actions you need to follow listed things,


extract_spreadsheet - this is your function where you are creating xlsx report with your logic.


def _cron_send_xlsx(self):

xlsx_report = self.env['object.object'].extract_spreadsheet()

attachment = xlsx_report.get('attachment_id')

attachment_id = self.env['ir.attachment'].browse(attachment)

    email_template = self.env.ref('module_name.email_template')

    email_template.attachment_ids = [(6, 0, attachment_id.ids)]

    email_template.write({'email_from': your_email_from, 

                          'email_to': your_email_to,

    email_template.with_context(ctx).send_mail(

        self.id, raise_exception=False, force_send=True)



Using this way you can send an email with Xlsx report.

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

形象
丢弃
相关帖文 回复 查看 活动
1
11月 22
3588
1
8月 21
6155
1
2月 25
950
1
5月 23
3990
0
12月 22
4463