微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 encodeString 生成 .xsl 文件

如何解决从 encodeString 生成 .xsl 文件

我有一个编码字符串 (excel_file),我想从这个字符串生成一个 xsl 文件

是否可以生成仅在我的 .py 文件添加代码而不将该文件保存在本地的 .xsl 文件,因为我想将此文件附加到邮件中。

att_id = self.env['ir.attachment'].create({

                    'name': 'My name','type': 'binary','datas':excel_file,'datas_fname': 'Myname.xsl','res_model': 'print.invoice.cron','res_id': self.id,'mimetype': 'text/csv'

                    })


                tools.email_send(email_from='sending@test.fr',email_to=['recive@gmail.com'],subject='Some subject',body=att_id)

我正在接收附件的 id,而不是文件。并且没有 email_send() 的 attache 属性

解决方法

所以这是我的建议:

att_id = self.env['ir.attachment'].create({

                    'name': 'My name','type': 'binary','datas':excel_file,'datas_fname': 'Myname.xsl','res_model': 'print.invoice.cron','res_id': self.id,'mimetype': 'text/csv'

                    })
template = self.env.ref(
                        'module_name.email_template',False)
ctx = dict(
                            default_model=self._name,default_res_id=self.id,default_use_template=bool(template),default_template_id=template.id,default_composition_mode='comment',default_email_to=email,default_lang=self.env.user.partner_id.lang,default_attachment_ids=[(6,att_id.ids)],)
self.env['mail.template'].browse(template.id).with_context(
                            ctx).send_mail(self.id,force_send=True)

模板创建代码:

    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
        <data noupdate="1">
            <record id="email_template" model="mail.template">
                <field name="name">Template Name</field>
                <field name="model_id" ref="module_name.model_your_model"/>
                <field name="email_to">${ctx.get('default_email_to')}</field>
                <field name="subject">Subject</field>
                <field name="body_html" type="html">
    <div style="margin: 0px; padding: 0px;">
        <p style="margin: 0px; padding: 0px; font-size: 13px;">
Email body
</p>
        Thanks
    </div>
                </field>
                <field name="lang">${ctx.get('default_lang')}</field>
                <field name="user_signature" eval="True"/>
                <field name="auto_delete" eval="True"/>
            </record>

        </data>
    </odoo>

请检查并告诉我它是否有效。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。