Untitled

mail@pastecode.io avatar
unknown
python
14 days ago
2.2 kB
1
Indexable
Never
def is_uninterrupted_months(self,workhour_contract):
    diferenca = (workhour_contract.data_end.year - workhour_contract.date_start.year) * 12 + (workhour_contract.data_end.month - workhour_contract.date_start.month)

    return diferenca >= self.TELEWORK_TIME - 1

def is_last_month_period(self,workhour_contract,date):
    last_month = DateRange.from_month(workhour_contract.data_end.year,workhour_contract.data_end.month)

    return last_month.in_range(date)

def get_days_month(self,dias_bilhetes,date):
    da = DayActivity.objects.filter(
        date__year=date.year,
        date__month=date.month,
        employee=self.employee,
        activity_type__classification__in=[1,8],
    ).exclude(
        id__in = dias_bilhetes,
        date__week_day = 1,
    ).exclude(
        date__week_day = 7,
    )
    log.debug(da)            
    return da

def get_dias_bilhetes(self,workhour_contract):
    return Ticket.objects.filter(
            date_record__gte = workhour_contract.date_start,
            date_record__lte = workhour_contract.data_end,
            employee = self.employee,
        ).exclude(
            day_activity__activity_type__classification__in = [2,3,4]
        ).values_list('day_activity',flat=True)

def is_falta_home_office(self,qnt_days=10,date=date, workhour_contract=None):
    date_now = datetime.now().date()
    day_one_date_now = date_now.replace(day=1)

    # if date.month == 12 or self.employee.type_by_possession == 'EST':
    #     return False

    if date < day_one_date_now:
        # if not date < self.BASE_DATA:
        if not self.is_uninterrupted_months(workhour_contract):
            log.debug('nao sao meses initerruptos')
            return False

        if not self.is_last_month_period(workhour_contract,date):
            log.debug('nao e ultimo mes do periodo')
            return False

        dias_bilhetes = self.get_dias_bilhetes(workhour_contract)
        dias_bilhetes = set(dias_bilhetes)

        if len(dias_bilhetes) < self.QTD_DAYS:
            days_month = self.get_days_month(dias_bilhetes,date)

            for dm in days_month[0: self.QTD_DAYS - len(dias_bilhetes)]:
                if date == dm.date:
                    return True
Leave a Comment