Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
3014 Tampilan

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.

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Feb 25
1201
1
Nov 24
2045
0
Okt 23
40
4
Agu 16
6472
0
Mar 15
4022