Skip to Content
Menu
This question has been flagged
1 Odpoveď
2971 Zobrazenia

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
Zrušiť
Best Answer

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
Zrušiť
Related Posts Replies Zobrazenia Aktivita
0
feb 25
1177
1
nov 24
2010
0
okt 23
40
4
aug 16
6460
0
mar 15
4014