[FIX] resource, hr_payroll: fix hours_per_day onchange
In resource, calendar.attendances with a resource_id specified were taken into account to compute the average hours per day. This is incorrect and could lead to hours_per_day being > 24h. Also when hr_payroll is installed, attendance_ids is replaced by normal attendance (those without a resource_id set) in the view. The onchange method was not called to recompute the average hours per day. This commit fixes both issues. closes odoo/odoo#29951
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import models, fields
|
||||
from odoo import models, fields, api
|
||||
from odoo.osv.expression import AND, OR
|
||||
|
||||
|
||||
@@ -16,6 +16,15 @@ class ResourceCalendar(models.Model):
|
||||
'resource.calendar.attendance', 'calendar_id', 'Employees working Time',
|
||||
domain=[('resource_id', '!=', False)])
|
||||
|
||||
def _get_global_attendances(self):
|
||||
res = super(ResourceCalendar, self)._get_global_attendances()
|
||||
res |= self.normal_attendance_ids.filtered(lambda attendance: not attendance.date_from and not attendance.date_to)
|
||||
return res
|
||||
|
||||
# Add a key on the api.onchange decorator
|
||||
@api.onchange('attendance_ids', 'normal_attendance_ids')
|
||||
def _onchange_hours_per_day(self):
|
||||
return super(ResourceCalendar, self)._onchange_hours_per_day()
|
||||
|
||||
class ResourceCalendarAttendance(models.Model):
|
||||
_inherit = 'resource.calendar.attendance'
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
<field name="model">resource.calendar</field>
|
||||
<field name="inherit_id" ref="resource.resource_calendar_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='attendance_ids']" position="replace">
|
||||
<xpath expr="//field[@name='attendance_ids']" position="attributes">
|
||||
<attribute name="invisible">1</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='attendance_ids']" position="after">
|
||||
<field name="normal_attendance_ids"/>
|
||||
</xpath>
|
||||
<xpath expr="//notebook" position="inside">
|
||||
|
||||
@@ -186,9 +186,13 @@ class ResourceCalendar(models.Model):
|
||||
default=lambda self: self._context.get('tz') or self.env.user.tz or 'UTC',
|
||||
help="This field is used in order to define in which timezone the resources will work.")
|
||||
|
||||
|
||||
def _get_global_attendances(self):
|
||||
return self.attendance_ids.filtered(lambda attendance: not attendance.date_from and not attendance.date_to and not attendance.resource_id)
|
||||
|
||||
@api.onchange('attendance_ids')
|
||||
def _onchange_hours_per_day(self):
|
||||
attendances = self.attendance_ids.filtered(lambda attendance: not attendance.date_from and not attendance.date_to)
|
||||
attendances = self._get_global_attendances()
|
||||
hour_count = 0.0
|
||||
for attendance in attendances:
|
||||
hour_count += attendance.hour_to - attendance.hour_from
|
||||
|
||||
Reference in New Issue
Block a user