[MERGE] hr_presence: Improve functional flow

Fine tune the module to improve the business flow:

1/ Allow to force the presence of an employee
2/ Don't notify followers when sending a email
3/ Open the leave request form instead of the leaves list

closes odoo/odoo#28483
This commit is contained in:
Robot Odoo
2018-11-07 18:44:45 +01:00
committed by GitHub
4 changed files with 30 additions and 10 deletions
+1
View File
@@ -293,6 +293,7 @@ class HolidaysRequest(models.Model):
tz = self.env.user.tz if self.env.user.tz and not self.request_unit_custom else 'UTC' # custom -> already in UTC
self.date_from = timezone(tz).localize(datetime.combine(self.request_date_from, hour_from)).astimezone(UTC).replace(tzinfo=None)
self.date_to = timezone(tz).localize(datetime.combine(self.request_date_to, hour_to)).astimezone(UTC).replace(tzinfo=None)
self._onchange_leave_dates()
@api.onchange('request_unit_half')
def _onchange_request_unit_half(self):
+1 -1
View File
@@ -3,7 +3,7 @@
<data noupdate="1">
<record id="mail_template_presence" model="mail.template">
<field name="name">Presence: Contact Employee</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="model_id" ref="hr.model_hr_employee"/>
<field name="subject">Unexpected Absence</field>
<field name="email_from">${ctx['email_from'] or ''}</field>
<field name="email_to">${ctx['email_to'] or ''}</field>
+23 -6
View File
@@ -95,7 +95,23 @@ class ResCompany(models.Model):
"context": {'search_default_group_hr_presence_state': 1},
}
def action_set_present(self):
if not self.env.user.has_group('hr.group_hr_manager'):
raise UserError(_("You don't have the right to do this. Please contact an Administrator."))
self.write({'hr_presence_state': 'present'})
def action_open_leave_request(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"res_model": "hr.leave",
"views": [[False, "form"]],
"view_mode": 'form',
"context": {'default_employee_id': self.id},
}
def action_send_sms(self):
self.ensure_one()
if not self.env.user.has_group('hr.group_hr_manager'):
raise UserError(_("You don't have the right to do this. Please contact an Administrator."))
if not self.mobile_phone:
@@ -108,7 +124,7 @@ Do not hesitate to contact your manager or the human resource department.""")
"res_model": "sms.send_sms",
"view_mode": 'form',
"context": {
'active_id': self.env.context.get('active_id'),
'active_id': self.id,
'default_message': body,
'default_recipients': self.mobile_phone,
},
@@ -117,22 +133,23 @@ Do not hesitate to contact your manager or the human resource department.""")
}
def action_send_mail(self):
self.ensure_one()
if not self.env.user.has_group('hr.group_hr_manager'):
raise UserError(_("You don't have the right to do this. Please contact an Administrator."))
employee = self.env['hr.employee'].sudo().browse(self.env.context.get('active_id'))
if not employee.work_email:
if not self.work_email:
raise UserError(_("There is no professional email address for this employee."))
template = self.env.ref('hr_presence.mail_template_presence', False)
compose_form = self.env.ref('mail.email_compose_message_wizard_form', False)
ctx = dict(
default_model='hr.employee',
default_res_id=employee.id,
default_model="hr.employee",
default_res_id=self.id,
default_use_template=bool(template),
default_template_id=template.id,
default_composition_mode='comment',
default_is_log=True,
custom_layout='mail.mail_notification_light',
email_from=self.env.user.email,
email_to=employee.work_email,
email_to=self.work_email,
)
return {
'name': _('Compose Email'),
@@ -22,9 +22,11 @@
<xpath expr="//div[hasclass('oe_kanban_details')]" position="inside">
<div class="o_kanban_record_bottom">
<div class="oe_kanban_bottom_left">
<button name="%(hr_holidays.hr_leave_action_all)d" type="action" class="btn btn-primary btn-sm mt8" context="{'default_employee_id': active_id}">Leaves</button>
<button name="action_send_sms" type="object" class="btn btn-primary btn-sm mt8" context="{'active_id': active_id}">SMS</button>
<button name="action_send_mail" type="object" class="btn btn-primary btn-sm mt8" context="{'active_id': active_id}">Mail</button>
<field name="hr_presence_state" invisible="1"/>
<button name="action_set_present" type="object" class="btn btn-primary btn-sm mt8 fa fa-check" title="Set as present" attrs="{'invisible': [('hr_presence_state', '!=', 'to_define')]}"> </button>
<button name="action_open_leave_request" type="object" class="btn btn-primary btn-sm mt8">Leaves</button>
<button name="action_send_sms" type="object" class="btn btn-primary btn-sm mt8">SMS</button>
<button name="action_send_mail" type="object" class="btn btn-primary btn-sm mt8">Mail</button>
</div>
</div>
</xpath>