Skip to content

Commit

Permalink
[8.0.1.0.0][hr_employee_birthday_list_reminder] Revisi
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Mar 8, 2020
1 parent 1504247 commit 684b00b
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def _compute_employee(self):
employee_ids =\
obj_hr_employee.search(
document._prepare_employee_data())
document.employee_ids = employee_ids.ids
employee_birthday_list =\
document._get_birthday_list(employee_ids)
document.employee_ids = employee_birthday_list

employee_ids = fields.Many2many(
string="Employee(s)",
Expand Down Expand Up @@ -150,21 +152,38 @@ def _compute_date_offset(self):
@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),
]
result = []
else:
result = [
("id", "in", self.manual_employee_ids.ids),
("birthday", ">=", date_start_conv),
("birthday", "<=", date_end_conv),
]
return result

@api.multi
def _get_birthday_list(self, employee_ids):
self.ensure_one()
employee_birtday_list = []

date_start_conv, date_end_conv =\
self._compute_date_offset()
current_year =\
datetime.now().year

for employee in employee_ids:
if employee.birthday:
birthday = employee.birthday
date = datetime.strptime(birthday, '%Y-%m-%d')
conv_birtday = date.replace(year=current_year)
str_birthday =\
datetime.strftime(conv_birtday, "%Y-%m-%d")
if (
str_birthday >= date_start_conv and
str_birthday <= date_end_conv
):
employee_birtday_list.append(employee.id)
return employee_birtday_list

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

0 comments on commit 684b00b

Please sign in to comment.