[IMP] hr_work_entry_contract: Lessen calls to _get_bypassing_work_entry_type
Allows to reduce the number of queries of 4*N, with N=number of contracts. closes odoo/odoo#67471 Related: odoo/upgrade#2255 Related: odoo/enterprise#16842 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -31,7 +31,10 @@ class HrContract(models.Model):
|
||||
def _get_more_vals_leave_interval(self, interval, leaves):
|
||||
return []
|
||||
|
||||
def _get_interval_leave_work_entry_type(self, interval, leaves):
|
||||
def _get_bypassing_work_entry_type(self):
|
||||
return self.env['hr.work.entry.type']
|
||||
|
||||
def _get_interval_leave_work_entry_type(self, interval, leaves, bypassing):
|
||||
# returns the work entry time related to the leave that
|
||||
# includes the whole interval.
|
||||
# Overriden in hr_work_entry_contract_holiday to select the
|
||||
@@ -45,6 +48,7 @@ class HrContract(models.Model):
|
||||
|
||||
def _get_contract_work_entries_values(self, date_start, date_stop):
|
||||
contract_vals = []
|
||||
bypassing_work_entry_type = self._get_bypassing_work_entry_type()
|
||||
for contract in self:
|
||||
employee = contract.employee_id
|
||||
calendar = contract.resource_calendar_id
|
||||
@@ -129,7 +133,7 @@ class HrContract(models.Model):
|
||||
# sql constraint error
|
||||
if interval[0] == interval[1]: # if start == stop
|
||||
continue
|
||||
leave_entry_type = contract._get_interval_leave_work_entry_type(interval, leaves)
|
||||
leave_entry_type = contract._get_interval_leave_work_entry_type(interval, leaves, bypassing_work_entry_type)
|
||||
interval_start = interval[0].astimezone(pytz.utc).replace(tzinfo=None)
|
||||
interval_stop = interval[1].astimezone(pytz.utc).replace(tzinfo=None)
|
||||
contract_vals += [dict([
|
||||
|
||||
@@ -40,10 +40,7 @@ class HrContract(models.Model):
|
||||
result.append(('leave_id', leave[2].holiday_id.id))
|
||||
return result
|
||||
|
||||
def _get_bypassing_work_entry_type(self):
|
||||
return self.env['hr.work.entry.type']
|
||||
|
||||
def _get_interval_leave_work_entry_type(self, interval, leaves):
|
||||
def _get_interval_leave_work_entry_type(self, interval, leaves, bypassing):
|
||||
# returns the work entry time related to the leave that
|
||||
# includes the whole interval.
|
||||
# Overriden in hr_work_entry_contract_holiday to select the
|
||||
@@ -56,9 +53,8 @@ class HrContract(models.Model):
|
||||
rc_leave = False
|
||||
|
||||
# Example: In CP200: Long term sick > Public Holidays (which is global)
|
||||
bypassing_work_entry_types = self._get_bypassing_work_entry_type()
|
||||
if bypassing_work_entry_types:
|
||||
bypassing_rc_leave = [l for l in including_holiday_rcleaves if l.holiday_id.holiday_status_id.work_entry_type_id in bypassing_work_entry_types]
|
||||
if bypassing:
|
||||
bypassing_rc_leave = [l for l in including_holiday_rcleaves if l.holiday_id.holiday_status_id.work_entry_type_id in bypassing]
|
||||
else:
|
||||
bypassing_rc_leave = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user