mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Initial commit of hr_payroll_gamification for 11.0
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
|
||||
17
hr_payroll_gamification/__manifest__.py
Executable file
17
hr_payroll_gamification/__manifest__.py
Executable file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
'name': 'Payroll Gamification',
|
||||
'description': 'Payroll Gamification',
|
||||
'version': '11.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',
|
||||
],
|
||||
'depends': [
|
||||
'hr_gamification',
|
||||
'hr_payroll',
|
||||
],
|
||||
}
|
||||
30
hr_payroll_gamification/data/payroll_data.xml
Normal file
30
hr_payroll_gamification/data/payroll_data.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="salary_rule_badges" model="hr.salary.rule">
|
||||
<field name="name">Badge Bonus</field>
|
||||
<field name="category_id" ref="hr_payroll.BASIC"/>
|
||||
<field name="code">BADGES</field>
|
||||
<field name="sequence" eval="5"/>
|
||||
<field name="amount_select">code</field>
|
||||
<field name="amount_python_compute">
|
||||
result = 0.0
|
||||
if inputs.BADGES:
|
||||
result = inputs.BADGES.amount
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="salary_rule_input_badges" model="hr.rule.input">
|
||||
<field name="name">Badges</field>
|
||||
<field name="code">BADGES</field>
|
||||
<field name="input_id" ref="salary_rule_badges"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_payroll.structure_base" model="hr.payroll.structure">
|
||||
<field eval="[(4, ref('hr_payroll_gamification.salary_rule_badges'))]" name="rule_ids"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</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
|
||||
11
hr_payroll_gamification/models/gamification.py
Normal file
11
hr_payroll_gamification/models/gamification.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class GamificationBadge(models.Model):
|
||||
_inherit = 'gamification.badge'
|
||||
|
||||
payroll_type = fields.Selection([
|
||||
('', 'None'),
|
||||
('fixed', 'Fixed'),
|
||||
], string='Payroll Type')
|
||||
payroll_amount = fields.Float(string='Payroll Amount', digits=(10, 4))
|
||||
17
hr_payroll_gamification/models/payroll.py
Normal file
17
hr_payroll_gamification/models/payroll.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class Payslip(models.Model):
|
||||
_inherit = 'hr.payslip'
|
||||
|
||||
@api.model
|
||||
def get_inputs(self, contracts, date_from, date_to):
|
||||
res = super(Payslip, self).get_inputs(contracts, date_from, date_to)
|
||||
for contract in contracts:
|
||||
for input in res:
|
||||
if input.get('code') == 'BADGES':
|
||||
input['amount'] = self._get_input_badges(contract, date_from, date_to)
|
||||
return res
|
||||
|
||||
def _get_input_badges(self, contract, date_from, date_to):
|
||||
return sum(contract.employee_id.badge_ids.filtered(lambda l: l.badge_id.payroll_type == 'fixed').mapped('badge_id.payroll_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
|
||||
137
hr_payroll_gamification/tests/test_payroll_badge.py
Normal file
137
hr_payroll_gamification/tests/test_payroll_badge.py
Normal file
@@ -0,0 +1,137 @@
|
||||
from odoo.tests import common
|
||||
from odoo import fields
|
||||
|
||||
|
||||
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
|
||||
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, '2018-01-01', '2018-01-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,
|
||||
})
|
||||
|
||||
self.assertEqual(self.employee.badge_ids, badge_user)
|
||||
|
||||
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',
|
||||
})
|
||||
payslip.onchange_employee_id('2018-01-01', '2018-01-31', employee_id=self.employee.id, contract_id=self.contract.id)
|
||||
payslip.compute_sheet()
|
||||
self.assertEqual(payslip._get_input_badges(self.contract, '2018-01-01', '2018-01-31'), 5.0)
|
||||
self.assertTrue(payslip.contract_id)
|
||||
basic = payslip.details_by_salary_rule_category.filtered(lambda l: l.code == 'GROSS')
|
||||
self.assertTrue(basic)
|
||||
self.assertEqual(basic.total, self.wage + additional_wage)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# def test_payroll_rate_multicompany(self):
|
||||
# test_rate_other = self.env['hr.payroll.rate'].create({
|
||||
# 'name': 'Test Rate',
|
||||
# 'code': 'TEST',
|
||||
# 'rate': 1.65,
|
||||
# 'date_from': '2018-01-01',
|
||||
# 'company_id': self.company_other.id,
|
||||
# })
|
||||
# rate = self.payslip.get_rate('TEST')
|
||||
# self.assertFalse(rate)
|
||||
# test_rate = self.env['hr.payroll.rate'].create({
|
||||
# 'name': 'Test Rate',
|
||||
# 'code': 'TEST',
|
||||
# 'rate': 1.65,
|
||||
# 'date_from': '2018-01-01',
|
||||
# })
|
||||
#
|
||||
# rate = self.payslip.get_rate('TEST')
|
||||
# self.assertEqual(rate, test_rate)
|
||||
#
|
||||
# test_rate_more_specific = self.env['hr.payroll.rate'].create({
|
||||
# 'name': 'Test Rate Specific',
|
||||
# 'code': 'TEST',
|
||||
# 'rate': 1.65,
|
||||
# 'date_from': '2018-01-01',
|
||||
# 'company_id': self.payslip.company_id.id,
|
||||
# })
|
||||
# rate = self.payslip.get_rate('TEST')
|
||||
# self.assertEqual(rate, test_rate_more_specific)
|
||||
#
|
||||
# def test_payroll_rate_newer(self):
|
||||
# test_rate_old = self.env['hr.payroll.rate'].create({
|
||||
# 'name': 'Test Rate',
|
||||
# 'code': 'TEST',
|
||||
# 'rate': 1.65,
|
||||
# 'date_from': '2018-01-01',
|
||||
# })
|
||||
# test_rate = self.env['hr.payroll.rate'].create({
|
||||
# 'name': 'Test Rate',
|
||||
# 'code': 'TEST',
|
||||
# 'rate': 2.65,
|
||||
# 'date_from': '2019-01-01',
|
||||
# })
|
||||
#
|
||||
# rate = self.payslip.get_rate('TEST')
|
||||
# self.assertEqual(rate, test_rate)
|
||||
#
|
||||
# def test_payroll_rate_precision(self):
|
||||
# test_rate = self.env['hr.payroll.rate'].create({
|
||||
# 'name': 'Test Rate',
|
||||
# 'code': 'TEST',
|
||||
# 'rate': 2.65001,
|
||||
# 'date_from': '2019-01-01',
|
||||
# })
|
||||
# self.assertEqual(round(test_rate.rate * 100000), 265001.0)
|
||||
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