Up-port from 7 to 8 new stuff for hr_holidays_usability
This commit is contained in:
@@ -50,12 +50,16 @@ class HrHolidays(models.Model):
|
|||||||
# For allocation (type = add), we don't change anything:
|
# For allocation (type = add), we don't change anything:
|
||||||
# The user writes in the field number_of_days_temp and
|
# The user writes in the field number_of_days_temp and
|
||||||
# number_of_days = number_of_days_temp
|
# number_of_days = number_of_days_temp
|
||||||
# For leave (type = remove), we don't let users enter the number of days,
|
# IN 7.0: For leave (type = remove), we don't let users enter the number
|
||||||
# we compute it for them
|
# of days, we compute it for them
|
||||||
# -> new computed field "number_of_days_remove' that compute the number
|
# -> new computed field "number_of_days_remove' that compute the number
|
||||||
# of days depending on the computation method defined on 'type'
|
# of days depending on the computation method defined on 'type'
|
||||||
# Redefine the field 'number_of_days' to take into accout
|
# Redefine the field 'number_of_days' to take into accout
|
||||||
# 'number_of_days_remove' when type == remove (= number_of_days_remove * -1)
|
# 'number_of_days_remove' when type == remove (= number_of_days_remove * -1)
|
||||||
|
# IN 8.0: for leaves, use the on_change on the dates to set the
|
||||||
|
# number_of_days_temp. But we want to have this field readonly, so we also
|
||||||
|
# inherit write + create (even in v8, readonly fields are not written in DB)
|
||||||
|
|
||||||
# change date time fields by date + selection morning/noon
|
# change date time fields by date + selection morning/noon
|
||||||
|
|
||||||
# How do we set the dates :
|
# How do we set the dates :
|
||||||
@@ -74,11 +78,7 @@ class HrHolidays(models.Model):
|
|||||||
# 1 for 'unpaid leaves' + repos compensateur + congés conventionnels + maladie
|
# 1 for 'unpaid leaves' + repos compensateur + congés conventionnels + maladie
|
||||||
# 1 or 2 for normal holidays
|
# 1 or 2 for normal holidays
|
||||||
|
|
||||||
@api.one
|
@api.model
|
||||||
@api.depends(
|
|
||||||
'vacation_date_from', 'vacation_time_from', 'vacation_date_to',
|
|
||||||
'vacation_time_to', 'number_of_days_temp', 'type', 'holiday_type',
|
|
||||||
'holiday_status_id.vacation_compute_method')
|
|
||||||
def _compute_number_of_days(self):
|
def _compute_number_of_days(self):
|
||||||
# depend on the holiday_status_id
|
# depend on the holiday_status_id
|
||||||
hhpo = self.env['hr.holidays.public']
|
hhpo = self.env['hr.holidays.public']
|
||||||
@@ -89,7 +89,8 @@ class HrHolidays(models.Model):
|
|||||||
self.vacation_date_from and
|
self.vacation_date_from and
|
||||||
self.vacation_time_from and
|
self.vacation_time_from and
|
||||||
self.vacation_date_to and
|
self.vacation_date_to and
|
||||||
self.vacation_time_to):
|
self.vacation_time_to and
|
||||||
|
self.vacation_date_from <= self.vacation_date_to):
|
||||||
if self.holiday_status_id.vacation_compute_method == 'business':
|
if self.holiday_status_id.vacation_compute_method == 'business':
|
||||||
business = True
|
business = True
|
||||||
else:
|
else:
|
||||||
@@ -145,19 +146,7 @@ class HrHolidays(models.Model):
|
|||||||
days -= 0.5
|
days -= 0.5
|
||||||
break
|
break
|
||||||
date_dt += relativedelta(days=1)
|
date_dt += relativedelta(days=1)
|
||||||
|
return days
|
||||||
# PASTE
|
|
||||||
if self.type == 'remove':
|
|
||||||
# read number_of_days_remove instead of number_of_days_temp
|
|
||||||
number_of_days = days * -1
|
|
||||||
number_of_days_remove = days
|
|
||||||
else:
|
|
||||||
# for allocations, we read the native field number_of_days_temp
|
|
||||||
number_of_days = self.number_of_days_temp
|
|
||||||
number_of_days_remove = 0
|
|
||||||
|
|
||||||
self.number_of_days = number_of_days
|
|
||||||
self.number_of_days_remove = number_of_days_remove
|
|
||||||
|
|
||||||
@api.one
|
@api.one
|
||||||
@api.depends('holiday_type', 'employee_id', 'holiday_status_id')
|
@api.depends('holiday_type', 'employee_id', 'holiday_status_id')
|
||||||
@@ -169,8 +158,7 @@ class HrHolidays(models.Model):
|
|||||||
self.holiday_type == 'employee' and
|
self.holiday_type == 'employee' and
|
||||||
self.employee_id and
|
self.employee_id and
|
||||||
self.holiday_status_id):
|
self.holiday_status_id):
|
||||||
days = self.holiday_status_id.get_days(
|
days = self.holiday_status_id.get_days(self.employee_id.id)
|
||||||
self.employee_id.id, False)
|
|
||||||
total_allocated_leaves =\
|
total_allocated_leaves =\
|
||||||
days[self.holiday_status_id.id]['max_leaves']
|
days[self.holiday_status_id.id]['max_leaves']
|
||||||
current_leaves_taken =\
|
current_leaves_taken =\
|
||||||
@@ -205,11 +193,6 @@ class HrHolidays(models.Model):
|
|||||||
default='evening',
|
default='evening',
|
||||||
help="For example, if you leave one full calendar week, "
|
help="For example, if you leave one full calendar week, "
|
||||||
"the end of vacation is Friday Evening")
|
"the end of vacation is Friday Evening")
|
||||||
number_of_days_remove = fields.Float(
|
|
||||||
compute='_compute_number_of_days',
|
|
||||||
string="Number of Days of Vacation", readonly=True)
|
|
||||||
# number_of_days is a native field that I inherit
|
|
||||||
number_of_days = fields.Float(compute='_compute_number_of_days')
|
|
||||||
current_leaves_taken = fields.Float(
|
current_leaves_taken = fields.Float(
|
||||||
compute='_compute_current_leaves', string='Current Leaves Taken',
|
compute='_compute_current_leaves', string='Current Leaves Taken',
|
||||||
readonly=True)
|
readonly=True)
|
||||||
@@ -223,6 +206,7 @@ class HrHolidays(models.Model):
|
|||||||
related='holiday_status_id.limit', string='Allow to Override Limit')
|
related='holiday_status_id.limit', string='Allow to Override Limit')
|
||||||
posted_date = fields.Date(
|
posted_date = fields.Date(
|
||||||
string='Posted Date', track_visibility='onchange')
|
string='Posted Date', track_visibility='onchange')
|
||||||
|
number_of_days_temp = fields.Float(string="Number of days")
|
||||||
|
|
||||||
@api.one
|
@api.one
|
||||||
@api.constrains(
|
@api.constrains(
|
||||||
@@ -306,9 +290,46 @@ class HrHolidays(models.Model):
|
|||||||
datetime_dt.astimezone(pytz.utc))
|
datetime_dt.astimezone(pytz.utc))
|
||||||
self.date_to = datetime_str
|
self.date_to = datetime_str
|
||||||
|
|
||||||
|
@api.onchange(
|
||||||
|
'vacation_date_from', 'vacation_time_from', 'vacation_date_to',
|
||||||
|
'vacation_time_to', 'number_of_days_temp', 'type', 'holiday_type',
|
||||||
|
'holiday_status_id')
|
||||||
|
def leave_number_of_days_change(self):
|
||||||
|
if self.type == 'remove':
|
||||||
|
days = self._compute_number_of_days()
|
||||||
|
self.number_of_days_temp = days
|
||||||
|
|
||||||
|
# Neutralize the native on_change on dates
|
||||||
|
def onchange_date_from(self, cr, uid, ids, date_to, date_from):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def onchange_date_to(self, cr, uid, ids, date_to, date_from):
|
||||||
|
return {}
|
||||||
|
|
||||||
# in v8, no more need to inherit check_holidays() as I did in v8
|
# in v8, no more need to inherit check_holidays() as I did in v8
|
||||||
# because it doesn't use number_of_days_temp
|
# because it doesn't use number_of_days_temp
|
||||||
|
|
||||||
|
# I want to set number_of_days_temp as readonly in the view of leaves
|
||||||
|
# and, even in v8, we can't write on a readonly field
|
||||||
|
# So I inherit write and create
|
||||||
|
@api.model
|
||||||
|
def create(self, vals):
|
||||||
|
obj = super(HrHolidays, self).create(vals)
|
||||||
|
if obj.type == 'remove':
|
||||||
|
days = obj._compute_number_of_days()
|
||||||
|
obj.number_of_days_temp = days
|
||||||
|
return obj
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def write(self, vals):
|
||||||
|
res = super(HrHolidays, self).write(vals)
|
||||||
|
for obj in self:
|
||||||
|
if obj.type == 'remove':
|
||||||
|
days = obj._compute_number_of_days()
|
||||||
|
if days != obj.number_of_days_temp:
|
||||||
|
obj.number_of_days_temp = days
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
class ResCompany(models.Model):
|
class ResCompany(models.Model):
|
||||||
_inherit = 'res.company'
|
_inherit = 'res.company'
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
|
|||||||
<attribute name="invisible">1</attribute>
|
<attribute name="invisible">1</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
<field name="number_of_days_temp" position="attributes">
|
<field name="number_of_days_temp" position="attributes">
|
||||||
<attribute name="attrs">{'invisible': [('type', '=', 'remove')]}</attribute>
|
<attribute name="attrs">{'readonly': [('type', '=', 'remove')]}</attribute>
|
||||||
</field>
|
|
||||||
<field name="number_of_days_temp" position="after">
|
|
||||||
<field name="number_of_days_remove" class="oe_inline" attrs="{'invisible': [('type', '=', 'add')]}"/>
|
|
||||||
</field>
|
</field>
|
||||||
<field name="holiday_status_id" position="after">
|
<field name="holiday_status_id" position="after">
|
||||||
<field name="vacation_date_from" attrs="{'required': [('type', '=', 'remove')], 'invisible': [('type', '=', 'add')]}"/>
|
<field name="vacation_date_from" attrs="{'required': [('type', '=', 'remove')], 'invisible': [('type', '=', 'add')]}"/>
|
||||||
@@ -69,12 +66,6 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
|
|||||||
<field name="model">hr.holidays</field>
|
<field name="model">hr.holidays</field>
|
||||||
<field name="inherit_id" ref="hr_holidays.view_holiday"/>
|
<field name="inherit_id" ref="hr_holidays.view_holiday"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="number_of_days" position="attributes">
|
|
||||||
<attribute name="invisible">1</attribute>
|
|
||||||
</field>
|
|
||||||
<field name="number_of_days" position="after">
|
|
||||||
<field name="number_of_days_remove" sum="Total Days of Vacation"/>
|
|
||||||
</field>
|
|
||||||
<field name="date_from" position="attributes">
|
<field name="date_from" position="attributes">
|
||||||
<attribute name="invisible">1</attribute>
|
<attribute name="invisible">1</attribute>
|
||||||
</field>
|
</field>
|
||||||
@@ -98,6 +89,29 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
|
|||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="view_hr_holidays_filter" model="ir.ui.view">
|
||||||
|
<field name="name">hr_holidays_usability.leave_request_tree</field>
|
||||||
|
<field name="model">hr.holidays</field>
|
||||||
|
<field name="inherit_id" ref="hr_holidays.view_hr_holidays_filter"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<filter name="validated" position="after">
|
||||||
|
<filter name="posted" string="Posted" domain="[('posted_date', '!=', False)]"/>
|
||||||
|
</filter>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="hr_holiday_graph" model="ir.ui.view">
|
||||||
|
<field name="name">hr_holidays_usability.hr_holiday_graph</field>
|
||||||
|
<field name="model">hr.holidays</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<graph string="Leave Requests" type="pivot">
|
||||||
|
<field name="employee_id" type="row"/>
|
||||||
|
<field name="holiday_status_id" type="col"/>
|
||||||
|
<field name="number_of_days_temp" type="measure"/>
|
||||||
|
</graph>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<record id="edit_holiday_status_form" model="ir.ui.view">
|
<record id="edit_holiday_status_form" model="ir.ui.view">
|
||||||
<field name="name">hr_holidays_usability.hr.holidays.status.form</field>
|
<field name="name">hr_holidays_usability.hr.holidays.status.form</field>
|
||||||
<field name="model">hr.holidays.status</field>
|
<field name="model">hr.holidays.status</field>
|
||||||
@@ -122,7 +136,14 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
|
|||||||
|
|
||||||
<!-- On the leave requests, put tree view by default instead of calendar -->
|
<!-- On the leave requests, put tree view by default instead of calendar -->
|
||||||
<record id="hr_holidays.action_open_ask_holidays_calendar" model="ir.actions.act_window.view">
|
<record id="hr_holidays.action_open_ask_holidays_calendar" model="ir.actions.act_window.view">
|
||||||
|
<field name="sequence" eval="4"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_open_ask_holidays_graph" model="ir.actions.act_window.view">
|
||||||
<field name="sequence" eval="5"/>
|
<field name="sequence" eval="5"/>
|
||||||
|
<field name="view_mode">graph</field>
|
||||||
|
<field name="view_id" ref="hr_holiday_graph"/>
|
||||||
|
<field name="act_window_id" ref="hr_holidays.open_ask_holidays"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="resource_calendar_leaves_cal_first_action" model="ir.actions.act_window">
|
<record id="resource_calendar_leaves_cal_first_action" model="ir.actions.act_window">
|
||||||
|
|||||||
@@ -28,11 +28,13 @@ class HrHolidaysMassAllocation(models.TransientModel):
|
|||||||
_name = 'hr.holidays.mass.allocation'
|
_name = 'hr.holidays.mass.allocation'
|
||||||
_description = 'Wizard for mass allocation of holidays'
|
_description = 'Wizard for mass allocation of holidays'
|
||||||
|
|
||||||
|
@api.model
|
||||||
def _get_all_employees(self):
|
def _get_all_employees(self):
|
||||||
return self.pool['hr.employee'].search([])
|
return self.env['hr.employee'].search([])
|
||||||
|
|
||||||
|
@api.model
|
||||||
def _get_default_holiday_status(self):
|
def _get_default_holiday_status(self):
|
||||||
res = self._user.company_id.\
|
res = self.env.user.company_id.\
|
||||||
mass_allocation_default_holiday_status_id or False
|
mass_allocation_default_holiday_status_id or False
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class HrHolidaysPost(models.TransientModel):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def select_date(self):
|
def select_date(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
hols = self.pool['hr.holidays'].search([
|
hols = self.env['hr.holidays'].search([
|
||||||
('type', '=', 'remove'),
|
('type', '=', 'remove'),
|
||||||
('holiday_type', '=', 'employee'),
|
('holiday_type', '=', 'employee'),
|
||||||
('state', '=', 'validate'),
|
('state', '=', 'validate'),
|
||||||
@@ -69,18 +69,21 @@ class HrHolidaysPost(models.TransientModel):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def run(self):
|
def run(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
# I have to make a copy of self.holidays_to_post_ids in a variable
|
||||||
|
# because, after the write, it doesn't have a value any more !!!
|
||||||
|
holidays_to_post = self.holidays_to_post_ids
|
||||||
today = fields.Date.context_today(self)
|
today = fields.Date.context_today(self)
|
||||||
if not self.holidays_to_post_ids:
|
if not self.holidays_to_post_ids:
|
||||||
raise Warning(
|
raise Warning(
|
||||||
_('No leave request to post.'))
|
_('No leave request to post.'))
|
||||||
self.holidays_to_post_ids.write({'posted_date': today})
|
self.holidays_to_post_ids.write({'posted_date': today})
|
||||||
# On v8, return a graph view !
|
view_id = self.env.ref('hr_holidays_usability.hr_holiday_graph').id
|
||||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
action = {
|
||||||
'hr_holidays', 'open_ask_holidays')
|
'name': _('Leave Requests'),
|
||||||
action.update({
|
'res_model': 'hr.holidays',
|
||||||
'target': 'current',
|
'type': 'ir.actions.act_window',
|
||||||
'domain': [('id', 'in', self.holidays_to_post_ids.ids)],
|
'domain': [('id', 'in', holidays_to_post.ids)],
|
||||||
'nodestroy': True,
|
'view_mode': 'graph',
|
||||||
'context': {'group_by': ['employee_id', 'holiday_status_id']},
|
'view_id': view_id,
|
||||||
})
|
}
|
||||||
return action
|
return action
|
||||||
|
|||||||
Reference in New Issue
Block a user