mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'mig/13.0/hr_payroll_gamification' into '13.0'
mig/13.0/hr_payroll_gamification into 13.0 See merge request hibou-io/hibou-odoo/suite!206
This commit is contained in:
1
hr_payroll_gamification/__init__.py
Normal file
1
hr_payroll_gamification/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
20
hr_payroll_gamification/__manifest__.py
Executable file
20
hr_payroll_gamification/__manifest__.py
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
'name': 'Payroll Gamification',
|
||||||
|
'description': 'Payroll Gamification',
|
||||||
|
'version': '13.0.1.0.1',
|
||||||
|
'website': 'https://hibou.io/',
|
||||||
|
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'category': 'Human Resources',
|
||||||
|
'data': [
|
||||||
|
'data/payroll_data.xml',
|
||||||
|
'views/gamification_views.xml',
|
||||||
|
],
|
||||||
|
'demo': [
|
||||||
|
'data/payroll_demo.xml',
|
||||||
|
],
|
||||||
|
'depends': [
|
||||||
|
'hr_gamification',
|
||||||
|
'hr_payroll',
|
||||||
|
],
|
||||||
|
}
|
||||||
10
hr_payroll_gamification/data/payroll_data.xml
Normal file
10
hr_payroll_gamification/data/payroll_data.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<!-- Salary Other Input -->
|
||||||
|
<record id="badge_other_input" model="hr.payslip.input.type">
|
||||||
|
<field name="name">Badges</field>
|
||||||
|
<field name="code">BADGES</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
16
hr_payroll_gamification/data/payroll_demo.xml
Normal file
16
hr_payroll_gamification/data/payroll_demo.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="hr_salary_rule_gamification" model="hr.salary.rule">
|
||||||
|
<field name="condition_select">python</field>
|
||||||
|
<field name="condition_python">result = inputs.BADGES.amount > 0.0 if inputs.BADGES else False</field>
|
||||||
|
<field name="amount_select">code</field>
|
||||||
|
<field name="amount_python_compute">result = inputs.BADGES.amount if inputs.BADGES else 0</field>
|
||||||
|
<field name="code">BADGES</field>
|
||||||
|
<field name="category_id" ref="hr_payroll.BASIC"/>
|
||||||
|
<field name="name">Badges</field>
|
||||||
|
<field name="sequence" eval="90"/>
|
||||||
|
<field name="struct_id" ref="hr_payroll.structure_002"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
2
hr_payroll_gamification/models/__init__.py
Normal file
2
hr_payroll_gamification/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import gamification
|
||||||
|
from . import payroll
|
||||||
12
hr_payroll_gamification/models/gamification.py
Normal file
12
hr_payroll_gamification/models/gamification.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class GamificationBadge(models.Model):
|
||||||
|
_inherit = 'gamification.badge'
|
||||||
|
|
||||||
|
payroll_type = fields.Selection([
|
||||||
|
('', 'None'),
|
||||||
|
('fixed', 'Fixed'),
|
||||||
|
('period', 'Granted in Pay Period'),
|
||||||
|
], string='Payroll Type')
|
||||||
|
payroll_amount = fields.Float(string='Payroll Amount', digits=(10, 4))
|
||||||
40
hr_payroll_gamification/models/payroll.py
Normal file
40
hr_payroll_gamification/models/payroll.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class Payslip(models.Model):
|
||||||
|
_inherit = 'hr.payslip'
|
||||||
|
|
||||||
|
@api.onchange('employee_id', 'struct_id', 'contract_id', 'date_from', 'date_to')
|
||||||
|
def _onchange_employee(self):
|
||||||
|
res = super()._onchange_employee()
|
||||||
|
if self.state == 'draft':
|
||||||
|
self._input_badges()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _input_badges(self):
|
||||||
|
badge_type = self.env.ref('hr_payroll_gamification.badge_other_input', raise_if_not_found=False)
|
||||||
|
if not badge_type:
|
||||||
|
return
|
||||||
|
|
||||||
|
amount = self._get_input_badges()
|
||||||
|
if not amount:
|
||||||
|
return
|
||||||
|
|
||||||
|
lines_to_keep = self.input_line_ids.filtered(lambda x: x.input_type_id != badge_type)
|
||||||
|
input_lines_vals = [(5, 0, 0)] + [(4, line.id, False) for line in lines_to_keep]
|
||||||
|
input_lines_vals.append((0, 0, {
|
||||||
|
'amount': amount,
|
||||||
|
'input_type_id': badge_type,
|
||||||
|
}))
|
||||||
|
self.update({'input_line_ids': input_lines_vals})
|
||||||
|
|
||||||
|
def _get_input_badges(self):
|
||||||
|
amount = 0.0
|
||||||
|
for bu in self.employee_id.badge_ids.filtered(lambda bu: bu.badge_id.payroll_type == 'fixed'):
|
||||||
|
amount += bu.badge_id.payroll_amount
|
||||||
|
for bu in self.employee_id.badge_ids.filtered(lambda bu: (
|
||||||
|
bu.badge_id.payroll_type == 'period'
|
||||||
|
and self.date_from <= bu.create_date.date() <= self.date_to
|
||||||
|
)):
|
||||||
|
amount += bu.badge_id.payroll_amount
|
||||||
|
return amount
|
||||||
1
hr_payroll_gamification/tests/__init__.py
Executable file
1
hr_payroll_gamification/tests/__init__.py
Executable file
@@ -0,0 +1 @@
|
|||||||
|
from . import test_payroll_badge
|
||||||
122
hr_payroll_gamification/tests/test_payroll_badge.py
Normal file
122
hr_payroll_gamification/tests/test_payroll_badge.py
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
from odoo.tests import common
|
||||||
|
from odoo import fields
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
|
||||||
|
class TestPayroll(common.TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestPayroll, self).setUp()
|
||||||
|
self.wage = 21.50
|
||||||
|
self.employee = self.env['hr.employee'].create({
|
||||||
|
'birthday': '1985-03-14',
|
||||||
|
'country_id': self.ref('base.us'),
|
||||||
|
'department_id': self.ref('hr.dep_rd'),
|
||||||
|
'gender': 'male',
|
||||||
|
'name': 'Jared',
|
||||||
|
'user_id': self.env.user.id,
|
||||||
|
})
|
||||||
|
self.contract = self.env['hr.contract'].create({
|
||||||
|
'name': 'test',
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'type_id': self.ref('hr_contract.hr_contract_type_emp'),
|
||||||
|
'struct_id': self.ref('hr_payroll.structure_base'),
|
||||||
|
'resource_calendar_id': self.ref('resource.resource_calendar_std'),
|
||||||
|
'wage': self.wage,
|
||||||
|
'date_start': '2018-01-01',
|
||||||
|
'state': 'open',
|
||||||
|
'schedule_pay': 'monthly',
|
||||||
|
})
|
||||||
|
|
||||||
|
def test_badge_amounts(self):
|
||||||
|
badge = self.env['gamification.badge'].create({
|
||||||
|
'name': 'test',
|
||||||
|
})
|
||||||
|
badge.payroll_amount = 5.0
|
||||||
|
|
||||||
|
def test_badge_payroll(self):
|
||||||
|
additional_wage = 5.0
|
||||||
|
additional_wage_period = 15.0
|
||||||
|
payslip = self.env['hr.payslip'].create({
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'contract_id': self.contract.id,
|
||||||
|
'date_from': '2018-01-01',
|
||||||
|
'date_to': '2018-01-31',
|
||||||
|
})
|
||||||
|
self.assertEqual(payslip._get_input_badges(self.contract, date(2018, 1, 1), date(2018, 1, 31)), 0.0)
|
||||||
|
payslip.compute_sheet()
|
||||||
|
basic = payslip.details_by_salary_rule_category.filtered(lambda l: l.code == 'GROSS')
|
||||||
|
self.assertTrue(basic)
|
||||||
|
self.assertEqual(basic.total, self.wage)
|
||||||
|
|
||||||
|
badge = self.env['gamification.badge'].create({
|
||||||
|
'name': 'test',
|
||||||
|
'payroll_type': 'fixed',
|
||||||
|
'payroll_amount': additional_wage,
|
||||||
|
})
|
||||||
|
|
||||||
|
badge_user = self.env['gamification.badge.user'].create({
|
||||||
|
'badge_id': badge.id,
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'user_id': self.env.user.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
badge_period = self.env['gamification.badge'].create({
|
||||||
|
'name': 'test period',
|
||||||
|
'payroll_type': 'period',
|
||||||
|
'payroll_amount': additional_wage_period,
|
||||||
|
})
|
||||||
|
|
||||||
|
# Need a specific 'create_date' to test.
|
||||||
|
badge_user_period = self.env['gamification.badge.user'].create({
|
||||||
|
'badge_id': badge_period.id,
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'user_id': self.env.user.id,
|
||||||
|
})
|
||||||
|
self.env.cr.execute('update gamification_badge_user set create_date = \'2018-02-10\' where id = %d;' % (badge_user_period.id, ))
|
||||||
|
badge_user_period = self.env['gamification.badge.user'].browse(badge_user_period.id)
|
||||||
|
|
||||||
|
self.assertEqual(self.employee.badge_ids, badge_user + badge_user_period)
|
||||||
|
|
||||||
|
# Includes only one badge
|
||||||
|
payslip = self.env['hr.payslip'].create({
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'date_from': '2018-01-01',
|
||||||
|
'date_to': '2018-01-31',
|
||||||
|
})
|
||||||
|
# This is crazy, but...
|
||||||
|
res = payslip.onchange_employee_id(date(2018, 1, 1), date(2018, 1, 31), employee_id=self.employee.id, contract_id=self.contract.id)
|
||||||
|
del res['value']['line_ids']
|
||||||
|
res['value']['input_line_ids'] = [(0, 0, l) for l in res['value']['input_line_ids']]
|
||||||
|
res['value']['worked_days_line_ids'] = [(0, 0, l) for l in res['value']['worked_days_line_ids']]
|
||||||
|
payslip.write(res['value'])
|
||||||
|
self.assertTrue(payslip.input_line_ids)
|
||||||
|
payslip.compute_sheet()
|
||||||
|
|
||||||
|
self.assertEqual(payslip._get_input_badges(self.contract, date(2018, 1, 1), date(2018, 1, 31)), additional_wage)
|
||||||
|
|
||||||
|
basic = payslip.details_by_salary_rule_category.filtered(lambda l: l.code == 'GROSS')
|
||||||
|
self.assertTrue(basic)
|
||||||
|
self.assertEqual(basic.total, self.wage + additional_wage)
|
||||||
|
|
||||||
|
# Include both Badges
|
||||||
|
payslip = self.env['hr.payslip'].create({
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'date_from': '2018-02-01',
|
||||||
|
'date_to': '2018-02-25', # Feb...
|
||||||
|
})
|
||||||
|
# This is crazy, but...
|
||||||
|
res = payslip.onchange_employee_id(date(2018, 2, 1), date(2018, 2, 25), employee_id=self.employee.id,
|
||||||
|
contract_id=self.contract.id)
|
||||||
|
del res['value']['line_ids']
|
||||||
|
res['value']['input_line_ids'] = [(0, 0, l) for l in res['value']['input_line_ids']]
|
||||||
|
res['value']['worked_days_line_ids'] = [(0, 0, l) for l in res['value']['worked_days_line_ids']]
|
||||||
|
payslip.write(res['value'])
|
||||||
|
self.assertTrue(payslip.input_line_ids)
|
||||||
|
payslip.compute_sheet()
|
||||||
|
|
||||||
|
self.assertEqual(payslip._get_input_badges(self.contract, date(2018, 2, 1), date(2018, 2, 25)), additional_wage + additional_wage_period)
|
||||||
|
|
||||||
|
basic = payslip.details_by_salary_rule_category.filtered(lambda l: l.code == 'GROSS')
|
||||||
|
self.assertTrue(basic)
|
||||||
|
self.assertEqual(basic.total, self.wage + additional_wage + additional_wage_period)
|
||||||
19
hr_payroll_gamification/views/gamification_views.xml
Normal file
19
hr_payroll_gamification/views/gamification_views.xml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="badge_form_view_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">gamification.badge.form.inherit</field>
|
||||||
|
<field name="model">gamification.badge</field>
|
||||||
|
<field name="priority">20</field>
|
||||||
|
<field name="inherit_id" ref="gamification.badge_form_view"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//sheet" position="inside">
|
||||||
|
<group string="Payroll">
|
||||||
|
<group>
|
||||||
|
<field name="payroll_type"/>
|
||||||
|
<field name="payroll_amount" attrs="{'invisible': [('payroll_type', '=', False)]}"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user