如何在Odoo中实现此功能?

时间:2015-08-27 10:16:18

标签: odoo odoo-8 thunderbird openerp-8

我一直在尝试发送邮件,只要在请假申请中有请假/批准/拒绝,并且我一直按照以下链接中的步骤进行 - https://www.odoo.com/forum/help-1/question/openerp-7-sending-email-to-manager-when-employee-applies-a-leave-7362

通过执行上述步骤,消息确实出现在Odoo收件箱中,但我无法将邮件发送到邮件客户端,如thunderbird

任何人都可以发表意见吗?

1 个答案:

答案 0 :(得分:1)

这是您想要的代码,

请假申请代码:

def create(self, cr, uid, values, context=None):

        res = super(hr_holidays, self).create(cr, uid, values, context=context)

        template = self.pool.get('ir.model.data').get_object(cr, uid, 'hr_holidays_aspire', 'leave_request')
        mail_id = self.pool.get('email.template').send_mail(cr, uid, template.id, res , force_send=True)

        return res

休假批准代码:

def holidays_validate(self, cr, uid, ids, context=None):

        compose_ctx = dict(context,active_ids=ids)
        search_domain = [('name', '=', 'Leave Approved')]
        template_id = self.pool['email.template'].search(cr, uid, search_domain, context=context)[0]

        compose_id = self.pool['mail.compose.message'].create(
            cr, uid, {
                'model': self._name,
                'composition_mode': 'mass_mail',
                'template_id': template_id,
                'post': True,
                'notify': True,
            }, context=compose_ctx)
        self.pool['mail.compose.message'].write(
            cr, uid, [compose_id],
            self.pool['mail.compose.message'].onchange_template_id(
                cr, uid, [compose_id],
                template_id, 'mass_mail', self._name, False,
                context=compose_ctx)['value'],
            context=compose_ctx)
        self.pool['mail.compose.message'].send_mail(cr, uid, [compose_id], context=compose_ctx)

        return True

请假拒绝代码:

def holidays_refuse(self, cr, uid, ids, context=None):
        compose_ctx = dict(context,active_ids=ids)
        search_domain = [('name', '=', 'Leave Refused')]
        template_id = self.pool['email.template'].search(cr, uid, search_domain, context=context)[0]

        compose_id = self.pool['mail.compose.message'].create(
            cr, uid, {
                'model': self._name,
                'composition_mode': 'mass_mail',
                'template_id': template_id,
                'post': True,
                'notify': True,
            }, context=compose_ctx)
        self.pool['mail.compose.message'].write(
            cr, uid, [compose_id],
            self.pool['mail.compose.message'].onchange_template_id(
                cr, uid, [compose_id],
                template_id, 'mass_mail', self._name, False,
                context=compose_ctx)['value'],
            context=compose_ctx)
        self.pool['mail.compose.message'].send_mail(cr, uid, [compose_id], context=compose_ctx)
        return super(hr_holidays, self).holidays_refuse(cr, uid, ids, context=context)

以下是Leave请求,批准和拒绝的三种不同模板。

        <!-- Templates for requesting leave -->
        <record id="leave_request" model="email.template">
            <field name="name">Leave Request</field>
            <field name="subject">Leave Application from ${object.employee_id.name} [${object.employee_id.employee_no}].</field>
            <field name="email_from">${object.employee_id.work_email}</field>
            <field name="email_to">${object.employee_id.parent_id.work_email}</field>
            <field name="model_id" ref="model_hr_holidays"/>
            <field name="user_signature" eval="0"/>
            <field name="body_html"><![CDATA[<p>Hi,</p>
            <p> ${object.employee_id.name} [${object.employee_id.employee_no}] has applied for a leave application.</p><br/>
            <p>Following are the applied leave details: </p>
            <p>Leave type: ${object.holiday_status_id.name}</p> 
            <p>From Date:  ${object.date_from}</p> 
            <p>To Date: ${object.date_to}</p> 
            <p>Number of days: ${object.number_of_days_temp}</p> 
            <p>Reason: ${object.name}</p> 
            <p>From Session: ${object.from_session}</p>
            <p>To Session: ${object.to_session}</p>
            <br/><br/>
            <p>Regards, ${object.employee_id.name}</p>
            ]]></field>
        </record>

        <!-- Templates for approving leave -->
        <record id="leave_approve" model="email.template">
            <field name="name">Leave Approved</field>
            <field name="subject">Your Leave Application has been Accepted.</field>
            <field name="email_from">${object.employee_id.parent_id.work_email}</field>
            <field name="email_to">${object.employee_id.work_email}</field>
            <field name="model_id" ref="model_hr_holidays"/>
            <field name="user_signature" eval="0"/>
            <field name="body_html"><![CDATA[<p>Hi ${object.employee_id.name} [${object.employee_id.employee_no}], </p>
            <p>Your leave application has been accepted.</p><br/>
            <p>Leave type: ${object.holiday_status_id.name}</p> 
            <p>From Date:  ${object.date_from}</p> 
            <p>To Date: ${object.date_to}</p> 
            <p>Number of days: ${object.number_of_days_temp}</p> 
            <p>Reason: ${object.name}</p> 
            <p>From Session: ${object.from_session}</p>
            <p>To Session: ${object.to_session}</p>
            <br/><br/>
            <p>Regards, ${object.employee_id.parent_id.name}</p>
            ]]></field>
        </record>

        <!-- Templates for refusing leave -->
        <record id="leave_refuse" model="email.template">
            <field name="name">Leave Refused</field>
            <field name="subject">Your Leave Application has been Refused.</field>
            <field name="email_from">${object.employee_id.parent_id.work_email}</field>
            <field name="email_to">${object.employee_id.work_email}</field>
            <field name="model_id" ref="model_hr_holidays"/>
            <field name="user_signature" eval="0"/>
           <field name="body_html"><![CDATA[<p>Hi ${object.employee_id.name} [${object.employee_id.employee_no}], </p>
            <p>Your leave application has been refused.</p><br/>
            <p>Leave type: ${object.holiday_status_id.name}</p> 
            <p>From Date:  ${object.date_from}</p> 
            <p>To Date: ${object.date_to}</p> 
            <p>Number of days: ${object.number_of_days_temp}</p> 
            <p>Reason: ${object.name}</p> 
            <p>From Session: ${object.from_session}</p>
            <p>To Session: ${object.to_session}</p>
            <br/><br/>
            <p>Regards, ${object.employee_id.parent_id.name}</p>
            ]]></field>
        </record>

干杯!!!