Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6526 Lượt xem

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.

 

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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!


Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất

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

   

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 22
3671
1
thg 8 21
6224
1
thg 2 25
1003
1
thg 5 23
4061
0
thg 12 22
4525