[REM] hr_payroll_gamification: available in professional

H14528
This commit is contained in:
Mayank Patel
2024-09-11 05:47:31 +00:00
parent d0b1ed2f90
commit 8a029bed93
10 changed files with 0 additions and 226 deletions

View File

@@ -1 +0,0 @@
from . import models

View File

@@ -1,20 +0,0 @@
{
'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',
],
}

View File

@@ -1,10 +0,0 @@
<?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>

View File

@@ -1,20 +0,0 @@
<?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>

View File

@@ -1,2 +0,0 @@
from . import gamification
from . import payroll

View File

@@ -1,12 +0,0 @@
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))

View File

@@ -1,55 +0,0 @@
from odoo import api, Command, fields, models
class Payslip(models.Model):
_inherit = 'hr.payslip'
@api.model_create_multi
def create(self, vals_list):
payslips = super().create(vals_list)
draft_slips = payslips.filtered(lambda p: p.employee_id and p.state == 'draft')
if not draft_slips:
return payslips
draft_slips._update_badges()
return payslips
def write(self, vals):
res = super().write(vals)
if 'date_to' in vals or 'date_from' in vals:
self._update_badges()
return res
def _update_badges(self):
badge_type = self.env.ref('hr_payroll_gamification.badge_other_input', raise_if_not_found=False)
if not badge_type:
return
for payslip in self:
amount = payslip._get_input_badge_amount()
line = payslip.input_line_ids.filtered(lambda l: l.input_type_id == badge_type)
command = []
if line and not amount:
command.append((2, line.id, False))
elif line and amount:
command.append((1, line.id, {
'amount': amount,
}))
elif amount:
command.append((0, 0, {
'name': badge_type.name,
'amount': amount,
'input_type_id': badge_type.id,
}))
if command:
payslip.update({'input_line_ids': command})
def _get_input_badge_amount(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

View File

@@ -1 +0,0 @@
from . import test_payroll_badge

View File

@@ -1,86 +0,0 @@
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)

View File

@@ -1,19 +0,0 @@
<?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>