mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[FIX] hr_payroll_gamification: modernize input line
This commit is contained in:
@@ -4,28 +4,46 @@ from odoo import api, Command, fields, models
|
|||||||
class Payslip(models.Model):
|
class Payslip(models.Model):
|
||||||
_inherit = 'hr.payslip'
|
_inherit = 'hr.payslip'
|
||||||
|
|
||||||
@api.depends('employee_id', 'contract_id', 'struct_id', 'date_from', 'date_to', 'struct_id')
|
@api.model_create_multi
|
||||||
def _compute_input_line_ids(self):
|
def create(self, vals_list):
|
||||||
res = super()._compute_input_line_ids()
|
payslips = super().create(vals_list)
|
||||||
badge_type = self.env.ref('hr_payroll_gamification.badge_other_input', raise_if_not_found=False)
|
draft_slips = payslips.filtered(lambda p: p.employee_id and p.state == 'draft')
|
||||||
if not badge_type:
|
if not draft_slips:
|
||||||
return res
|
return payslips
|
||||||
for slip in self:
|
|
||||||
amount = slip._get_input_badges()
|
draft_slips._update_badges()
|
||||||
if not amount:
|
return payslips
|
||||||
continue
|
|
||||||
slip.update({
|
def write(self, vals):
|
||||||
'input_line_ids': [
|
res = super().write(vals)
|
||||||
Command.create({
|
if 'date_to' in vals or 'date_from' in vals:
|
||||||
'name': badge_type.name or 'Badges',
|
self._update_badges()
|
||||||
'amount': amount,
|
|
||||||
'input_type_id': badge_type.id,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _get_input_badges(self):
|
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
|
amount = 0.0
|
||||||
for bu in self.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
|
amount += bu.badge_id.payroll_amount
|
||||||
|
|||||||
Reference in New Issue
Block a user