mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
MIG hr_payroll_gamification to Odoo 13 (and Odoo 13 Enterprise's Payroll semantics)
This commit is contained in:
@@ -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. <hello@hibou.io>',
|
||||
'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',
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
<?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
|
||||
<!-- Salary Other Input -->
|
||||
<record id="badge_other_input" model="hr.payslip.input.type">
|
||||
<field name="name">Badges</field>
|
||||
<field name="code">BADGES</field>
|
||||
</record>
|
||||
|
||||
</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>
|
||||
16
hr_payroll_gamification/data/payroll_demo.xml
Normal file
16
hr_payroll_gamification/data/payroll_demo.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user