[IMP] hr-luncheon-voucher: move resource code to dedicated addon

Moves code in add-on hr_effective_attendance_period
This commit is contained in:
Stéphan Sainléger
2023-01-24 22:24:57 +01:00
parent c7e1c8de0b
commit 68788e3950
3 changed files with 1 additions and 65 deletions

View File

@@ -2,7 +2,7 @@
{ {
"name": "HR Luncheon Voucher", "name": "HR Luncheon Voucher",
"category": "Human Resources", "category": "Human Resources",
"version": "14.0.1.2.0", "version": "14.0.2.0.0",
"summary": "Manage luncheon vouchers credit and distribution", "summary": "Manage luncheon vouchers credit and distribution",
"author": "Elabore", "author": "Elabore",
"website": "https://elabore.coop/", "website": "https://elabore.coop/",

View File

@@ -3,6 +3,5 @@
from . import calendar_event_type from . import calendar_event_type
from . import hr_employee from . import hr_employee
from . import hr_lv_allocation from . import hr_lv_allocation
from . import resource
from . import res_company from . import res_company
from . import res_config_settings from . import res_config_settings

View File

@@ -1,63 +0,0 @@
from datetime import timedelta
import math
from odoo import models, fields
class ResourceCalendar(models.Model):
_inherit = "resource.calendar"
def _retrieve_day_matching_attendances(self, day):
domain = [
("calendar_id", "=", self.id),
("dayofweek", "=", day.weekday()),
("effective_attendance_period", "=", True)
]
if self.two_weeks_calendar:
# Employee has Even/Odd weekly calendar
week_type = 1 if int(math.floor((day.toordinal() - 1) / 7) % 2) else 0
domain.append(("week_type", "=", week_type))
result = self.env["resource.calendar.attendance"].search(domain)
return result
def is_working_day(self, day):
day_attendances = self._retrieve_day_matching_attendances(day)
if len(day_attendances) == 0:
# This day of the week is not supposed to be a working day
return False
else:
# This day of the week is supposed to be a working day
return True
def is_full_working_day(self, day):
day_attendances = self._retrieve_day_matching_attendances(day)
morning_worked = len(day_attendances.filtered(lambda x: x.day_period == "morning")) > 0
afternoon_worked = len(day_attendances.filtered(lambda x: x.day_period == "afternoon")) > 0
return morning_worked and afternoon_worked
def _is_worked_attendance(self, resource, day, attendance):
attendance_start = fields.Datetime.to_datetime(day.date()) + timedelta(hours=attendance.hour_from)
attendance_end = fields.Datetime.to_datetime(day.date()) + timedelta(hours=attendance.hour_to)
resource_leaves = self.env["resource.calendar.leaves"].search([("resource_id", "=", resource.id), ("date_from", "<=", attendance_start), ("date_to", ">=", attendance_end)])
if resource_leaves:
return False
else:
# a part or the whole attendance is worked
return True
def is_worked_day(self, resource, day):
day_attendances = self._retrieve_day_matching_attendances(day)
# If at least one attendance is worked, return True
for attendance in day_attendances:
if self._is_worked_attendance(resource, day, attendance):
return True
return False
def all_attendances_worked(self, resource, day):
day_attendances = self._retrieve_day_matching_attendances(day)
# If at least one attendance is not worked, return False
for attendance in day_attendances:
if not self._is_worked_attendance(resource, day, attendance):
return False
return True