From fd8e413198e76ba373c05155553f389db28d27cf Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 5 Jan 2020 13:30:22 -0800 Subject: [PATCH] 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