Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
2978 Vizualizări

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
feb. 25
1185
1
nov. 24
2023
0
oct. 23
40
4
aug. 16
6465
0
mar. 15
4018