コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
2968 ビュー

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
1177
1
11月 24
2009
0
10月 23
40
4
8月 16
6456
0
3月 15
4014