From e5221d6a9616aac00ab9383b5958423bcd322ac1 Mon Sep 17 00:00:00 2001
From: Alexis de Lattre
Date: Tue, 6 Jun 2017 16:27:44 +0200
Subject: [PATCH] hr_holidays_usability: add support for emails
Many small fixes and improvements
---
hr_holidays_usability/hr_holidays.py | 40 +++++++++++++++----
hr_holidays_usability/hr_holidays_mail.xml | 10 ++---
hr_holidays_usability/hr_holidays_view.xml | 4 +-
.../report/hr_holidays_employee_counter.py | 7 ++--
.../security/holiday_security.xml | 8 +++-
.../wizard/hr_holidays_mass_allocation.py | 6 +--
.../wizard/hr_holidays_post_view.xml | 2 +-
7 files changed, 56 insertions(+), 21 deletions(-)
diff --git a/hr_holidays_usability/hr_holidays.py b/hr_holidays_usability/hr_holidays.py
index 13e9f6f..21d983f 100644
--- a/hr_holidays_usability/hr_holidays.py
+++ b/hr_holidays_usability/hr_holidays.py
@@ -34,7 +34,7 @@ class HrEmployee(models.Model):
_inherit = 'hr.employee'
holiday_exclude_mass_allocation = fields.Boolean(
- string='Exclude from Mass Holiday Attribution')
+ string='Exclude from Mass Holiday Allocation')
class HrHolidays(models.Model):
@@ -73,7 +73,7 @@ class HrHolidays(models.Model):
# 1 or 2 for normal holidays
@api.model
- def _compute_number_of_days(self):
+ def _usability_compute_number_of_days(self):
# depend on the holiday_status_id
hhpo = self.env['hr.holidays.public']
days = 0.0
@@ -218,6 +218,11 @@ class HrHolidays(models.Model):
string='Public Title',
help="Warning: this title is shown publicly in the "
"calendar. Don't write private/personnal information in this field.")
+ # by default, there is no company_id field on hr.holidays !
+ company_id = fields.Many2one(
+ related='employee_id.resource_id.company_id', store=True,
+ readonly=True)
+ state = fields.Selection(default='draft') # hr_holidays, default='confirm'
@api.constrains(
'vacation_date_from', 'vacation_date_to', 'holiday_type', 'type')
@@ -307,16 +312,14 @@ class HrHolidays(models.Model):
'holiday_status_id')
def leave_number_of_days_change(self):
if self.type == 'remove':
- days = self._compute_number_of_days()
+ days = self._usability_compute_number_of_days()
self.number_of_days_temp = days
# Neutralize the native on_change on dates
def _onchange_date_from(self):
- print "_onchange_date_from self=", self
return {}
def _onchange_date_to(self):
- print "xxxxxxxxxxxxxxx _onchange_date_to self=", self
return {}
# I want to set number_of_days_temp as readonly in the view of leaves
@@ -326,7 +329,7 @@ class HrHolidays(models.Model):
def create(self, vals):
obj = super(HrHolidays, self).create(vals)
if obj.type == 'remove':
- days = obj._compute_number_of_days()
+ days = obj._usability_compute_number_of_days()
obj.number_of_days_temp = days
return obj
@@ -335,11 +338,22 @@ class HrHolidays(models.Model):
res = super(HrHolidays, self).write(vals)
for obj in self:
if obj.type == 'remove':
- days = obj._compute_number_of_days()
+ days = obj._usability_compute_number_of_days()
if days != obj.number_of_days_temp:
obj.number_of_days_temp = days
return res
+ @api.multi
+ def action_confirm(self):
+ for holi in self:
+ if not self._context.get('no_email_notification'):
+ template = self.env.ref(
+ 'hr_holidays_usability.email_template_hr_holidays')
+ template.with_context(
+ dbname=self._cr.dbname,
+ new_holiday_state='submitted').send_mail(holi.id)
+ return super(HrHolidays, self).action_confirm()
+
@api.multi
def action_validate(self):
for holi in self:
@@ -364,6 +378,12 @@ class HrHolidays(models.Model):
"Allocation request '%s' has a leave type '%s' that "
"can be approved only by an HR Manager.")
% (holi.name, holi.holiday_status_id.name))
+ if not self._context.get('no_email_notification'):
+ template = self.env.ref(
+ 'hr_holidays_usability.email_template_hr_holidays')
+ template.with_context(
+ dbname=self._cr.dbname,
+ new_holiday_state='validated').send_mail(holi.id)
return super(HrHolidays, self).action_validate()
@api.multi
@@ -377,6 +397,12 @@ class HrHolidays(models.Model):
"You cannot refuse your own Leave or Allocation "
"holiday request '%s'.")
% holi.name)
+ if not self._context.get('no_email_notification'):
+ template = self.env.ref(
+ 'hr_holidays_usability.email_template_hr_holidays')
+ template.with_context(
+ dbname=self._cr.dbname,
+ new_holiday_state='refused').send_mail(holi.id)
return super(HrHolidays, self).action_refuse()
diff --git a/hr_holidays_usability/hr_holidays_mail.xml b/hr_holidays_usability/hr_holidays_mail.xml
index 49f0b7f..4e48540 100644
--- a/hr_holidays_usability/hr_holidays_mail.xml
+++ b/hr_holidays_usability/hr_holidays_mail.xml
@@ -8,7 +8,7 @@
${object.employee_id.parent_id.user_id.email or ''}
${object.employee_id.user_id.email or ''}
${user.email or ''}
- ${ctx.get('dbname') and 'prod' not in ctx.get('dbname') and '[TEST]' or ''}[${object.type == 'remove' and 'Leave' or 'Allocation'} ${ctx.get('wkf_tracker')}] ${object.name or ''} - ${object.employee_id.name or ''}
+ ${ctx.get('dbname') and 'prod' not in ctx.get('dbname') and '[TEST]' or ''}[${object.type == 'remove' and 'Leave' or 'Allocation'} ${ctx.get('new_holiday_state')}] ${object.name or ''} - ${object.employee_id.name or ''}
${user.lang}
WARNING : THIS IS A TEST E-MAIL sent from a test Odoo database (${ctx.get('dbname')}). Do not take into account !
% endif
-The following ${object.type == 'remove' and 'leave request' or 'ALLOCATION request (i.e. credit of days, not debit !)'} has been ${ctx.get('wkf_tracker') or 'ERROR'} today in Odoo by ${user.name or ''} :
+The following ${object.type == 'remove' and 'leave request' or 'ALLOCATION request (i.e. credit of days, not debit !)'} has been ${ctx.get('new_holiday_state') or 'ERROR'} today in Odoo by ${user.name or ''} :
- Employee : ${object.employee_id.name or ''}
@@ -35,11 +35,11 @@
- Notes for the manager : ${object.notes or ''}
-% if ctx.get('wkf_tracker') == 'submitted':
+% if ctx.get('new_holiday_state') == 'submitted':
% if object.type == 'remove':
-To validate or refuse it, go to the menu Human Resources > Leaves > Leave requests to approve.
+To validate or refuse it, go to the menu Leaves > Leaves to Approve > Leaves.
% else:
-To validate or refuse it, go to the menu Human Resources > Leaves > Allocation requests.
+To validate or refuse it, go to the menu Leaves > Leaves to Approve > Leaves Allocation.
% endif
% endif
diff --git a/hr_holidays_usability/hr_holidays_view.xml b/hr_holidays_usability/hr_holidays_view.xml
index 9cb6b9a..792e2a9 100644
--- a/hr_holidays_usability/hr_holidays_view.xml
+++ b/hr_holidays_usability/hr_holidays_view.xml
@@ -35,7 +35,7 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
-
+
@@ -61,6 +61,7 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
+
@@ -86,6 +87,7 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
+
diff --git a/hr_holidays_usability/report/hr_holidays_employee_counter.py b/hr_holidays_usability/report/hr_holidays_employee_counter.py
index 1680ae4..9023c4a 100644
--- a/hr_holidays_usability/report/hr_holidays_employee_counter.py
+++ b/hr_holidays_usability/report/hr_holidays_employee_counter.py
@@ -3,7 +3,7 @@
# @author Alexis de Lattre
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import fields, models, tools
+from odoo import fields, models, api, tools
class HrHolidaysEmployeeCounter(models.Model):
@@ -22,9 +22,10 @@ class HrHolidaysEmployeeCounter(models.Model):
leaves_remaining_posted = fields.Float(string='Posted Remaining Leaves')
allocated_leaves = fields.Float(string='Allocated Leaves')
+ @api.model_cr
def init(self):
- tools.drop_view_if_exists(self._cr, 'hr_holidays_employee_counter')
- self._cr.execute("""
+ tools.drop_view_if_exists(self.env.cr, 'hr_holidays_employee_counter')
+ self.env.cr.execute("""
CREATE or REPLACE view hr_holidays_employee_counter AS (
SELECT
min(hh.id) AS id,
diff --git a/hr_holidays_usability/security/holiday_security.xml b/hr_holidays_usability/security/holiday_security.xml
index 96c5f39..024e470 100644
--- a/hr_holidays_usability/security/holiday_security.xml
+++ b/hr_holidays_usability/security/holiday_security.xml
@@ -1,5 +1,5 @@
-
+