Up-port new stuff from hr_holidays_usability from 7.0 to 8.0
This commit is contained in:
3
hr_holidays_usability/wizard/__init__.py
Normal file
3
hr_holidays_usability/wizard/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
from . import hr_holidays_mass_allocation
|
||||
from . import hr_holidays_post
|
||||
89
hr_holidays_usability/wizard/hr_holidays_mass_allocation.py
Normal file
89
hr_holidays_usability/wizard/hr_holidays_mass_allocation.py
Normal file
@@ -0,0 +1,89 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# HR Holidays Usability module for Odoo
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import models, fields, api, workflow, _
|
||||
from openerp.exceptions import Warning
|
||||
|
||||
|
||||
class HrHolidaysMassAllocation(models.TransientModel):
|
||||
_name = 'hr.holidays.mass.allocation'
|
||||
_description = 'Wizard for mass allocation of holidays'
|
||||
|
||||
def _get_all_employees(self):
|
||||
return self.pool['hr.employee'].search([])
|
||||
|
||||
def _get_default_holiday_status(self):
|
||||
res = self._user.company_id.\
|
||||
mass_allocation_default_holiday_status_id or False
|
||||
return res
|
||||
|
||||
number_of_days = fields.Float(
|
||||
string='Number of Days', required=True, default=2.08)
|
||||
holiday_status_id = fields.Many2one(
|
||||
'hr.holidays.status', string='Leave Type', required=True,
|
||||
default=_get_default_holiday_status)
|
||||
employee_ids = fields.Many2many(
|
||||
'hr.employee', string='Employees', default=_get_all_employees)
|
||||
auto_approve = fields.Boolean(
|
||||
string='Automatic Approval', default=True)
|
||||
# size=64 because the name field of hr.holidays is size=64
|
||||
name = fields.Char('Description', size=64)
|
||||
|
||||
_sql_constraints = [(
|
||||
'number_of_days_positive',
|
||||
'CHECK (number_of_days > 0)',
|
||||
'The number of days must be positive',
|
||||
)]
|
||||
|
||||
@api.multi
|
||||
def run(self):
|
||||
self.ensure_one()
|
||||
if not self.number_of_days:
|
||||
raise Warning(
|
||||
_('You must set a value for the number of days.'))
|
||||
if not self.employee_ids:
|
||||
raise Warning(
|
||||
_('You must select at least one employee.'))
|
||||
alloc_hol_ids = []
|
||||
hho = self.env['hr.holidays']
|
||||
auto_approve = self.auto_approve
|
||||
for employee in self.employee_ids:
|
||||
hol = hho.create({
|
||||
'name': self.name,
|
||||
'number_of_days_temp': self.number_of_days,
|
||||
'employee_id': employee.id,
|
||||
'type': 'add',
|
||||
'holiday_type': 'employee',
|
||||
'holiday_status_id': self.holiday_status_id.id,
|
||||
})
|
||||
if auto_approve:
|
||||
workflow.trg_validate(
|
||||
self._uid, 'hr.holidays', hol.id, 'validate', self._cr)
|
||||
alloc_hol_ids.append(hol.id)
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'hr_holidays', 'open_allocation_holidays')
|
||||
action.update({
|
||||
'target': 'current',
|
||||
'domain': [('id', 'in', alloc_hol_ids)],
|
||||
'nodestroy': True,
|
||||
})
|
||||
return action
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="hr_holidays_mass_allocation_form" model="ir.ui.view">
|
||||
<field name="name">hr_holidays_mass_allocation_form</field>
|
||||
<field name="model">hr.holidays.mass.allocation</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Mass Allocation of Holidays" version="7.0">
|
||||
<group name="main">
|
||||
<field name="name"/>
|
||||
<field name="holiday_status_id"/>
|
||||
<field name="employee_ids" widget="many2many_tags"/>
|
||||
<field name="number_of_days"/>
|
||||
<field name="auto_approve"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="run" type="object" string="Create Allocations"
|
||||
class="oe_highlight"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_holidays_mass_allocation_action" model="ir.actions.act_window">
|
||||
<field name="name">Mass Allocation</field>
|
||||
<field name="res_model">hr.holidays.mass.allocation</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="hr_holidays_mass_allocation_menu"
|
||||
action="hr_holidays_mass_allocation_action"
|
||||
parent="hr_holidays.menu_open_ask_holidays"
|
||||
groups="base.group_hr_user"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
86
hr_holidays_usability/wizard/hr_holidays_post.py
Normal file
86
hr_holidays_usability/wizard/hr_holidays_post.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# HR Holidays Usability module for Odoo
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import models, fields, api, _
|
||||
from openerp.exceptions import Warning
|
||||
|
||||
|
||||
class HrHolidaysPost(models.TransientModel):
|
||||
_name = 'hr.holidays.post'
|
||||
_description = 'Wizard for post holidays'
|
||||
|
||||
before_date = fields.Date(
|
||||
string='Select Leave Requests That Ended Before', required=True,
|
||||
default=fields.Date.context_today,
|
||||
help="The wizard will select the validated holidays "
|
||||
"that ended before that date (including holidays that "
|
||||
"ended on that date).")
|
||||
holidays_to_post_ids = fields.Many2many(
|
||||
'hr.holidays', string='Leave Requests to Post',
|
||||
domain=[
|
||||
('type', '=', 'remove'),
|
||||
('holiday_type', '=', 'employee'),
|
||||
('state', '=', 'validate'),
|
||||
('posted_date', '=', False),
|
||||
])
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
('done', 'Done'),
|
||||
], string='State', readonly=True, default='draft')
|
||||
|
||||
@api.multi
|
||||
def select_date(self):
|
||||
self.ensure_one()
|
||||
hols = self.pool['hr.holidays'].search([
|
||||
('type', '=', 'remove'),
|
||||
('holiday_type', '=', 'employee'),
|
||||
('state', '=', 'validate'),
|
||||
('posted_date', '=', False),
|
||||
('vacation_date_to', '<=', self.before_date),
|
||||
])
|
||||
self.write({
|
||||
'state': 'done',
|
||||
'holidays_to_post_ids': [(6, 0, hols.ids)],
|
||||
})
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'hr_holidays_usability', 'hr_holidays_post_action')
|
||||
action['res_id'] = self.id
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def run(self):
|
||||
self.ensure_one()
|
||||
today = fields.Date.context_today(self)
|
||||
if not self.holidays_to_post_ids:
|
||||
raise Warning(
|
||||
_('No leave request to post.'))
|
||||
self.holidays_to_post_ids.write({'posted_date': today})
|
||||
# On v8, return a graph view !
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'hr_holidays', 'open_ask_holidays')
|
||||
action.update({
|
||||
'target': 'current',
|
||||
'domain': [('id', 'in', self.holidays_to_post_ids.ids)],
|
||||
'nodestroy': True,
|
||||
'context': {'group_by': ['employee_id', 'holiday_status_id']},
|
||||
})
|
||||
return action
|
||||
47
hr_holidays_usability/wizard/hr_holidays_post_view.xml
Normal file
47
hr_holidays_usability/wizard/hr_holidays_post_view.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="hr_holidays_post_form" model="ir.ui.view">
|
||||
<field name="name">hr_holidays_post_form</field>
|
||||
<field name="model">hr.holidays.post</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Post Leaves" version="7.0">
|
||||
<group name="main" string="Leave Requests to Post">
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="before_date" states="draft"/>
|
||||
<field name="holidays_to_post_ids" nolabel="1"
|
||||
context="{'tree_view_ref': 'hr_holidays.view_holiday'}"
|
||||
states="done"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="select_date" type="object" string="Get Holiday Requests"
|
||||
class="oe_highlight" states="draft"/>
|
||||
<button name="run" type="object" string="Post"
|
||||
class="oe_highlight" states="done"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_holidays_post_action" model="ir.actions.act_window">
|
||||
<field name="name">Post Leave Requests</field>
|
||||
<field name="res_model">hr.holidays.post</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="hr_holidays_post_menu"
|
||||
action="hr_holidays_post_action"
|
||||
parent="hr_holidays.menu_open_ask_holidays"
|
||||
groups="base.group_hr_user"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user