mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'mig/15.0/hr_payroll_gamification' into '15.0-test'
mig/15.0/hr_payroll_gamification into 15.0-test See merge request hibou-io/hibou-odoo/suite!1264
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': '15.0.1.0.0',
|
||||
'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_hibou',
|
||||
],
|
||||
}
|
||||
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>
|
||||
20
hr_payroll_gamification/data/payroll_demo.xml
Normal file
20
hr_payroll_gamification/data/payroll_demo.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?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))
|
||||
37
hr_payroll_gamification/models/payroll.py
Normal file
37
hr_payroll_gamification/models/payroll.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from odoo import api, Command, fields, models
|
||||
|
||||
|
||||
class Payslip(models.Model):
|
||||
_inherit = 'hr.payslip'
|
||||
|
||||
@api.depends('employee_id', 'contract_id', 'struct_id', 'date_from', 'date_to', 'struct_id')
|
||||
def _compute_input_line_ids(self):
|
||||
res = super()._compute_input_line_ids()
|
||||
badge_type = self.env.ref('hr_payroll_gamification.badge_other_input', raise_if_not_found=False)
|
||||
if not badge_type:
|
||||
return res
|
||||
for slip in self:
|
||||
amount = slip._get_input_badges()
|
||||
if not amount:
|
||||
continue
|
||||
slip.update({
|
||||
'input_line_ids': [
|
||||
Command.create({
|
||||
'name': badge_type.name or 'Badges',
|
||||
'amount': amount,
|
||||
'input_type_id': badge_type.id,
|
||||
}),
|
||||
],
|
||||
})
|
||||
return res
|
||||
|
||||
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
|
||||
86
hr_payroll_gamification/tests/test_payroll_badge.py
Normal file
86
hr_payroll_gamification/tests/test_payroll_badge.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from odoo.addons.hr_payroll_hibou.tests import common
|
||||
from odoo import fields
|
||||
from datetime import date
|
||||
|
||||
|
||||
class TestPayslip(common.TestPayslip):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPayslip, self).setUp()
|
||||
self.wage = 2000.00
|
||||
self.structure = self.env.ref('hr_payroll.structure_002')
|
||||
self.structure_type = self.structure.type_id
|
||||
self.structure_type.wage_type = 'monthly'
|
||||
self.employee = self._createEmployee()
|
||||
self.employee.user_id = self.env.user
|
||||
self.contract = self._createContract(self.employee, wage=self.wage)
|
||||
|
||||
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._createPayslip(self.employee,
|
||||
'2018-01-01',
|
||||
'2018-01-31',
|
||||
)
|
||||
payslip.compute_sheet()
|
||||
cats = self._getCategories(payslip)
|
||||
self.assertEqual(cats['BASIC'], 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._createPayslip(self.employee,
|
||||
'2018-01-01',
|
||||
'2018-01-31',)
|
||||
self.assertTrue(payslip.input_line_ids)
|
||||
input_line = payslip.input_line_ids.filtered(lambda l: l.name == 'Badges')
|
||||
self.assertTrue(input_line)
|
||||
self.assertEqual(input_line.amount, additional_wage)
|
||||
payslip.compute_sheet()
|
||||
cats = self._getCategories(payslip)
|
||||
self.assertEqual(cats['BASIC'], self.wage + additional_wage)
|
||||
|
||||
|
||||
# Include both Badges
|
||||
payslip = self._createPayslip(self.employee,
|
||||
'2018-02-01',
|
||||
'2018-02-25',)
|
||||
input_line = payslip.input_line_ids.filtered(lambda l: l.name == 'Badges')
|
||||
self.assertTrue(input_line)
|
||||
self.assertEqual(input_line.amount, additional_wage + additional_wage_period)
|
||||
payslip.compute_sheet()
|
||||
cats = self._getCategories(payslip)
|
||||
self.assertEqual(cats['BASIC'], 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