From 238eb46eaeae28be6391378f9fb05756a916719a Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Wed, 15 May 2019 17:38:09 -0700 Subject: [PATCH 1/5] Initial commit of `hr_payroll_gamification` for 11.0 --- hr_payroll_gamification/__init__.py | 1 + hr_payroll_gamification/__manifest__.py | 17 +++ hr_payroll_gamification/data/payroll_data.xml | 30 ++++ hr_payroll_gamification/models/__init__.py | 2 + .../models/gamification.py | 11 ++ hr_payroll_gamification/models/payroll.py | 17 +++ hr_payroll_gamification/tests/__init__.py | 1 + .../tests/test_payroll_badge.py | 137 ++++++++++++++++++ .../views/gamification_views.xml | 19 +++ 9 files changed, 235 insertions(+) create mode 100644 hr_payroll_gamification/__init__.py create mode 100755 hr_payroll_gamification/__manifest__.py create mode 100644 hr_payroll_gamification/data/payroll_data.xml create mode 100644 hr_payroll_gamification/models/__init__.py create mode 100644 hr_payroll_gamification/models/gamification.py create mode 100644 hr_payroll_gamification/models/payroll.py create mode 100755 hr_payroll_gamification/tests/__init__.py create mode 100644 hr_payroll_gamification/tests/test_payroll_badge.py create mode 100644 hr_payroll_gamification/views/gamification_views.xml 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..277008b9 --- /dev/null +++ b/hr_payroll_gamification/__manifest__.py @@ -0,0 +1,17 @@ +{ + 'name': 'Payroll Gamification', + 'description': 'Payroll Gamification', + 'version': '11.0.1.0.1', + 'website': 'https://hibou.io/', + 'author': 'Hibou Corp. ', + 'license': 'AGPL-3', + 'category': 'Human Resources', + 'data': [ + 'data/payroll_data.xml', + 'views/gamification_views.xml', + ], + 'depends': [ + 'hr_gamification', + 'hr_payroll', + ], +} diff --git a/hr_payroll_gamification/data/payroll_data.xml b/hr_payroll_gamification/data/payroll_data.xml new file mode 100644 index 00000000..ca89d7c4 --- /dev/null +++ b/hr_payroll_gamification/data/payroll_data.xml @@ -0,0 +1,30 @@ + + + + + + Badge Bonus + + BADGES + + code + +result = 0.0 +if inputs.BADGES: + result = inputs.BADGES.amount + + + + + + Badges + BADGES + + + + + + + + + \ No newline at end of file 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..9a32f3f8 --- /dev/null +++ b/hr_payroll_gamification/models/gamification.py @@ -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)) diff --git a/hr_payroll_gamification/models/payroll.py b/hr_payroll_gamification/models/payroll.py new file mode 100644 index 00000000..21d0665b --- /dev/null +++ b/hr_payroll_gamification/models/payroll.py @@ -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')) 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..24ab278d --- /dev/null +++ b/hr_payroll_gamification/tests/test_payroll_badge.py @@ -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) 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 From a76a8071fabe4ccc189548b49ddb2a57ae3429af Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Fri, 24 May 2019 11:54:16 -0600 Subject: [PATCH 2/5] IMP `hr_payroll_gamification` Fix tests and implement 'per-period' badges. --- .../models/gamification.py | 1 + hr_payroll_gamification/models/payroll.py | 12 +- .../tests/test_payroll_badge.py | 110 ++++++++---------- 3 files changed, 58 insertions(+), 65 deletions(-) diff --git a/hr_payroll_gamification/models/gamification.py b/hr_payroll_gamification/models/gamification.py index 9a32f3f8..ac1538b7 100644 --- a/hr_payroll_gamification/models/gamification.py +++ b/hr_payroll_gamification/models/gamification.py @@ -7,5 +7,6 @@ class GamificationBadge(models.Model): 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 index 21d0665b..3ac9c10e 100644 --- a/hr_payroll_gamification/models/payroll.py +++ b/hr_payroll_gamification/models/payroll.py @@ -9,9 +9,17 @@ class Payslip(models.Model): res = super(Payslip, self).get_inputs(contracts, date_from, date_to) for contract in contracts: for input in res: - if input.get('code') == 'BADGES': + if input.get('contract_id') == contract.id and 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')) + amount = 0.0 + for bu in contract.employee_id.badge_ids.filtered(lambda bu: bu.badge_id.payroll_type == 'fixed'): + amount += bu.badge_id.payroll_amount + for bu in contract.employee_id.badge_ids.filtered(lambda bu: ( + bu.badge_id.payroll_type == 'period' + and date_from <= bu.create_date <= date_to + )): + amount += bu.badge_id.payroll_amount + return amount diff --git a/hr_payroll_gamification/tests/test_payroll_badge.py b/hr_payroll_gamification/tests/test_payroll_badge.py index 24ab278d..961eebd6 100644 --- a/hr_payroll_gamification/tests/test_payroll_badge.py +++ b/hr_payroll_gamification/tests/test_payroll_badge.py @@ -35,6 +35,7 @@ class TestPayroll(common.TransactionCase): 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, @@ -59,79 +60,62 @@ class TestPayroll(common.TransactionCase): 'user_id': self.env.user.id, }) - self.assertEqual(self.employee.badge_ids, badge_user) + 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, - '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) + # This is crazy, but... + res = payslip.onchange_employee_id('2018-01-01', '2018-01-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, '2018-01-01', '2018-01-31'), 5.0) - self.assertTrue(payslip.contract_id) + + self.assertEqual(payslip._get_input_badges(self.contract, '2018-01-01', '2018-01-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('2018-02-01', '2018-02-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, '2018-02-01', '2018-02-25'), additional_wage + additional_wage_period) - - - - # 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) + 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) From 75df8e56dbd40630a111098fa02cf0906195ef87 Mon Sep 17 00:00:00 2001 From: Bhoomi Date: Tue, 15 Oct 2019 12:21:09 -0400 Subject: [PATCH 3/5] MIG `hr_payroll_gamification` For Odoo 12.0 --- hr_payroll_gamification/__manifest__.py | 2 +- hr_payroll_gamification/models/payroll.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hr_payroll_gamification/__manifest__.py b/hr_payroll_gamification/__manifest__.py index 277008b9..1c261450 100755 --- a/hr_payroll_gamification/__manifest__.py +++ b/hr_payroll_gamification/__manifest__.py @@ -1,7 +1,7 @@ { 'name': 'Payroll Gamification', 'description': 'Payroll Gamification', - 'version': '11.0.1.0.1', + 'version': '12.0.1.0.1', 'website': 'https://hibou.io/', 'author': 'Hibou Corp. ', 'license': 'AGPL-3', diff --git a/hr_payroll_gamification/models/payroll.py b/hr_payroll_gamification/models/payroll.py index 3ac9c10e..a652053e 100644 --- a/hr_payroll_gamification/models/payroll.py +++ b/hr_payroll_gamification/models/payroll.py @@ -19,7 +19,7 @@ class Payslip(models.Model): amount += bu.badge_id.payroll_amount for bu in contract.employee_id.badge_ids.filtered(lambda bu: ( bu.badge_id.payroll_type == 'period' - and date_from <= bu.create_date <= date_to + and date_from <= str(bu.create_date) <= date_to )): amount += bu.badge_id.payroll_amount return amount From 441c084d845ba7acdc5cbecac5419810ea00a028 Mon Sep 17 00:00:00 2001 From: Bhoomi Date: Thu, 17 Oct 2019 12:59:42 -0400 Subject: [PATCH 4/5] Fix `hr_payroll_gamification` Resolve datetime error on payslip. --- hr_payroll_gamification/models/payroll.py | 2 +- hr_payroll_gamification/tests/test_payroll_badge.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hr_payroll_gamification/models/payroll.py b/hr_payroll_gamification/models/payroll.py index a652053e..d6d53a40 100644 --- a/hr_payroll_gamification/models/payroll.py +++ b/hr_payroll_gamification/models/payroll.py @@ -19,7 +19,7 @@ class Payslip(models.Model): amount += bu.badge_id.payroll_amount for bu in contract.employee_id.badge_ids.filtered(lambda bu: ( bu.badge_id.payroll_type == 'period' - and date_from <= str(bu.create_date) <= date_to + and date_from <= bu.create_date.date() <= date_to )): amount += bu.badge_id.payroll_amount return amount diff --git a/hr_payroll_gamification/tests/test_payroll_badge.py b/hr_payroll_gamification/tests/test_payroll_badge.py index 961eebd6..ae996fb0 100644 --- a/hr_payroll_gamification/tests/test_payroll_badge.py +++ b/hr_payroll_gamification/tests/test_payroll_badge.py @@ -1,5 +1,6 @@ from odoo.tests import common from odoo import fields +from datetime import date class TestPayroll(common.TransactionCase): @@ -42,7 +43,7 @@ class TestPayroll(common.TransactionCase): '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) + 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) @@ -84,7 +85,7 @@ class TestPayroll(common.TransactionCase): 'date_to': '2018-01-31', }) # This is crazy, but... - res = payslip.onchange_employee_id('2018-01-01', '2018-01-31', employee_id=self.employee.id, contract_id=self.contract.id) + 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']] @@ -92,7 +93,7 @@ class TestPayroll(common.TransactionCase): self.assertTrue(payslip.input_line_ids) payslip.compute_sheet() - self.assertEqual(payslip._get_input_badges(self.contract, '2018-01-01', '2018-01-31'), additional_wage) + 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) @@ -105,7 +106,7 @@ class TestPayroll(common.TransactionCase): 'date_to': '2018-02-25', # Feb... }) # This is crazy, but... - res = payslip.onchange_employee_id('2018-02-01', '2018-02-25', employee_id=self.employee.id, + 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']] @@ -114,7 +115,7 @@ class TestPayroll(common.TransactionCase): self.assertTrue(payslip.input_line_ids) payslip.compute_sheet() - self.assertEqual(payslip._get_input_badges(self.contract, '2018-02-01', '2018-02-25'), additional_wage + additional_wage_period) + 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) From 77998a46a86eaef423839e9ad7d8598488645cd0 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 5 Jan 2020 13:30:22 -0800 Subject: [PATCH 5/5] MIG `hr_payroll_gamification` to Odoo 13 (and Odoo 13 Enterprise's Payroll semantics) --- hr_payroll_gamification/__manifest__.py | 5 ++- hr_payroll_gamification/data/payroll_data.xml | 30 +++------------ hr_payroll_gamification/data/payroll_demo.xml | 16 ++++++++ hr_payroll_gamification/models/payroll.py | 37 +++++++++++++------ 4 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 hr_payroll_gamification/data/payroll_demo.xml diff --git a/hr_payroll_gamification/__manifest__.py b/hr_payroll_gamification/__manifest__.py index 1c261450..19f976d5 100755 --- a/hr_payroll_gamification/__manifest__.py +++ b/hr_payroll_gamification/__manifest__.py @@ -1,7 +1,7 @@ { 'name': 'Payroll Gamification', 'description': 'Payroll Gamification', - 'version': '12.0.1.0.1', + 'version': '13.0.1.0.1', 'website': 'https://hibou.io/', 'author': 'Hibou Corp. ', 'license': 'AGPL-3', @@ -10,6 +10,9 @@ 'data/payroll_data.xml', 'views/gamification_views.xml', ], + 'demo': [ + 'data/payroll_demo.xml', + ], 'depends': [ 'hr_gamification', 'hr_payroll', diff --git a/hr_payroll_gamification/data/payroll_data.xml b/hr_payroll_gamification/data/payroll_data.xml index ca89d7c4..f4ac1ed8 100644 --- a/hr_payroll_gamification/data/payroll_data.xml +++ b/hr_payroll_gamification/data/payroll_data.xml @@ -1,30 +1,10 @@ - - - Badge Bonus - - BADGES - - code - -result = 0.0 -if inputs.BADGES: - result = inputs.BADGES.amount + + + Badges + BADGES + - - - - - 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..f5e955a2 --- /dev/null +++ b/hr_payroll_gamification/data/payroll_demo.xml @@ -0,0 +1,16 @@ + + + + + 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/payroll.py b/hr_payroll_gamification/models/payroll.py index d6d53a40..567f9652 100644 --- a/hr_payroll_gamification/models/payroll.py +++ b/hr_payroll_gamification/models/payroll.py @@ -4,22 +4,37 @@ 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('contract_id') == contract.id and input.get('code') == 'BADGES': - input['amount'] = self._get_input_badges(contract, date_from, date_to) + @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 _get_input_badges(self, contract, date_from, date_to): + 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 contract.employee_id.badge_ids.filtered(lambda bu: bu.badge_id.payroll_type == 'fixed'): + 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 contract.employee_id.badge_ids.filtered(lambda bu: ( + for bu in self.employee_id.badge_ids.filtered(lambda bu: ( bu.badge_id.payroll_type == 'period' - and date_from <= bu.create_date.date() <= date_to + and self.date_from <= bu.create_date.date() <= self.date_to )): amount += bu.badge_id.payroll_amount return amount