[IMP] hr: enforce selection of one advanced control option

Before this commit, it was possible to activate the Advanced Presence
Control feature without any advanced feature enabled.

This commit enforces the selection of *at least* one of those option
(email or IP).

closes odoo/odoo#60498

Taskid: 2361870
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Kevin Baptiste
2020-11-12 09:17:57 +00:00
parent 4097829caa
commit af357fecd6
3 changed files with 26 additions and 1 deletions
+13 -1
View File
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from odoo import fields, models
import threading
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
class ResConfigSettings(models.TransientModel):
@@ -18,3 +20,13 @@ class ResConfigSettings(models.TransientModel):
hr_presence_control_email_amount = fields.Integer(related="company_id.hr_presence_control_email_amount", readonly=False)
hr_presence_control_ip_list = fields.Char(related="company_id.hr_presence_control_ip_list", readonly=False)
hr_employee_self_edit = fields.Boolean(string="Employee Editing", config_parameter='hr.hr_employee_self_edit')
@api.constrains('module_hr_presence', 'hr_presence_control_email', 'hr_presence_control_ip')
def _check_advanced_presence(self):
test_mode = self.env.registry.in_test_mode() or getattr(threading.currentThread(), 'testing', False)
if self.env.context.get('install_mode', False) or test_mode:
return
for settings in self:
if settings.module_hr_presence and not (settings.hr_presence_control_email or settings.hr_presence_control_ip):
raise ValidationError(_('You should select at least one Advanced Presence Control option.'))
+12
View File
@@ -3,3 +3,15 @@
from . import controllers
from . import models
from odoo import api, SUPERUSER_ID
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
email = env['ir.config_parameter'].get_param('hr_presence.hr_presence_control_email')
ip = env['ir.config_parameter'].get_param('hr_presence.hr_presence_control_ip')
if not email and not ip:
env['ir.config_parameter'].sudo().set_param('hr_presence.hr_presence_control_email', True)
+1
View File
@@ -26,4 +26,5 @@ Allows to contact directly the employee in case of unjustified absence.
'demo': [],
'installable': True,
'auto_install': False,
'post_init_hook': 'post_init_hook'
}