Adapt hr_holidays post wiz to new field

This commit is contained in:
Alexis de Lattre
2017-06-06 17:57:05 +02:00
parent e5221d6a96
commit 94926d188a
10 changed files with 98 additions and 49 deletions

View File

@@ -21,7 +21,7 @@
'security/holiday_security.xml',
'security/ir.model.access.csv',
'wizard/hr_holidays_mass_allocation_view.xml',
'wizard/hr_holidays_post_view.xml',
'wizard/hr_holidays_to_payslip_view.xml',
],
'installable': True,
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2015-2017 Akretion (http://www.akretion.com)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_general_configuration" model="ir.ui.view">
<field name="name">hr_holidays_usability.base.config.settings.form</field>
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="arch" type="xml">
<group name="report" position="after">
<group string="Leaves" name="holidays">
<field name="mass_allocation_default_holiday_status_id"/>
</group>
</group>
</field>
</record>
</odoo>

View File

@@ -163,6 +163,21 @@ class HrHolidays(models.Model):
holi.current_leaves_taken = current_leaves_taken
holi.current_remaining_leaves = current_remaining_leaves
@api.depends('payslip_date')
def _compute_payslip_status(self):
for holi in self:
if holi.payslip_date:
holi.payslip_status = True
else:
holi.payslip_status = False
def _set_payslip_status(self):
for holi in self:
if holi.payslip_status:
holi.payslip_date = fields.Date.context_today(self)
else:
holi.payslip_date = False
vacation_date_from = fields.Date(
string='First Day of Vacation', track_visibility='onchange',
readonly=True, states={
@@ -209,8 +224,17 @@ class HrHolidays(models.Model):
limit = fields.Boolean( # pose des pbs de droits
related='holiday_status_id.limit', string='Allow to Override Limit',
readonly=True)
posted_date = fields.Date(
string='Posted Date', track_visibility='onchange')
payslip_date = fields.Date(
string='Transfer to Payslip Date', track_visibility='onchange',
readonly=True)
# even with the new boolean field "payslip_status", I want to keep
# the "posted_date" (renamed payslip_date) field, because I want structured
# info. The main argument is that, if I don't write down the info at the end
# of the wizard "Post Leave Requests", I want to easily
# re-display the info
payslip_status = fields.Boolean(
readonly=True, compute='_compute_payslip_status',
inverse='_set_payslip_status', store=True, track_visibility='onchange')
number_of_days_temp = fields.Float(string="Number of days")
# The 'name' field is displayed publicly in the calendar
# So the label should not be 'Description' but 'Public Title'

View File

@@ -59,8 +59,8 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
</group>
</group>
</field>
<field name="department_id" position="after">
<field name="posted_date" groups="hr_holidays.group_hr_holidays_manager"/>
<field name="payslip_status" position="after">
<field name="payslip_date"/>
<field name="company_id" groups="base.group_multi_company"/>
</field>
</field>
@@ -85,10 +85,10 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
<field name="vacation_date_to"/>
<field name="vacation_time_to"/>
</field>
<field name="holiday_status_id" position="after">
<field name="posted_date" groups="hr_holidays.group_hr_holidays_manager"/>
<button name="toggle_payslip_status" position="after">
<field name="payslip_date"/>
<field name="company_id" groups="base.group_multi_company"/>
</field>
</button>
</field>
</record>
@@ -122,8 +122,11 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation -->
<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 name="gray" position="after">
<filter string="Reported in Payslip" name="green" domain="[('payslip_status', '=', True)]" groups="hr_holidays.group_hr_holidays_manager"/>
</filter>
<filter name="group_type" position="after">
<filter name="group_payslip_date" string="Transfer to Payslip Date" context="{'group_by': 'payslip_date:day'}"/>
</filter>
</field>
</record>

View File

@@ -17,9 +17,9 @@ class HrHolidaysEmployeeCounter(models.Model):
holiday_status_id = fields.Many2one(
"hr.holidays.status", string="Leave Type")
leaves_validated_current = fields.Float(string='Current Leaves Validated')
leaves_validated_posted = fields.Float(string='Leaves Posted')
leaves_validated_payslip = fields.Float(string='Leaves in Payslip')
leaves_remaining_current = fields.Float(string='Current Remaining Leaves')
leaves_remaining_posted = fields.Float(string='Posted Remaining Leaves')
leaves_remaining_payslip = fields.Float(string='Remaining Leaves in Payslip')
allocated_leaves = fields.Float(string='Allocated Leaves')
@api.model_cr
@@ -38,18 +38,18 @@ class HrHolidaysEmployeeCounter(models.Model):
END) AS leaves_validated_current,
sum(
CASE WHEN hh.type='remove'
AND hh.posted_date IS NOT null
AND hh.payslip_date IS NOT null
THEN hh.number_of_days * -1
ELSE 0
END) AS leaves_validated_posted,
END) AS leaves_validated_payslip,
sum(hh.number_of_days) AS leaves_remaining_current,
sum(
CASE WHEN (
hh.type='remove' AND hh.posted_date IS NOT null)
hh.type='remove' AND hh.payslip_date IS NOT null)
OR hh.type='add'
THEN hh.number_of_days
ELSE 0
END) as leaves_remaining_posted,
END) as leaves_remaining_payslip,
sum(
CASE WHEN hh.type = 'add'
THEN hh.number_of_days

View File

@@ -11,10 +11,9 @@
<field name="holiday_status_id"/>
<field name="allocated_leaves"/>
<field name="leaves_validated_current"/>
<field name="leaves_validated_posted"/>
<field name="leaves_validated_payslip"/>
<field name="leaves_remaining_current"/>
<field name="leaves_remaining_posted"
sum="Total Posted Remaining Leaves"/>
<field name="leaves_remaining_payslip" sum="Total"/>
</tree>
</field>
</record>

View File

@@ -4,7 +4,7 @@
<!--
Employee : only see his holidays
Officer = the manager of some employees : see his holidays and the ones of his subordinates
Manager = person that administrates the holidays process : can see everything, do mass allocation, post holidays, etc...
Manager = person that administrates the holidays process : can see everything, do mass allocation, transfer to payslip, etc...
-->
<record id="hr_holidays_counter_personal_rule" model="ir.rule">

View File

@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
from . import hr_holidays_mass_allocation
from . import hr_holidays_post
from . import hr_holidays_to_payslip

View File

@@ -7,9 +7,9 @@ from odoo import models, fields, api, _
from odoo.exceptions import UserError
class HrHolidaysPost(models.TransientModel):
_name = 'hr.holidays.post'
_description = 'Wizard for post holidays'
class HrHolidaysToPayslip(models.TransientModel):
_name = 'hr.holidays.to.payslip'
_description = 'Wizard for transfer holidays to payslip'
before_date = fields.Date(
string='Select Leave Requests That Ended Before', required=True,
@@ -17,13 +17,13 @@ class HrHolidaysPost(models.TransientModel):
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',
holidays_to_payslip_ids = fields.Many2many(
'hr.holidays', string='Leave Requests to Transfer to Payslip',
domain=[
('type', '=', 'remove'),
('holiday_type', '=', 'employee'),
('state', '=', 'validate'),
('posted_date', '=', False),
('payslip_date', '=', False),
])
state = fields.Selection([
('draft', 'Draft'),
@@ -37,35 +37,35 @@ class HrHolidaysPost(models.TransientModel):
('type', '=', 'remove'),
('holiday_type', '=', 'employee'),
('state', '=', 'validate'),
('posted_date', '=', False),
('payslip_date', '=', False),
('vacation_date_to', '<=', self.before_date),
('company_id', '=', self.env.user.company_id.id),
])
self.write({
'state': 'done',
'holidays_to_post_ids': [(6, 0, hols.ids)],
'holidays_to_payslip_ids': [(6, 0, hols.ids)],
})
action = self.env['ir.actions.act_window'].for_xml_id(
'hr_holidays_usability', 'hr_holidays_post_action')
'hr_holidays_usability', 'hr_holidays_to_payslip_action')
action['res_id'] = self.id
return action
@api.multi
def run(self):
self.ensure_one()
# I have to make a copy of self.holidays_to_post_ids in a variable
# I have to make a copy of self.holidays_to_payslip_ids in a variable
# because, after the write, it doesn't have a value any more !!!
holidays_to_post = self.holidays_to_post_ids
holidays_to_payslip = self.holidays_to_payslip_ids
today = fields.Date.context_today(self)
if not self.holidays_to_post_ids:
raise UserError(_('No leave request to post.'))
self.holidays_to_post_ids.write({'posted_date': today})
if not self.holidays_to_payslip_ids:
raise UserError(_('No leave request to transfer to payslip.'))
self.holidays_to_payslip_ids.write({'payslip_date': today})
view_id = self.env.ref('hr_holidays_usability.hr_holiday_pivot').id
action = {
'name': _('Leave Requests'),
'res_model': 'hr.holidays',
'type': 'ir.actions.act_window',
'domain': [('id', 'in', holidays_to_post.ids)],
'domain': [('id', 'in', holidays_to_payslip.ids)],
'view_mode': 'pivot',
'view_id': view_id,
}

View File

@@ -7,22 +7,22 @@
<odoo>
<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>
<record id="hr_holidays_to_payslip_form" model="ir.ui.view">
<field name="name">hr_holidays_to_payslip_form</field>
<field name="model">hr.holidays.to.payslip</field>
<field name="arch" type="xml">
<form string="Post Leaves">
<group name="main" string="Leave Requests to Post">
<form string="Transfer Leaves to Payslip">
<group name="main" string="Leave Requests to Transfer to Payslip">
<field name="state" invisible="1"/>
<field name="before_date" states="draft"/>
<field name="holidays_to_post_ids" nolabel="1" colspan="2"
<field name="holidays_to_payslip_ids" nolabel="1" colspan="2"
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"
<button name="run" type="object" string="Transfer to Payslip"
class="oe_highlight" states="done"/>
<button special="cancel" string="Cancel" class="oe_link"/>
</footer>
@@ -30,15 +30,15 @@
</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>
<record id="hr_holidays_to_payslip_action" model="ir.actions.act_window">
<field name="name">Transfer to Payslip</field>
<field name="res_model">hr.holidays.to.payslip</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem id="hr_holidays_post_menu"
action="hr_holidays_post_action"
<menuitem id="hr_holidays_to_payslip_menu"
action="hr_holidays_to_payslip_action"
parent="hr_holidays_administration_menu"
groups="hr_holidays.group_hr_holidays_manager"/>