跳至內容
選單
此問題已被標幟
1 回覆
2976 瀏覽次數

Hi,

I want to send notifications to the employees whose passport and ID expiry dates are near.

Send an email to notify them about the renewal. 

notify the employees one month before the expiry dates.

Can someone please help me create this in the odoo 17 custom module.

頭像
捨棄
最佳答案

Hi,

To create a custom module in Odoo 17 for notifying employees about passport and ID expiry dates, you can follow these steps:


Inherit hr.employee to add necessary fields and functions:

class HrEmployee(models.Model):

    _inherit = 'hr.employee'


    passport_expiry_date = fields.Date(string='Passport Expiry Date')

    id_expiry_date = fields.Date(string='ID Expiry Date')


    @api.model

    def notify_passport_expiry(self):

        today = fields.Date.today()

        one_month_later = today + timedelta(days=30)

        employees_to_notify = self.search([

            ('passport_expiry_date', '=', one_month_later)

        ])


        for employee in employees_to_notify:

            template = self.env.ref('your_module.email_template_passport_expiry')

            template.send_mail(employee.id, force_send=True)

Scheduled action corresponding to this:

    <record id="ir_cron_employee_email" model="ir.cron">
        <field name="name">Passport Expiry</field>
        <field name="model_id" ref="model_hr_employee"/>
        <field name="state">code</field>
<field name="code">model.notify_passport_expiry()</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
        <field name="numbercall">-1</field>
    </record>

Also create an email template:

<record id="email_template_passport_expiry" model="mail.template">

        <field name="name">Passport Expiry Notification</field>

        <field name="model_id" ref="hr.model_hr_employee"/>

        <field name="email_from">${user.email|safe}</field>

        <field name="subject">Passport Expiry Notification</field>

        <field name="body_html">

            <![CDATA[

            <p>Hello ${object.name},</p>

            <p>Your passport is expiring on ${object.passport_expiry_date}. Please renew it soon.</p>

            ]]>

        </field>

        <field name="auto_delete" eval="True"/>

    </record>


Hope it helps

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
2月 25
1184
1
11月 24
2021
0
10月 23
40
4
8月 16
6465
0
3月 15
4017