Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
6460 Visualizações

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.

 

Avatar
Cancelar
Autor Melhor resposta

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!


Avatar
Cancelar

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.

Melhor resposta

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

   

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
nov. 22
3603
1
ago. 21
6159
1
fev. 25
956
1
mai. 23
4002
0
dez. 22
4472