Permalink
Browse files

[IMP] hr_payroll: reorganize menus layouts

Improve usability in the Payroll app.
  • Loading branch information...
Musvol committed Jan 8, 2019
1 parent 1bc2652 commit 8e7b877957566af3a4e8adcc918d99b2fb0e4aa9
@@ -32,6 +32,7 @@
'views/hr_leave_views.xml',
'views/resource_views.xml',
'views/hr_benefit_template.xml',
'views/hr_payroll_menu.xml',
],
'demo': ['data/hr_payroll_demo.xml'],
'qweb': [
@@ -73,6 +73,7 @@ def write(self, vals):
vals['active'] = True
if vals['state'] == 'cancelled':
vals['active'] = False
self.mapped('leave_id').action_refuse()
return super(HrBenefit, self).write(vals)

@api.multi
@@ -283,3 +284,14 @@ class HrBenefitType(models.Model):
help="If the active field is set to false, it will allow you to hide the benefit type without removing it.")
is_leave = fields.Boolean(default=False, string="Leave")

class Contacts(models.Model):
_name = 'hr.benefit.employee'
_description = 'Benefits Employees'

user_id = fields.Many2one('res.users', 'Me', required=True, default=lambda self: self.env.user)
employee_id = fields.Many2one('hr.employee', 'Employee', required=True)
active = fields.Boolean('Active', default=True)

_sql_constraints = [
('user_id_employee_id_unique', 'UNIQUE(user_id,employee_id)', 'You cannot have twice the same employee.')
]
@@ -25,6 +25,16 @@ def _compute_payslip_count(self):
for employee in self:
employee.payslip_count = len(employee.slip_ids)

def has_non_validated_benefits(self, date_from, date_to):
return bool(self.env['hr.benefit'].search_count([
('employee_id', 'in', self.ids),
('date_start', '<=', date_to),
('date_stop', '>=', date_from),
('state', 'in', ['draft', 'confirmed'])
]))




@api.model
def generate_benefit(self, date_start, date_stop):
@@ -34,7 +44,6 @@ def generate_benefit(self, date_start, date_stop):
date_stop = datetime.strptime(date_stop, fmt).replace(tzinfo=pytz.utc)

for employee in self.env['hr.contract'].search([('state', 'in', ['open', 'pending', 'close'])]).mapped('employee_id'):
print(employee.name, employee.contract_id.state)
# Approved leaves
emp_leaves = employee.resource_calendar_id.leave_ids.filtered(
lambda r:
@@ -69,5 +69,5 @@ def action_validate(self):
def action_refuse(self):
super(HrLeave, self).action_refuse()
benefits = self.env['hr.benefit'].search([('leave_id', 'in', self.ids)])
benefits.write({'display_warning': False, 'leave_id': None})
benefits.write({'display_warning': False, 'active': False})
return True
@@ -24,16 +24,16 @@ class HrPayslip(models.Model):
'mandatory anymore and thus the rules applied will be all the rules set on the '
'structure of all contracts of the employee valid for the chosen period')
name = fields.Char(string='Payslip Name', readonly=True,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
number = fields.Char(string='Reference', readonly=True, copy=False,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
employee_id = fields.Many2one('hr.employee', string='Employee', required=True, readonly=True,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
date_from = fields.Date(string='Date From', readonly=True, required=True,
default=lambda self: fields.Date.to_string(date.today().replace(day=1)), states={'draft': [('readonly', False)]})
default=lambda self: fields.Date.to_string(date.today().replace(day=1)), states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
date_to = fields.Date(string='Date To', readonly=True, required=True,
default=lambda self: fields.Date.to_string((datetime.now() + relativedelta(months=+1, day=1, days=-1)).date()),
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
# this is chaos: 4 states are defined, 3 are used ('verify' isn't) and 5 exist ('confirm' seems to have existed)
state = fields.Selection([
('draft', 'Draft'),
@@ -46,28 +46,42 @@ class HrPayslip(models.Model):
\n* If the payslip is confirmed then status is set to \'Done\'.
\n* When user cancel payslip the status is \'Rejected\'.""")
line_ids = fields.One2many('hr.payslip.line', 'slip_id', string='Payslip Lines', readonly=True,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
company_id = fields.Many2one('res.company', string='Company', readonly=True, copy=False,
default=lambda self: self.env['res.company']._company_default_get(),
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
worked_days_line_ids = fields.One2many('hr.payslip.worked_days', 'payslip_id',
string='Payslip Worked Days', copy=True, readonly=True,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
input_line_ids = fields.One2many('hr.payslip.input', 'payslip_id', string='Payslip Inputs',
readonly=True, states={'draft': [('readonly', False)]})
readonly=True, states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
paid = fields.Boolean(string='Made Payment Order ? ', readonly=True, copy=False,
states={'draft': [('readonly', False)]})
note = fields.Text(string='Internal Note', readonly=True, states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
note = fields.Text(string='Internal Note', readonly=True, states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
contract_id = fields.Many2one('hr.contract', string='Contract', readonly=True,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
credit_note = fields.Boolean(string='Credit Note', readonly=True,
states={'draft': [('readonly', False)]},
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]},
help="Indicates this payslip has a refund of another")
payslip_run_id = fields.Many2one('hr.payslip.run', string='Payslip Batches', readonly=True,
copy=False, states={'draft': [('readonly', False)]})
copy=False, states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
payslip_count = fields.Integer(compute='_compute_payslip_count', string="Payslip Computation Details")
compute_date = fields.Date('Computed On')

basic_wage = fields.Monetary(compute='_compute_basic_wage')
net_wage = fields.Monetary(compute='_compute_net_wage')
currency_id = fields.Many2one(related='contract_id.currency_id')

@api.multi
def _compute_basic_wage(self):
for payslip in self:
payslip.basic_wage = payslip.get_salary_line_total('BASIC')

@api.multi
def _compute_net_wage(self):
for payslip in self:
payslip.net_wage = payslip.get_salary_line_total('NET')

@api.multi
def _compute_payslip_count(self):
for payslip in self:
@@ -11,3 +11,4 @@ access_hr_payslip_run,hr.payslip.run,model_hr_payslip_run,hr_payroll.group_hr_pa
access_hr_salary_rule_user,hr.salary.rule.user,model_hr_salary_rule,hr_payroll.group_hr_payroll_user,1,1,1,1
access_hr_benefit,access_hr_benefit,model_hr_benefit,group_hr_payroll_user,1,1,1,1
access_hr_benefit_type,access_hr_benefit_type,model_hr_benefit_type,group_hr_payroll_user,1,1,1,1
access_hr_benefit_employee,hr.benefit.employee,model_hr_benefit_employee,group_hr_payroll_user,1,1,1,1
@@ -1,21 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<!-- <record model="ir.actions.server" id="generate_benefit">
<field name="name">Generate Benefit</field>
<field name="model_id" ref="hr.model_hr_employee"/>
<field name="binding_model_id" ref="hr.model_hr_employee"/>
<field name="state">code</field>
<field name="code">
model.search([('contract_id.state', 'in', ['open', 'pending'])]).generate_benefit()
</field>
</record> -->

<record id="hr_benefit_action" model="ir.actions.act_window">
<field name="name">Benefit</field>
<field name="res_model">hr.benefit</field>
<field name="view_type">form</field>
<field name="view_mode">calendar,tree,form</field>
<field name="view_mode">calendar,tree,form,pivot</field>
</record>

<record id="hr_benefit_calendar" model="ir.ui.view">
@@ -30,14 +20,12 @@ model.search([('contract_id.state', 'in', ['open', 'pending'])]).generate_benefi
color="benefit_type_id"
event_limit="5">
<field name="state" invisible="1"/>
<field name="employee_id" invisible="1"/>
<field name="display_warning" invisible="1"/>
<field name="name"/>
<field name="employee_id" write_model="hr.benefit.employee" write_field="employee_id" avatar_field="image_small"/>
<templates>
<t t-name="calendar-box">
<t t-set="color" t-value="widget.getColor(event.color_index)"/>
<div t-att-style="typeof color === 'string' ? ('background-color:'+color)+';' : ''" t-attf-class="#{record.is_highlighted &amp;&amp; record.is_highlighted.value ? 'o_event_hightlight' : ''} #{typeof color === 'number' ? 'o_calendar_color_'+color : ''}">
<field name="name"/>
<div class="fc-time"/>
<div class="o_fields">
<t t-if="record.display_warning">
@@ -117,6 +105,8 @@ model.search([('contract_id.state', 'in', ['open', 'pending'])]).generate_benefi
<field name="employee_id"/>
<field name="name"/>
<filter string="My Benefits" domain="[('employee_id.user_id','=',uid)]" name="my_benefits"/>
<filter string="With error" domain="[('display_warning','=', True)]" name="benefits_error"/>
<filter name="date_filter" string="Date" date="date_start"/>
<filter name="group_employee" string="Employee" context="{'group_by':'employee_id'}"/>
</search>
</field>
@@ -157,19 +147,10 @@ model.search([('contract_id.state', 'in', ['open', 'pending'])]).generate_benefi
</field>
</record>

<menuitem
id="hr_menu_benefit_menu" name="Benefits" action="hr_benefit_action" parent="menu_hr_payroll_root" sequence="25"/>

<record id="action_view_hr_benefit_type" model="ir.actions.act_window">
<field name="name">Benefit Types</field>
<field name="res_model">hr.benefit.type</field>
<field name="view_mode">tree,kanban,form</field>
</record>
<menuitem
id="menu_hr_benefit_type_view"
action="action_view_hr_benefit_type"
parent="menu_hr_payroll_configuration"
sequence="25"
/>

</odoo>
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Root Menus -->

<menuitem id="menu_hr_payroll_root" name="Payroll" sequence="45" web_icon="hr_payroll,static/description/icon.png"/>
<menuitem id="menu_hr_payroll_configuration" name="Configuration" parent="menu_hr_payroll_root"
sequence="100" groups="hr_payroll.group_hr_payroll_manager"/>

<!-- Contract View -->
<record id="hr_contract_form_inherit" model="ir.ui.view">
<field name="name">hr.contract.view.form.inherit</field>
@@ -0,0 +1,147 @@
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>

<!-- Root Menus -->

<menuitem id="menu_hr_payroll_root" name="Payroll" sequence="45" web_icon="hr_payroll,static/description/icon.png"/>


<menuitem
id="menu_hr_payroll_salary_computation"
name="Salary Computation"
parent="menu_hr_payroll_root"
sequence="50"
groups="hr_payroll.group_hr_payroll_manager"/>

<menuitem
id="menu_hr_payroll_payslips"
name="Employee Payslips"
parent="menu_hr_payroll_root"
sequence="60"
groups="hr_payroll.group_hr_payroll_manager"/>

<menuitem
id="menu_hr_payroll_configuration"
name="Configuration"
parent="menu_hr_payroll_root"
sequence="100"
groups="hr_payroll.group_hr_payroll_manager"/>

<!-- **** Salary Computation **** -->
<menuitem
id="menu_hr_payroll_employee_payslips"
name="Payslips"
parent="menu_hr_payroll_salary_computation"
sequence="60"
action="action_view_hr_payslip_month_form"
groups="hr_payroll.group_hr_payroll_manager"/>
<!-- TODO add filter-->

<menuitem
id="hr_menu_benefit_menu"
name="Benefits"
action="hr_benefit_action"
parent="menu_hr_payroll_salary_computation"
sequence="25"/>

<!-- **** Employee Payslips **** -->
<menuitem
id="menu_hr_payslip_run"
action="action_hr_payslip_run_tree"
name="Batches"
parent="menu_hr_payroll_payslips"/>

<menuitem
id="menu_hr_payroll_employee_all_payslips"
name="All Payslips"
parent="menu_hr_payroll_payslips"
sequence="60"
action="action_view_hr_payslip_form"
groups="hr_payroll.group_hr_payroll_manager"/>

<!-- **** Configuration **** -->
<menuitem
id="menu_hr_payroll_global_settings"
name="Settings"
parent="menu_hr_payroll_configuration"
sequence="0"
action="action_hr_payroll_configuration"
groups="base.group_system"/>

<!-- Benefits Configuration -->
<menuitem
id="menu_hr_benefit_confirguration"
name="Benefits"
parent="menu_hr_payroll_configuration"
sequence="50"
/>
<menuitem
id="menu_hr_benefit_type_view"
action="action_view_hr_benefit_type"
parent="menu_hr_benefit_confirguration"
/>

<!-- Salary Configuration -->
<menuitem
id="menu_hr_salary_configuration"
name="Salary"
parent="menu_hr_payroll_configuration"
sequence="30"
/>

<menuitem
id="menu_action_hr_salary_rule_form"
action="action_salary_rule_form"
name="Rules"
parent="menu_hr_salary_configuration"
sequence="10"/>

<menuitem
id="menu_hr_salary_rule_category"
action="action_hr_salary_rule_category"
name="Rule Categories"
parent="menu_hr_salary_configuration"
sequence="20"
groups="base.group_no_one"
/>

<menuitem
id="menu_hr_payroll_structure_view"
action="action_view_hr_payroll_structure_list_form"
name="Structures"
parent="menu_hr_salary_configuration"
sequence="30"
/>

<menuitem
id="menu_action_hr_contribution_register_form"
action="action_contribution_register_form"
parent="menu_hr_salary_configuration"
sequence="50"
/>

<!-- Repository Configuration -->
<menuitem
id="menu_hr_repository_confirguration"
name="Repository"
parent="menu_hr_payroll_configuration"
sequence="50"
/>

<menuitem
id="menu_hr_payroll_employees_configuration"
action="hr.open_view_employee_list_my"
parent="menu_hr_repository_confirguration"
sequence="10"
/>

<menuitem
id="menu_hr_payroll_contracts_configuration"
action="hr_contract.action_hr_contract"
parent="menu_hr_repository_confirguration"
sequence="20"
/>



</odoo>
Oops, something went wrong.

0 comments on commit 8e7b877

Please sign in to comment.