콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
7392 화면

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!!!

아바타
취소
베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
1
5월 25
1184
3
6월 23
5277
0
4월 23
91
6
1월 23
17080
2
12월 22
4978