Skip to content

Commit

Permalink
Merge 1504247 into a0e2f0c
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Mar 6, 2020
2 parents a0e2f0c + 1504247 commit 6e8ae66
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 0 deletions.
38 changes: 38 additions & 0 deletions hr_employee_birthday_list_reminder/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===============================
Employee Birthday List Reminder
===============================


Installation
============

To install this module, you need to:

1. Clone the branch 8.0 of the repository https://github.com/open-synergy/opnsynid-hr
2. Add the path to this repository in your configuration (addons-path)
3. Update the module list
4. Go to menu *Setting -> Modules -> Local Modules*
5. Search For *Employee Birthday List Reminder*
6. Install the module

Credits
=======

Contributors
------------

* Michael Viriyananda <viriyananda.michael@gmail.com>
* Andhitia Rama <andhitia.r@gmail.com>

Maintainer
----------

.. image:: https://opensynergy-indonesia.com/logo.png
:alt: OpenSynergy Indonesia
:target: https://opensynergy-indonesia.com

This module is maintained by the OpenSynergy Indonesia.
7 changes: 7 additions & 0 deletions hr_employee_birthday_list_reminder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2020 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
models,
)
27 changes: 27 additions & 0 deletions hr_employee_birthday_list_reminder/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Copyright 2020 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# pylint: disable=locally-disabled, manifest-required-author
{
"name": "Employee Birthday List Reminder",
"version": "8.0.1.0.0",
"category": "Human Resource",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": [
"mail",
"email_template",
"hr",
],
"data": [
"security/ir.model.access.csv",
"views/hr_birthday_list_reminder_views.xml",
],
"external_dependencies": {
"python": [
"pandas"
],
},
}
7 changes: 7 additions & 0 deletions hr_employee_birthday_list_reminder/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2020 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import(
hr_birthday_list_reminder,
)
223 changes: 223 additions & 0 deletions hr_employee_birthday_list_reminder/models/hr_birthday_list_reminder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# -*- coding: utf-8 -*-
# Copyright 2020 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields, api
from datetime import datetime
import logging
_logger = logging.getLogger(__name__)

try:
import pandas as pd
except (ImportError, IOError) as err:
_logger.debug(err)


class HrBirthdayListReminder(models.Model):
_name = "hr.birthday_list_reminder"
_inherit = [
"mail.thread",
]
_description = "Employee Birthday Reminder"

name = fields.Char(
string="Description",
required=True,
)
active = fields.Boolean(
string="Active",
default=True,
)
list_type = fields.Selection(
string="Type",
selection=[
("all", "All Employee"),
("manual", "Manual Selection"),
],
default="manual",
required=True,
)

@api.multi
def _compute_employee(self):
obj_hr_employee =\
self.env["hr.employee"]

for document in self:
employee_ids =\
obj_hr_employee.search(
document._prepare_employee_data())
document.employee_ids = employee_ids.ids

employee_ids = fields.Many2many(
string="Employee(s)",
comodel_name="hr.employee",
compute="_compute_employee",
store=False,
)
manual_employee_ids = fields.Many2many(
string="Employee(s)",
comodel_name="hr.employee",
relation="rel_birthday_reminder_2_manual_employee",
column1="reminder_id",
columnt2="employee_id",
)
date_start_offset = fields.Integer(
string="Date Start Offset",
required=True,
default=0,
)
date_start_offset_period = fields.Selection(
string="Date Start Offset Period",
selection=[
("day", "Day"),
("month", "Month"),
],
default="day",
required=True,
)
date_end_offset = fields.Integer(
string="Date End Offset",
required=True,
default=0,
)
date_end_offset_period = fields.Selection(
string="Date End Offset Period",
selection=[
("day", "Day"),
("month", "Month"),
],
default="day",
required=True,
)
cron_id = fields.Many2one(
string="Cron",
comodel_name="ir.cron",
readonly=True,
)
email_template_id = fields.Many2one(
string="Email Template",
comodel_name="email.template",
)
recipient_partner_ids = fields.Many2many(
string="Recipient(s)",
comodel_name="res.partner",
relation="rel_birthday_reminder_2_recipient",
column1="reminder_id",
column2="partner_id",
)
note = fields.Text(
string="Note",
)

@api.multi
def _compute_date_offset(self):
self.ensure_one()
date_start_offset =\
self.date_start_offset
date_end_offset =\
self.date_end_offset
date_start_offset_period =\
self.date_start_offset_period
date_end_offset_period =\
self.date_end_offset_period
dt_now = pd.to_datetime(datetime.now())
# Compute Date Start Offset
if date_start_offset_period == "day":
dt_start =\
dt_now + pd.DateOffset(
days=date_start_offset)
else:
dt_start =\
dt_now + pd.DateOffset(
months=date_start_offset)
# Compute Date End Offset
if date_end_offset_period == "day":
dt_end =\
dt_now + pd.DateOffset(
days=date_end_offset)
else:
dt_end =\
dt_now + pd.DateOffset(
months=date_end_offset)
# Convert offset from datetime to date
date_start_conv =\
datetime.strftime(dt_start, "%Y-%m-%d")
date_end_conv =\
datetime.strftime(dt_end, "%Y-%m-%d")
return date_start_conv, date_end_conv

@api.multi
def _prepare_employee_data(self):
self.ensure_one()
date_start_conv, date_end_conv =\
self._compute_date_offset()
if self.list_type == "all":
result = [
("birthday", ">=", date_start_conv),
("birthday", "<=", date_end_conv),
]
else:
result = [
("id", "in", self.manual_employee_ids.ids),
("birthday", ">=", date_start_conv),
("birthday", "<=", date_end_conv),
]
return result

@api.multi
def action_create_cron(self):
for document in self:
document._generate_cron()

@api.multi
def action_delete_cron(self):
for document in self:
document.cron_id.unlink()

@api.multi
def _generate_cron(self):
self.ensure_one()
data = self._prepare_cron_data()
obj_cron = self.env["ir.cron"]
cron = obj_cron.create(data)
self.write({"cron_id": cron.id})

@api.multi
def _prepare_cron_data(self):
self.ensure_one()
cron_name = "Employee Birthday Reminder: %s" % (
self.name)
return {
"name": cron_name,
"user_id": self.env.user.id,
"active": True,
"interval_number": 30,
"interval_type": "days",
"numberofcall": -1,
"doall": True,
"model": "hr.birthday_list_reminder",
"function": "cron_send_email",
"args": "(%s,)" % (self.id),
}

@api.model
def cron_send_email(self, reminder_id):
reminder = self.browse([reminder_id])[0]
reminder._send_email()

@api.multi
def _send_email(self):
self.ensure_one()
obj_template = self.env["email.template"]
obj_mail = self.env["mail.mail"]

if self.email_template_id and self.recipient_partner_ids:
template = self.email_template_id
# TODO: Use email.template send_mail method
email_dict = obj_template.generate_email(
template_id=template.id, res_id=self.id)
mail = obj_mail.create(email_dict)
mail.write(
{"recipient_ids": [(6, 0, self.recipient_partner_ids.ids)]})
mail.send()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
hr_birthday_list_reminder_employee,hr.birthday_list_reminder - user,model_hr_birthday_list_reminder,base.group_user,1,1,1,1
hr_birthday_list_reminder_all,hr.birthday_list_reminder - all,model_hr_birthday_list_reminder,,0,0,0,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6e8ae66

Please sign in to comment.