o
    !5h$                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
Z
G dd dejZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd dejZG dd dejZd dl mZ G dd dejZdS )    )models)User)ValidationError)timezone)	timedeltaNc                   @   sD   e Zd ZejdejddZejddZ	ejddZ
G dd dZdS )		BaseModelTF)primary_keydefaulteditableauto_now_add)auto_nowc                   @      e Zd ZdZdS )zBaseModel.MetaTN)__name__
__module____qualname__abstract r   r   $/var/www/html/rh/vacations/models.pyMeta       r   N)r   r   r   r   	UUIDFielduuiduuid4idDateTimeField
created_at
updated_atr   r   r   r   r   r      s
    r   c                   @   sR   e Zd ZejddZejddddZe Zej	ddZ
dd	 ZG d
d dZdS )Company   
max_length   TCNPJr!   uniqueverbose_namer	   c                 C   s   | j S N)nameselfr   r   r   __str__   s   zCompany.__str__c                   @   r   )zCompany.Meta	CompaniesN)r   r   r   verbose_name_pluralr   r   r   r   r      r   r   N)r   r   r   r   	CharFieldr)   cnpj	TextFieldaddressBooleanField	is_activer,   r   r   r   r   r   r      s    r   c                   @   sX   e Zd ZejeejddZejddZ	ejddZ
ejddZdd	 ZG d
d dZdS )
CostCentercost_centers	on_deleterelated_name2   r    r   Tr'   c                 C   s   | j  d| j d| jj dS )N -  ())coder)   companyr*   r   r   r   r,   "   s   zCostCenter.__str__c                   @   r   )zCostCenter.Meta)r?   r>   Nr   r   r   unique_togetherr   r   r   r   r   %   r   r   N)r   r   r   r   
ForeignKeyr   CASCADEr?   r/   r>   r)   r3   r4   r,   r   r   r   r   r   r5      s    r5   c                   @   sl  e Zd ZdZdZdZdZedfedfedfedfgZej	e
ejd	d
ZejdeedZejeejdd
ZejeddZejddddZe ZejddZejdddZejddddddZejddddddZejdddddZejddd d!dZejdddd"d#dZ ejd$ddd%d&dZ!ejd'ddej"d(d)Z#ej$d*d+dZ%ej&d,ddd-d.d/Z'd0d1 Z(e)d2d3 Z*d4S )5EmployeeProfileemployeemanageradmininternColaboradorGestorzAdministrador (RH)u   Estagiárioprofiler7      r!   choicesr	   	employees)r9   r:   Tu
   Matrícular$   r'   FzPode ser tutor)r	   r&      CPFu   Cadastro de Pessoa Física)r!   blanknullr&   	help_textu   Carga Horáriau   Carga horária diáriau   Início do turnou   Horário de início da jornada)rR   rS   r&   rT   zFim do turnou   Horário de término da jornadaTurmau   Identificação da turmad   u   Funçãou   Função exercidar+   estagiarios)rS   rR   r8   r9   r   u   Saldo de Férias (manual)logos/u   Logomarca do Estagiáriou$   Será exibida no relatório de ponto)	upload_torR   rS   r&   rT   c                 C   s   | j   d| j dS )Nr<   r=   )userget_full_nameemployee_idr*   r   r   r   r,   {   s   zEmployeeProfile.__str__c                 C   s   ddl m} || S )Nr   calculate_vacation_balance)vacations.utilsr^   )r+   r^   r   r   r   current_vacation_balance~   s   z(EmployeeProfile.current_vacation_balanceN)+r   r   r   USER_ROLE_EMPLOYEEUSER_ROLE_MANAGERUSER_ROLE_ADMINUSER_ROLE_INTERNUSER_ROLE_CHOICESr   OneToOneFieldr   rC   rZ   r/   rolerB   r   r?   ManyToManyFieldr5   r6   r\   	DateField	hire_dater3   r4   is_tutorcpfcarga_horaria	TimeFieldhorario_trabalho_iniciohorario_trabalho_fimturmafuncaoSET_NULLtutorIntegerFieldvacation_balance
ImageField	logo_filer,   propertyr`   r   r   r   r   rD   (   s    rD   c                       s  e Zd ZdZdZdZdZedfedfedfedfgZej	e
ejd	d
Ze Ze ZejdeedZejdddZej	e
ejddddZejdddZejdddZejdddZejddddZejdddZejdddZdd Z fddZ e!dd Z"dd  Z#G d!d" d"Z$  Z%S )#VacationRequestpendingapprovedrejected	cancelledPendenteAprovado	Rejeitado	Canceladovacation_requestsr7   rL   rM   r   z,Number of days being sold (max 1/3 of total))r	   rT   Tapproved_vacations)r8   rS   rR   r9   )rS   rR   rR   rS   Fu8   Marcar como férias já gozadas, registradas manualmenteu2   Observação ou justificativa para ajustes manuais)rR   rS   rT   c                 C   s   | j | jkrtddi| j | j jd }|dk rtdtd|d }| j|kr3tdd	| d
i| jsPddlm} || j	}|| j |krRtd| dd S d S )Nend_dateu0   A data final deve ser posterior à data inicial.      uA   Conforme a CLT, períodos de férias devem ter no mínimo 5 dias.
      selling_daysu-   Conforme a CLT, você pode vender no máximo u    dias (1/3 das férias).r   r]   u,   Saldo insuficiente de férias. Você possui u    dias disponíveis.)
r   
start_dater   daysminr   	is_manualr_   r^   rE   )r+   
total_daysmax_selling_daysr^   balancer   r   r   clean   s&   

zVacationRequest.cleanc                    s   |    t j|i | d S r(   )r   supersave)r+   argskwargs	__class__r   r   r      s   zVacationRequest.savec                 C   s   | j | j jd | j S )Nr   )r   r   r   r   r*   r   r   r   r      s   zVacationRequest.total_daysc                 C   s$   d| j j  d| j d| j dS )Nu   Férias de r<   z a r=   )rE   rZ   r[   r   r   r*   r   r   r   r,      s   $zVacationRequest.__str__c                   @      e Zd ZdgZdS )zVacationRequest.Metaz-start_dateNr   r   r   orderingr   r   r   r   r          
r   )&r   r   r   STATUS_PENDINGSTATUS_APPROVEDSTATUS_REJECTEDSTATUS_CANCELLEDSTATUS_CHOICESr   rB   rD   rC   rE   ri   r   r   r/   statusru   r   rs   approved_byr   approval_dater1   rejection_reasonr3   r   correction_notecancellation_datecancellation_reasonr   r   ry   r   r,   r   __classcell__r   r   r   r   rz      sD    
rz   c                   @   s   e Zd ZdZdZdZdZdZedfedfedfed	fed
fgZe	j
ee	jddZe	jdedZe	j
ee	jdddZe	jdddZdd ZG dd dZdS )VacationLogrequestapproverejectcanceleditu   Solicitaçãou   Aprovaçãou
   RejeiçãoCancelamentou   Ediçãologsr7   rL   r!   rN   Tvacation_logs)r8   rS   r9   r   c                 C   s    |    d| j d| j  S )Nr;   z por )get_action_displayvacation_requestperformed_byr[   r*   r   r   r   r,      s    zVacationLog.__str__c                   @   r   )zVacationLog.Metaz-created_atNr   r   r   r   r   r      r   r   N)r   r   r   ACTION_REQUESTACTION_APPROVEACTION_REJECTACTION_CANCELACTION_EDITACTION_CHOICESr   rB   rz   rC   r   r/   actionr   rs   r   r1   detailsr,   r   r   r   r   r   r      s$    r   c                   @   sT   e Zd ZejdejdZejddZg dZ	ej
de	dZG dd	 d	Zd
d ZdS )ClockRecordrD   )r8   Tr   ))inEntrada)	lunch_outu   Saída para Almoço)lunch_inu   Retorno do Almoço)outu   Saída FinalrL   r   c                   @   r   )zClockRecord.Meta	timestampNr   r   r   r   r   r      r   r   c                 C   s&   | j j  d| j d| jd S )Nr;   z%d/%m/%Y %H:%M)rE   rZ   r[   typer   strftimer*   r   r   r   r,      s   &zClockRecord.__str__N)r   r   r   r   rB   rC   rE   r   r   TYPE_CHOICESr/   r   r   r,   r   r   r   r   r      s    r   c                   @   sh   e Zd ZejdejddZejdejddZe Z	e Z
ejejdZejddZG dd dZd	S )
ClockReportApprovalrD   aprovacoes_tutorr7   relatorios_aprovadosr'   Tc                   @   s   e Zd Zg dZdS )zClockReportApproval.Meta)rt   rH   monthyearNr@   r   r   r   r   r      s    r   N)r   r   r   r   rB   rC   rt   rH   ru   r   r   r   r   nowapproved_atr3   signedr   r   r   r   r   r      s    r   c                   @   s,   e Zd ZejddZejddZdd ZdS )LogoInstitucionalrX   )rY   Tr   c                 C   s   d| j  S )NzLogo )r   r*   r   r   r   r,   
  s   zLogoInstitucional.__str__N)	r   r   r   r   rw   imagemr   	criado_emr,   r   r   r   r   r     s    r   )	django.dbr   django.contrib.auth.modelsr   django.core.exceptionsr   django.utilsr   datetimer   r   Modelr   r   r5   rD   rz   r   r   r   r   r   r   r   r   <module>   s     ^F