Ejemplo n.º 1
0
    def clean_date(self):
        now = datetime.datetime.now()
        data = self.cleaned_data.get('date')
        if not data:
            return data

        # Check that selected date is not in the past
        if data < now.date():
            raise ValidationError(
                _('Sorry, you can\'t make reservations for past days.'))

        service_provider = self.service.service_provider

        # Check if it's overlapping with working days (convert date to weekday and check if it's in the week_days list)
        workinghrs = WorkingHours.get_for_day(service_provider, data.weekday())
        if workinghrs is None:
            raise ValidationError(
                _('Sorry, you can\'t make a reservation on a non working day.')
            )

        # Check if it's overlapping with absences
        if Absence.is_absent_on(service_provider, data):
            raise ValidationError(
                _('Sorry, the provider is absent on this day.'))

        return data
Ejemplo n.º 2
0
def getWorkingHours(provider, service_id, date):
    workinghrs = WorkingHours.get_for_day(provider, date.weekday())

    employees_workinghours_on_curr_service = EmployeeWorkingHours.objects.filter(service=service_id)
    maxTime_from = employees_workinghours_on_curr_service[0].time_from
    maxTime_to = employees_workinghours_on_curr_service[0].time_to
    for employee_workinghours in employees_workinghours_on_curr_service:
        if maxTime_from > employee_workinghours.time_from:
            maxTime_from = employee_workinghours.time_from
    if maxTime_to < employee_workinghours.time_to:
        maxTime_to = employee_workinghours.time_to

    events = []

    # Check if provider is working on this date
    if workinghrs is None or Absence.is_absent_on(provider, date):
        return [
            {
                "title": ugettext(EVENT_TITLE_CLOSED_WHOLE_DAY),
                "start": encodeDatetime(date),
                "end": encodeDatetime(date + datetime.timedelta(days=1)),
                "color": EVENT_CLOSED_COLOR,
            }
        ]

        # Start
    events.append(
        {
            "title": ugettext(EVENT_TITLE_CLOSED),
            "start": encodeDatetime(date),
            "end": encodeDatetime(datetime.datetime.combine(date, maxTime_from)),
            "color": EVENT_PAUSE_COLOR,
        }
    )

    # End
    events.append(
        {
            "title": ugettext(EVENT_TITLE_CLOSED),
            "start": encodeDatetime(datetime.datetime.combine(date, maxTime_to)),
            "end": encodeDatetime(date + datetime.timedelta(days=1)),
            "color": EVENT_PAUSE_COLOR,
        }
    )

    for wrkbrk in workinghrs.breaks.all():
        events.append(
            {
                "title": ugettext(EVENT_TITLE_CLOSED),
                "start": encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_from)),
                "end": encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_to)),
                "color": EVENT_PAUSE_COLOR,
            }
        )

    return events
Ejemplo n.º 3
0
def getWorkingHours(provider, date):
    workinghrs = WorkingHours.get_for_day(provider, date.weekday())
    events = []

    # Check if provider is working on this date
    if workinghrs is None or Absence.is_absent_on(provider, date):
        return [{
            'title': ugettext(EVENT_TITLE_CLOSED_WHOLE_DAY),
            'start': encodeDatetime(date),
            'end': encodeDatetime(date + datetime.timedelta(days=1)),
            'color': EVENT_CLOSED_COLOR
        }]

    # Start
    events.append({
        'title':
        ugettext(EVENT_TITLE_CLOSED),
        'start':
        encodeDatetime(date),
        'end':
        encodeDatetime(datetime.datetime.combine(date, workinghrs.time_from)),
        'color':
        EVENT_PAUSE_COLOR
    })

    # End
    events.append({
        'title':
        ugettext(EVENT_TITLE_CLOSED),
        'start':
        encodeDatetime(datetime.datetime.combine(date, workinghrs.time_to)),
        'end':
        encodeDatetime(date + datetime.timedelta(days=1)),
        'color':
        EVENT_PAUSE_COLOR
    })

    for wrkbrk in workinghrs.breaks.all():
        events.append({
            'title':
            ugettext(EVENT_TITLE_CLOSED),
            'start':
            encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_from)),
            'end':
            encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_to)),
            'color':
            EVENT_PAUSE_COLOR
        })

    return events
Ejemplo n.º 4
0
    def clean_date(self):
        now = datetime.datetime.now()
        data = self.cleaned_data.get('date')
        if not data:
            return data

        # Check that selected date is not in the past
        if data < now.date():
            raise ValidationError(_('Sorry, you can\'t make reservations for past days.'))

        service_provider = self.service.service_provider

        # Check if it's overlapping with working days (convert date to weekday and check if it's in the week_days list)
        workinghrs = WorkingHours.get_for_day(service_provider, data.weekday())
        if workinghrs is None:
            raise ValidationError(_('Sorry, you can\'t make a reservation on a non working day.'))

        # Check if it's overlapping with absences
        if Absence.is_absent_on(service_provider, data):
            raise ValidationError(_('Sorry, the provider is absent on this day.'))

        return data
Ejemplo n.º 5
0
def getWorkingHours(provider, date):
	workinghrs = WorkingHours.get_for_day(provider, date.weekday())
	events = []

	# Check if provider is working on this date
	if workinghrs is None or Absence.is_absent_on(provider, date):
		return [{
			'title': ugettext(EVENT_TITLE_CLOSED_WHOLE_DAY),
			'start': encodeDatetime(date),
			'end': encodeDatetime(date + datetime.timedelta(days=1)),
			'color': EVENT_CLOSED_COLOR
		}]

	# Start
	events.append({
		'title': ugettext(EVENT_TITLE_CLOSED),
		'start': encodeDatetime(date),
		'end': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_from)),
		'color': EVENT_PAUSE_COLOR
	})

	# End
	events.append({
		'title': ugettext(EVENT_TITLE_CLOSED),
		'start': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_to)),
		'end': encodeDatetime(date + datetime.timedelta(days=1)),
		'color': EVENT_PAUSE_COLOR
	})

	for wrkbrk in workinghrs.breaks.all():
		events.append({
			'title': ugettext(EVENT_TITLE_CLOSED),
			'start': encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_from)),
			'end': encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_to)),
			'color': EVENT_PAUSE_COLOR
		})

	return events
Ejemplo n.º 6
0
def getEmployeeWorkingHours(provider, service_id, employee_id, date):
    workinghrs = EmployeeWorkingHours.get_for_day(service_id, employee_id, date.weekday())
    events = []

    # Check if provider is working on this date
    if workinghrs is None or Absence.is_absent_on(provider, date):
        return [
            {
                "title": ugettext(EVENT_TITLE_CLOSED_WHOLE_DAY),
                "start": encodeDatetime(date),
                "end": encodeDatetime(date + datetime.timedelta(days=1)),
                "color": EVENT_CLOSED_COLOR,
            }
        ]

        # Start
    events.append(
        {
            "title": ugettext(EVENT_TITLE_CLOSED),
            "start": encodeDatetime(date),
            "end": encodeDatetime(datetime.datetime.combine(date, workinghrs.time_from)),
            "color": EVENT_PAUSE_COLOR,
        }
    )

    # End
    events.append(
        {
            "title": ugettext(EVENT_TITLE_CLOSED),
            "start": encodeDatetime(datetime.datetime.combine(date, workinghrs.time_to)),
            "end": encodeDatetime(date + datetime.timedelta(days=1)),
            "color": EVENT_PAUSE_COLOR,
        }
    )

    return events
Ejemplo n.º 7
0
def getWorkingHours(provider, service_id, date):
    workinghrs = WorkingHours.get_for_day(provider, date.weekday())

    employees_workinghours_on_curr_service = EmployeeWorkingHours.objects.filter(
        service=service_id)
    maxTime_from = employees_workinghours_on_curr_service[0].time_from
    maxTime_to = employees_workinghours_on_curr_service[0].time_to
    for employee_workinghours in employees_workinghours_on_curr_service:
        if maxTime_from > employee_workinghours.time_from:
            maxTime_from = employee_workinghours.time_from
    if maxTime_to < employee_workinghours.time_to:
        maxTime_to = employee_workinghours.time_to

    events = []

    # Check if provider is working on this date
    if workinghrs is None or Absence.is_absent_on(provider, date):
        return [{
            'title': ugettext(EVENT_TITLE_CLOSED_WHOLE_DAY),
            'start': encodeDatetime(date),
            'end': encodeDatetime(date + datetime.timedelta(days=1)),
            'color': EVENT_CLOSED_COLOR
        }]

    # Start
    events.append({
        'title':
        ugettext(EVENT_TITLE_CLOSED),
        'start':
        encodeDatetime(date),
        'end':
        encodeDatetime(datetime.datetime.combine(date, maxTime_from)),
        'color':
        EVENT_PAUSE_COLOR
    })

    # End
    events.append({
        'title':
        ugettext(EVENT_TITLE_CLOSED),
        'start':
        encodeDatetime(datetime.datetime.combine(date, maxTime_to)),
        'end':
        encodeDatetime(date + datetime.timedelta(days=1)),
        'color':
        EVENT_PAUSE_COLOR
    })

    for wrkbrk in workinghrs.breaks.all():
        events.append({
            'title':
            ugettext(EVENT_TITLE_CLOSED),
            'start':
            encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_from)),
            'end':
            encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_to)),
            'color':
            EVENT_PAUSE_COLOR
        })

    return events
Ejemplo n.º 8
0
def getEmployeeWorkingHours(provider, employee, date, past):
    sp_workinghrs = WorkingHours.get_for_day(provider, date.weekday())
    workinghrs = EmployeeWorkingHours.get_for_day(employee, date.weekday())
    events = []

    if past:
        now = datetime.datetime.now()
        if date < now.date():
            return [
                {
                    'title': ugettext('In the past'),
                    'start': encodeDatetime(date),
                    'end': encodeDatetime(datetime.datetime.combine(date, datetime.time(23, 59))),
                    'color': '#444444'
                }
            ]
        elif date == now.date():
            events.append(
                {
                    'title': ugettext('In the past'),
                    'start': encodeDatetime(date),
                    'end': encodeDatetime(datetime.datetime.combine(date, now.time())),
                    'color': '#444444'
                }
            )

    # TODO add employee absence support
    if sp_workinghrs is None or Absence.is_absent_on(provider, date):
        return [
            {
                'title': ugettext(EVENT_TITLE_CLOSED_WHOLE_DAY),
                'start': encodeDatetime(date),
                'end': encodeDatetime(date + datetime.timedelta(days=1)),
                'color': EVENT_CLOSED_COLOR
            }
        ]
    if workinghrs is None:
        return [
            {
                'title': ugettext(EVENT_TITLE_NOT_WORKING_WHOLE_DAY),
                'start': encodeDatetime(date),
                'end': encodeDatetime(date + datetime.timedelta(days=1)),
                'color': EVENT_CLOSED_COLOR
            }
        ]

    events.append({
        'title': ugettext(EVENT_TITLE_NOT_WORKING),
        'start': encodeDatetime(date),
        'end': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_from)),
        'color': EVENT_PAUSE_COLOR
    })

    events.append({
        'title': ugettext(EVENT_TITLE_NOT_WORKING),
        'start': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_to)),
        'end': encodeDatetime(date + datetime.timedelta(days=1)),
        'color': EVENT_PAUSE_COLOR
    })

    for wrkbrk in sp_workinghrs.breaks.all():
        events.append({
            'title': ugettext(EVENT_TITLE_CLOSED),
            'start': encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_from)),
            'end': encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_to)),
            'color': EVENT_PAUSE_COLOR
        })

    return events
Ejemplo n.º 9
0
def getWorkingHours(service, provider, date, past):
    workinghrs = WorkingHours.get_for_day(provider, date.weekday())
    events = []

    if past:
        now = datetime.datetime.now()
        if date < now.date():
            return [
                {
                    'title': ugettext('In the past'),
                    'start': encodeDatetime(date),
                    'end': encodeDatetime(datetime.datetime.combine(date, datetime.time(23, 59))),
                    'color': '#444444'
                }
            ]
        elif date == now.date():
            events.append(
                {
                    'title': ugettext('In the past'),
                    'start': encodeDatetime(date),
                    'end': encodeDatetime(datetime.datetime.combine(date, now.time())),
                    'color': '#444444'
                }
            )

    # Check if provider is working on this date
    if workinghrs is None or Absence.is_absent_on(provider, date):
        return [
            {
                'title': ugettext(EVENT_TITLE_CLOSED_WHOLE_DAY),
                'start': encodeDatetime(date),
                'end': encodeDatetime(date + datetime.timedelta(days=1)),
                'color': EVENT_CLOSED_COLOR
            }
        ]

    # Start
    events.append({
        'title': ugettext(EVENT_TITLE_CLOSED),
        'start': encodeDatetime(date),
        'end': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_from)),
        'color': EVENT_PAUSE_COLOR
    })

    # End
    events.append({
        'title': ugettext(EVENT_TITLE_CLOSED),
        'start': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_to)),
        'end': encodeDatetime(date + datetime.timedelta(days=1)),
        'color': EVENT_PAUSE_COLOR
    })

    for wrkbrk in workinghrs.breaks.all():
        events.append({
            'title': ugettext(EVENT_TITLE_CLOSED),
            'start': encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_from)),
            'end': encodeDatetime(datetime.datetime.combine(date, wrkbrk.time_to)),
            'color': EVENT_PAUSE_COLOR
        })

    if service is not None:
        employees = Employee.objects.filter(id__in=service.employees.all(), employer=provider.id)
    else:
        employees = Employee.objects.filter(employer=provider.id).all()
    first_arrive = datetime.time(23, 59)
    last_gone = datetime.time(0)
    for e in employees:
        if e.working_hours.all():
            cwh = e.working_hours.all()[0].get_for_day(e, date.weekday())
        if cwh:
            if cwh.time_to > last_gone:
                last_gone = cwh.time_to
            if cwh.time_from < first_arrive:
                first_arrive = cwh.time_from
    if employees:
        if first_arrive == datetime.time(23, 59) and last_gone == datetime.time(0):
            return [{
                        'title': ugettext('No employees scheduled but we are still open. Huh.'),
                        'start': encodeDatetime(date),
                        'end': encodeDatetime(date + datetime.timedelta(days=1)),
                        'color': EVENT_CLOSED_COLOR
                    }]
        else:
            if first_arrive > workinghrs.time_from:
                events.append({
                    'title': ugettext('No employees here yet'),
                    'start': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_from)),
                    'end': encodeDatetime(datetime.datetime.combine(date, first_arrive)),
                    'color': EVENT_PAUSE_COLOR
                })
            if last_gone < workinghrs.time_to:
                events.append({
                    'title': ugettext('All employees have left'),
                    'start': encodeDatetime(datetime.datetime.combine(date, last_gone)),
                    'end': encodeDatetime(datetime.datetime.combine(date, workinghrs.time_to)),
                    'color': EVENT_PAUSE_COLOR
                })
    return events