Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
7294 Zobrazení

Hi,

I am working on the Attendance module and I want to automatically send an email to the employees at the end of the day who forgets to logout keeping HR in CC odoo12.

Could anyone help me to achieve this?

Thank you in advance!!!

Avatar
Zrušit
Nejlepší odpověď

Hi,

For this you can use the cron job/scheduled action which runs at the end of every day, and inside the corresponding function you can check whether the employee is logged out or not, if not you can send email notification from there. 

For creating a scheduled action, see this sample:

<record forcecreate="True" id="ir_cron_scheduler_alarm" model="ir.cron">
<field name="name">Calendar: Event Reminder</field>
<field name="model_id" ref="model_calendar_alarm_manager"/>
<field name="state">code</field>
<field name="code">model.get_next_mail()</field>
<field eval="False" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">30</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
</record>

Once cron job is created the function will be triggered in the given time interval, then from the function you can easily send the email notification as per the need.

See: How To Create Scheduled Actions in Odoo

For sending Email from python using Email template, see this sample code,

@api.one
def send_forum_validation_email(self, forum_id=None):
if not self.email:
return False
token = self._generate_forum_token(self.id, self.email)
activation_template = self.env.ref('website_forum.validation_email')
if activation_template:
params = {
'token': token,
'id': self.id,
'email': self.email}
if forum_id:
params['forum_id'] = forum_id
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
token_url = base_url + '/forum/validate_email?%s' % urls.url_encode(params)
with self._cr.savepoint():
activation_template.sudo().with_context(token_url=token_url).send_mail(
self.id, force_send=True, raise_exception=True)
return True


Also you can check whether the automated actions can help in this case. If you activate the debug mode, navigate to settings -> technical, here there is a menu named Automated action, have a look at it too.

Email Template: How To Create Email Template

Send Email from code: Send Email From Code Using Email Template

Thanks

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
kvě 25
1076
3
čvn 23
5123
0
dub 23
91
6
led 23
16904
2
pro 22
4847