diff --git a/hr_payroll_gamification/__init__.py b/hr_payroll_gamification/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/hr_payroll_gamification/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_payroll_gamification/__manifest__.py b/hr_payroll_gamification/__manifest__.py new file mode 100755 index 00000000..4de55d3d --- /dev/null +++ b/hr_payroll_gamification/__manifest__.py @@ -0,0 +1,20 @@ +{ + 'name': 'Payroll Gamification', + 'description': 'Payroll Gamification', + 'version': '15.0.1.0.0', + 'website': 'https://hibou.io/', + 'author': 'Hibou Corp. ', + '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', + ], +} diff --git a/hr_payroll_gamification/data/payroll_data.xml b/hr_payroll_gamification/data/payroll_data.xml new file mode 100644 index 00000000..f4ac1ed8 --- /dev/null +++ b/hr_payroll_gamification/data/payroll_data.xml @@ -0,0 +1,10 @@ + + + + + + Badges + BADGES + + + \ No newline at end of file diff --git a/hr_payroll_gamification/data/payroll_demo.xml b/hr_payroll_gamification/data/payroll_demo.xml new file mode 100644 index 00000000..b79992de --- /dev/null +++ b/hr_payroll_gamification/data/payroll_demo.xml @@ -0,0 +1,20 @@ + + + + + python + +result = inputs.BADGES.amount > 0.0 if inputs.BADGES else False + + code + +result = inputs.BADGES.amount if inputs.BADGES else 0 + + BADGES + + Badges + + + + + diff --git a/hr_payroll_gamification/models/__init__.py b/hr_payroll_gamification/models/__init__.py new file mode 100644 index 00000000..4ce66a41 --- /dev/null +++ b/hr_payroll_gamification/models/__init__.py @@ -0,0 +1,2 @@ +from . import gamification +from . import payroll diff --git a/hr_payroll_gamification/models/gamification.py b/hr_payroll_gamification/models/gamification.py new file mode 100644 index 00000000..ac1538b7 --- /dev/null +++ b/hr_payroll_gamification/models/gamification.py @@ -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)) diff --git a/hr_payroll_gamification/models/payroll.py b/hr_payroll_gamification/models/payroll.py new file mode 100644 index 00000000..06aecb0b --- /dev/null +++ b/hr_payroll_gamification/models/payroll.py @@ -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 diff --git a/hr_payroll_gamification/tests/__init__.py b/hr_payroll_gamification/tests/__init__.py new file mode 100755 index 00000000..ce4bbfce --- /dev/null +++ b/hr_payroll_gamification/tests/__init__.py @@ -0,0 +1 @@ +from . import test_payroll_badge diff --git a/hr_payroll_gamification/tests/test_payroll_badge.py b/hr_payroll_gamification/tests/test_payroll_badge.py new file mode 100644 index 00000000..c2a1dd6e --- /dev/null +++ b/hr_payroll_gamification/tests/test_payroll_badge.py @@ -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) diff --git a/hr_payroll_gamification/views/gamification_views.xml b/hr_payroll_gamification/views/gamification_views.xml new file mode 100644 index 00000000..17fe63a8 --- /dev/null +++ b/hr_payroll_gamification/views/gamification_views.xml @@ -0,0 +1,19 @@ + + + + gamification.badge.form.inherit + gamification.badge + 20 + + + + + + + + + + + + + \ No newline at end of file