
    vgH                     "   d dl mZ d dl d dlmZ  G d dej
                        Z G d dej
                        Z G d d	ej
                        Z G d
 dej
                        Z	 G d dej
                        Z
 G d dej
                        Zy)    )serializers)*)RecruitmentMailTemplatec                      e Zd Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  d      Z
 ej                  dd      Z G d	 d
      Zd Zd Zy)AttendanceSerializeremployee_id.employee_first_nameTsource	read_onlyemployee_id.employee_last_nameshift_id.employee_shiftemployee_id.badge_idr   zwork_type_id.work_typec                       e Zd ZeZg dZy)AttendanceSerializer.Meta)
overtime_secondat_work_secondattendance_dayrequest_descriptionapproved_overtime_secondrequest_typerequested_datais_validate_requestis_validate_request_approvedattendance_overtimeN__name__
__module____qualname__
Attendancemodelexclude     F/var/www/horilla/horilla_api/api_serializers/attendance/serializers.pyMetar      s    
r$   r&   c                     | j                   r|S |j                  d      }|j                  dt        j                               }t        j
                  j                  ||      j                         rt        d      |S )Nemployee_idattendance_dater(   r)   z@Attendance for this employee on the current date already exists.)	instancegetdatetodayr    objectsfilterexistsValidationError)selfdatar(   r)   s       r%   validatezAttendanceSerializer.validate"   sv    ==Khh}-((#4djjlC$$#_ % 

&( "S  r$   c                 V    	 |j                   j                  }|j                  S #  Y y xY wNr(   employee_profileurlr3   objr9   s      r%   get_employee_profile_urlz-AttendanceSerializer.get_employee_profile_url0   -    	"??#'''	   !$ (N)r   r   r   r   	CharFieldemployee_first_nameemployee_last_name
shift_namebadge_idSerializerMethodFieldemployee_profile_url	work_typer&   r5   r=   r#   r$   r%   r   r      s    /+//0D /../4 '&&.GSWXJ${$$,BdSH<;<<tL%%%-EQUVI
 
r$   r   c                       e Zd Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  d      Z
 G d d	      Zd
 Z fdZd Z xZS )AttendanceRequestSerializerr   Tr	   r   r   r   r   c                       e Zd ZeZg dZy) AttendanceRequestSerializer.Meta)r   attendance_overtime_approveattendance_validatedr   r   r   r   
created_atNr   r#   r$   r%   r&   rK   C   s    	
r$   r&   c                    |j                  d      }|j                  d      }t        j                  j                  ||      }|j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d	      |j                  d
      |j                  d      d
}|j	                         r|j
                  |d<   t        |      |d<   | j                  d   |d<   | j                  d   |d<   |d   dk(  rd n|d   |d<   |d   dk(  rd n|d   |d<   | j                  d	   |d	<   | j                  d   |d<   |j                         }|j                         D ]  \  }}t        |      ||<    t        j                  |      |_        d|_        |j                  dk7  rd|_        | j                  d   |_        |j!                         S t        di |}	d|	_        d|	_        | j                  d   |	_        d|	_        |	j!                          |	S )Nr(   r)   r*   attendance_clock_in_dateattendance_clock_inattendance_clock_outattendance_clock_out_dateshift_idwork_type_idattendance_worked_hourminimum_hour)
r(   r)   rP   rQ   rR   rS   rT   rU   rV   rW   NoneTcreate_requestupdate_requestr   Fr#   )r,   r    r/   r0   r1   idstrr4   firstitemsjsondumpsr   r   r   r   saverM   )
r3   validated_datar(   r)   attendancesr4   
attendancekeyvaluenew_instances
             r%   createz"AttendanceRequestSerializer.createP   s~   $((7(,,->? ((//#_ 0 
 *--m<-112CD(6(:(:;U(V#1#5#56K#L$2$6$67M$N)7););+* '**:6*..~>&4&8&89Q&R*..~>
 "-..D&)/&:D"#/3yy9S/TD+,*.))4I*JD&' ./69 01 '( 34> 56 ,-
 $(99^#<D #yy4D$**,J"jjl '
UJS	'(,

4(8J%-1J*&&*::*:
'-1YY7L-MJ*??$$!)D)+/(,1)+/995J+K($4!r$   c                 N    d|v r|j                  d       t        | 	  ||      S )Nr(   )popsuperupdate)r3   r+   rb   	__class__s      r%   rl   z"AttendanceRequestSerializer.update   s*    N*}-w~h77r$   c                 V    	 |j                   j                  }|j                  S #  Y y xY wr7   r8   r;   s      r%   r=   z4AttendanceRequestSerializer.get_employee_profile_url   r>   r?   )r   r   r   r   r@   rA   rB   rC   rD   rE   rF   r&   rh   rl   r=   __classcell__)rm   s   @r%   rI   rI   8   s    /+//0D /../4 '&&.GSWXJ${$$,BdSH<;<<tL
 
6p8
r$   rI   c                       e Zd Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  d      Z	 G d d      Z
d	 Zy
)AttendanceOverTimeSerializerr   Tr	   r   r   r   c                       e Zd ZeZg dZy)!AttendanceOverTimeSerializer.Meta)r[   rA   rB   rF   rD   r(   monthyearworked_hourspending_hoursovertimeN)r   r   r   AttendanceOverTimer!   fieldsr#   r$   r%   r&   rs      s    "
r$   r&   c                 V    	 |j                   j                  }|j                  S #  Y y xY wr7   r8   r;   s      r%   r=   z5AttendanceOverTimeSerializer.get_employee_profile_url   r>   r?   N)r   r   r   r   r@   rD   rA   rB   rE   rF   r&   r=   r#   r$   r%   rq   rq      sm    ${$$,BdSH/+//0D /../4 =;<<tL
 
 r$   rq   c                   p    e Zd Z ej                  dd      Z ej                  dd      Z G d d      Zy)$AttendanceLateComeEarlyOutSerializerr   Tr	   r   c                       e Zd ZeZdZy))AttendanceLateComeEarlyOutSerializer.Meta__all__N)r   r   r   AttendanceLateComeEarlyOutr!   rz   r#   r$   r%   r&   r      s    *r$   r&   Nr   r   r   r   r@   rA   rB   r&   r#   r$   r%   r}   r}      >    /+//0D /../4 r$   r}   c                   p    e Zd Z ej                  dd      Z ej                  dd      Z G d d      Zy)AttendanceActivitySerializerr   Tr	   r   c                       e Zd ZeZdZy)!AttendanceActivitySerializer.Metar   N)r   r   r   AttendanceActivityr!   rz   r#   r$   r%   r&   r      s    "r$   r&   Nr   r#   r$   r%   r   r      r   r$   r   c                        e Zd Z G d d      Zy)MailTemplateSerializerc                       e Zd ZeZdZy)MailTemplateSerializer.Metar   N)r   r   r   r   r!   rz   r#   r$   r%   r&   r      s    'r$   r&   N)r   r   r   r&   r#   r$   r%   r   r      s     r$   r   N)rest_frameworkr   attendance.modelsrecruitment.modelsr   ModelSerializerr   rI   rq   r}   r   r   r#   r$   r%   <module>r      s    &  6.;66 .bZ+"="= Zz;#>#> D
;+F+F 

;#>#> 
[88 r$   