
    vgc                        d Z ddlZddlmZmZmZ ddlmZ ddlZddlm	Z	 ddl
mZ ddlmZ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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"m#Z# ddl$m%Z%m&Z& d ed      fd ed      fd ed      fd ed      fd ed      fgZ'd ed      fd ed      fd ed      fd ed       fd ed!      fd" ed#      fd$ ed%      fgZ(d& Z)d' Z* G d( d)e#      Z+ G d* d+e#      Z, G d, d-e#      Z- G d. d/e#      Z. G d0 d1e#      Z/ G d2 d3e#      Z0 e1d4d5      D  cg c]  }  e2|        e2|       f c} Z3e3ji                  d6 ed7      f       d8 ed      fd9 ed      fd: ed      fd; ed       fd< ed!      fd= ed#      fd> ed%      fgZ5d? ed@      fdA edB      fdC edD      fgZ6 G dE dFe#      Z7 G dG dHe#      Z8 G dI dJejr                        Z: G dK dLe#      Z;ddMl<m=Z=m>Z>  G dN dOe#      Z? G dP dQe#      Z@ G dR dSe#      ZA G dT dUejr                        ZB G dV dWe#      ZC G dX dYe#      ZD G dZ d[e#      ZE G d\ d]e#      ZF G d^ d_e#      ZG G d` dae#      ZH G db dce#      ZIddde edf      fgZJdg edh      fdi edj      fdk edl      fdm edn      fdo edp      fdq edr      fds edt      fdu edv      fgZK G dw dxe#      ZL G dy dzejr                        ZM G d{ d|ejr                        ZN G d} d~ejr                        ZO G d dejr                        ZP G d de#      ZQ G d de#      ZR G d dejr                        ZS G d dejr                        ZT G d dejr                        ZU G d de#      ZV G d dejr                        ZWd ZX G d dejr                        ZY G d de#      ZZ G d de#      Z[ G d de#      Z\ G d de#      Z] G d dejr                        Z^ eee]      d        Z_ ej                  d ej                  d             yc c} w )z:
models.py

This module is used to register django models
    N)datedatetime	timedelta)Iterable)apps)messages)AbstractUserUser)ValidationError)models)	post_save)receiver)gettext_lazy)HorillaCompanyManager)horilla_middlewares)_thread_locals)get_horilla_model_class)HorillaModel)HorillaAuditInfoHorillaAuditLog0z
First Week1zSecond Week2z
Third Week3zFourth Week4z
Fifth WeekMondayTuesday	WednesdayThursdayFriday5Saturday6Sundayc                 Z   t        |       dkD  rt        t        d            	 | j                  d      \  }}t	        |      }t	        |      }t        t        |            dkD  s|t        d      vrt        t        d            y# t        $ r}t        t        d            |d}~ww xY w)	zM
    this method is used to validate the format of duration like fields.
       z)Invalid format, it should be HH:MM format:   <   zInvalid time, excepted HH:MMzInvalid format,  excepted HH:MMN)lenr   _splitintstrrange
ValueError)valuehourminutees       /var/www/horilla/base/models.pyvalidate_time_formatr6   1   s     5zA~a KLMMK{{3'f4yVs4y>AuRy!8!!$B"CDD "9 Ka ABCJKs   A"B 	B*B%%B*c                 <    t        j                  |       }|D ]  } y N)r   get_messages)requeststoragemessages      r5   clear_messagesr=   A   s$    ##G,G     c                      e Zd ZdZ ej
                  d      Z ej                  d      Z ej                  d      Z
 ej
                  d      Z ej
                  d      Z ej
                  d      Z ej
                  d      Z ej                  dd	
      Z ej"                         Z ej
                  dd	d	      Z ej
                  dd	d	      Z G d d      ZdefdZy)Companyz
    Company model
    2   
max_lengthFdefault      z	base/iconT)	upload_tonull   rC   blankrI   c                   <    e Zd ZdZ ed      Z ed      ZddgZdZy)Company.Meta6
        Meta class to add additional options
        r@   	CompaniescompanyaddressbaseN)	__name__
__module____qualname____doc__r+   verbose_nameverbose_name_pluralunique_together	app_label r>   r5   MetarN   [   s+    	 |n$i0	r>   r]   returnc                 ,    t        | j                        S r8   )r.   rQ   selfs    r5   __str__zCompany.__str__e   s    4<<  r>   N)rT   rU   rV   rW   r   	CharFieldrQ   BooleanFieldhq	TextFieldrR   countrystatecityzip	FileFieldiconManagerobjectsdate_formattime_formatr]   r.   rb   r\   r>   r5   r@   r@   G   s     f"-G			U	+Bf#.Gf"-GF+E6r*D
&

b
)C6D fnnG"&""b4HK"&""b4HK ! !r>   r@   c                        e Zd ZdZ ej
                  dd      Z ej                  ed e	d            Z
 e       Z G d d	      Z fd
Z fdZd Z xZS )
Departmentz
    Department model
    rA   F)rC   rL   Tr@   rL   rX   c                   ,    e Zd Z ed      Z ed      Zy)Department.Metarr   DepartmentsNrT   rU   rV   r+   rX   rY   r\   r>   r5   r]   ru   s   s    .r>   r]   c                 z   t        |   |i | t        t        dd       }|r|j                  r|j                  j                  dd       }|j                  j                  dd       }t        j                  j                  ||      j                  | j                        j                         rt        d      y )Nr:   
company_id
department)company_id__id__inrz   idz.This department already exists in this company)supercleangetattrr   POSTgetlistgetrr   rn   filterexcluder}   existsr   )ra   argskwargsr:   rQ   rz   	__class__s         r5   r   zDepartment.cleanw   s    t&v&.)T:w||ll**<>G )),=J""))'.: *  DGG$	 &&VWWr>   c                 J    t        |   |i |  | j                  |i | | S r8   r~   saver   ra   r   r   r   s      r5   r   zDepartment.save   ,    d%f%

D#F#r>   c                 ,    t        | j                        S r8   )r.   rz   r`   s    r5   rb   zDepartment.__str__   s    4??##r>   )rT   rU   rV   rW   r   rc   rz   ManyToManyFieldr@   r+   ry   r   rn   r]   r   r   rb   __classcell__r   s   @r5   rr   rr   i   sY     "!!Ru=J'''t!I,WJ#%G/ / 
$r>   rr   c                       e Zd ZdZ ej
                  ddd      Z ej                  eej                  d e
d            Z ej                  ed e
d	      
      Z ed      Z G d d      Zd Zy)JobPositionz
    JobPosition model
    rA   FrK   job_positionrr   	on_deleterelated_namerX   Tr@   rs   department_id__company_idc                   0    e Zd ZdZ ed      Z ed      Zy)JobPosition.MetarO   Job PositionzJob PositionsNrT   rU   rV   rW   r+   rX   rY   r\   r>   r5   r]   r      s    	 (0r>   r]   c                 f    t        | j                  dz   | j                  j                  z         dz   S )Nz - ())r.   r   department_idrz   r`   s    r5   rb   zJobPosition.__str__   s/    4$$v-0B0B0M0MMNQTTTr>   N)rT   rU   rV   rW   r   rc   r   
ForeignKeyrr   PROTECTr+   r   r   r@   ry   r   rn   r]   rb   r\   r>   r5   r   r      s|     $6##rUKL%F%%..#|_	M (''t!I,WJ#$?@G1 1Ur>   r   c                       e Zd ZdZ ej
                  eej                   ed            Z	 ej                  ddd      Z ej                  ed ed      	      Z ed
      Z G d d      Zd Zy)JobRolezJobRole modelr   r   rX   rA   FTrK   r@   rs   *job_position_id__department_id__company_idc                   4    e Zd ZdZ ed      Z ed      ZdZy)JobRole.MetarO   zJob Rolez	Job Roles)job_position_idjob_roleN)rT   rU   rV   rW   r+   rX   rY   rZ   r\   r>   r5   r]   r      s!    	 }n9r>   r]   c                 L    | j                    d| j                  j                   S )N - )r   r   r   r`   s    r5   rb   zJobRole.__str__   s$    --D$8$8$E$E#FGGr>   N)rT   rU   rV   rW   r   r   r   r   r+   r   rc   r   r   r@   ry   r   rn   r]   rb   r\   r>   r5   r   r      st    'f''v~~An<MO  v2UFH'''t!I,WJ#$PQG: :Hr>   r   c                        e Zd ZdZ ej
                  d      Z ej                  ed e	d            Z
 e       Z G d d      Zd	efd
Z fdZ fdZ xZS )WorkTypez
    WorkType model
    rA   rB   Tr@   rs   c                   0    e Zd ZdZ ed      Z ed      Zy)WorkType.MetarO   z	Work Typez
Work TypesNr   r\   r>   r5   r]   r      s    	 ~or>   r]   r^   c                 ,    t        | j                        S r8   )r.   	work_typer`   s    r5   rb   zWorkType.__str__   s    4>>""r>   c                 z   t        |   |i | t        t        dd       }|r|j                  r|j                  j                  dd       }|j                  j                  dd       }t        j                  j                  ||      j                  | j                        j                         rt        d      y )Nr:   ry   r   )r{   r   r|   z-This work type already exists in this company)r~   r   r   r   r   r   r   r   rn   r   r   r}   r   r   )ra   r   r   r:   rQ   r   r   s         r5   r   zWorkType.clean   s    t&v&.)T:w||ll**<>G((d;I  ''7i'XDGG$ &&UVVr>   c                 J    t        |   |i |  | j                  |i | | S r8   r   r   s      r5   r   zWorkType.save   r   r>   )rT   rU   rV   rW   r   rc   r   r   r@   r+   ry   r   rn   r]   r.   rb   r   r   r   r   s   @r5   r   r      sc     !  B/I'''t!I,WJ#%G. .# # r>   r   c                   j   e Zd ZdZ ej
                  d      Z ej                  eej                  d e
d            Z ej                  eej                  d e
d            Z ej                  d	d
 e
d            Z ej                  edd      Z ed      Z G d d      ZdefdZd Zd Zy)RotatingWorkTypez 
    RotatingWorkType model
    rA   rB   
work_type1zWork Type 1r   
work_type2zWork Type 2employee.EmployeeRotatingWorkTypeAssignEmployeethroughrX   TrE   rL   rI   +employee_id__employee_work_info__company_idc                   0    e Zd ZdZ ed      Z ed      Zy)RotatingWorkType.MetarO   Rotating Work TypezRotating Work TypesNr   r\   r>   r5   r]   r          	 -. 56r>   r]   r^   c                 ,    t        | j                        S r8   r.   namer`   s    r5   rb   zRotatingWorkType.__str__      499~r>   c                 8   | j                   | j                  k(  rt        t        d            | j                  r| j                  j                  dg       ng }|r9t        | j                  j                        |d   k(  rt        t        d            |r9t        | j                   j                        |d   k(  rt        t        d            t        t        |      dz
        D ]3  }||   s	||dz      s||   ||dz      k(  s!t        t        d             y )Nz'Select different work type continuouslyadditional_work_typesr      )
r   r   r   r+   additional_datar   r.   r}   r/   r*   )ra   r   is      r5   r   zRotatingWorkType.clean  s   ??doo-!!$M"NOO ##   $$%<bA 	 "DOO&&'+@+CC!!$M"NOO "DOO&&'+@+DD!!$M"NOOs01A56 	XA$Q',A!a%,H(+/DQU/KK)!,U*VWW	Xr>   c                     t         j                  j                  | j                        }|j                  }|r9|j                  d      }|r"t
        j                  j                  |      }|S d }|S d }|S )Nr|   r   id__in)r   rn   r   pkr   r   r   )ra   rotating_work_typer   additional_work_type_idsr   s        r5   r   z&RotatingWorkType.additional_work_types1  s    -5599TWW9E,<<'6':':;R'S$'(0(8(8(?(?3 )@ )% %$ )-% %$ %)!$$r>   N)rT   rU   rV   rW   r   rc   r   r   r   r   r+   r   r   r   employee_id	JSONFielddictr   r   rn   r]   r.   rb   r   r   r\   r>   r5   r   r      s     6r*D"""..!}%	J #""..!}%	J )&(((z]K
 'f&&O
 $$QRG7 7 X6%r>   r   r       lastzLast Daymondaytuesday	wednesdaythursdayfridaysaturdaysundayafterAfterweeklyWeekendmonthlyMonthlyc            
       2   e Zd ZdZ ej
                  dej                  d ed            Z ej
                  e	ej                   ed            Z
 ej                  ej                  j                  j                   ed      	      Z ej                  d ed
            Z ej
                  edej                  d ed            Z ej
                  edej                  d ed            Z ej*                  dedd ed            Z ej0                  d ed      	      Z ej*                  ddedd ed            Z ej*                  dde ed            Z ej<                  edd      Z  e!de"g      Z# e$d       Z% G d! d"      Z&d# Z'y$)%r   z&
    RotatingWorkTypeAssign model
    r   Tr   )r   rI   rX   r   r   
Start DaterE   rX   Next SwitchrI   rX   current_work_typezCurrent Work Type)rI   r   r   rX   next_work_typezNext Work Type
   FBased OnrC   choicesrI   rL   rX      Rotate After Dayr   Rotate Every WeekendrC   rE   r   rL   rI   rX   r   Rotate Every Month)rC   rE   r   rX   r   history_setr   basesr   c                   8    e Zd ZdZ ed      Z ed      ZddgZy)RotatingWorkTypeAssign.MetarO   zRotating Work Type AssignzRotating Work Type Assigns-next_change_date!-employee_id__employee_first_nameNrT   rU   rV   rW   r+   rX   rY   orderingr\   r>   r5   r]   r     s+    	 45 <=')LMr>   r]   c                    | j                   r| j                  vt        j                  j	                  d| j                        }|j                         r;|j                         j                  | j                  k7  rt        t        d            | j                  t        j                  j                  j                         j                         k  rt        t        d            y )NT)	is_activer   +Only one active record allowed per employee+Date must be greater than or equal to today)r   r   r   rn   r   r   firstr}   r   r+   
start_datedjangoutilstimezonenowr   ra   siblingss     r5   r   zRotatingWorkTypeAssign.clean  s    >>d..:-55<<D,<,< = H  X^^%5%8%8DGG%C%a(U&VWW??V\\22668==??!!$Q"RSS @r>   N)(rT   rU   rV   rW   r   r   r   r+   r   r   rotating_work_type_id	DateFieldr  r  r  r  r  next_change_dater   r   r   rc   BASED_ONbased_onIntegerFieldrotate_after_dayDAYrotate_every_weekendDAY_DATErotate_everyr   r   r   r   r   historyr   rn   r]   r   r\   r>   r5   r   r   S  s    $&##..z]	K .F--FNNCWAX "!!%%)),J (v''T-@PQ)))..(*+ 'V&&..%'(N  vz]H +v**"4 5 ,6++-. $6##+,	L 'f&&O
 "
G $$QRGN N	Tr>   r   c                        e Zd ZdZ ej
                  d      Z ej                  ed e	d            Z
 ed      Z G d d	      Zd
efdZ fdZ fdZ xZS )EmployeeTypez
    EmployeeType model
    rA   rB   Tr@   rs   r   c                   0    e Zd ZdZ ed      Z ed      Zy)EmployeeType.MetarO   zEmployee TypezEmployee TypesNr   r\   r>   r5   r]   r    s    	 ) 01r>   r]   r^   c                 ,    t        | j                        S r8   )r.   employee_typer`   s    r5   rb   zEmployeeType.__str__  s    4%%&&r>   c                 z   t        |   |i | t        t        dd       }|r|j                  r|j                  j                  dd       }|j                  j                  dd       }t        j                  j                  ||      j                  | j                        j                         rt        d      y )Nr:   ry   r  )r{   r  r|   z1This employee type already exists in this company)r~   r   r   r   r   r   r   r  rn   r   r   r}   r   r   )ra   r   r   r:   rQ   r  r   s         r5   r   zEmployeeType.clean  s    t&v&.)T:w||ll**<>G#LL,,_dCM$$++'.m ,  DGG$	 &G  	r>   c                 J    t        |   |i |  | j                  |i | | S r8   r   r   s      r5   r   zEmployeeType.save  r   r>   )rT   rU   rV   rW   r   rc   r  r   r@   r+   ry   r   rn   r]   r.   rb   r   r   r   r   s   @r5   r  r    sf     %F$$3M'''t!I,WJ#$QRG2 2' '$ r>   r  c                       e Zd ZdZ ej
                  de      Z ej                  e	d e
d            Z e       Z G d d      Zd	efd
Zy)EmployeeShiftDayz 
    EmployeeShiftDay model
    rG   rC   r   Tr@   rs   c                   0    e Zd ZdZ ed      Z ed      Zy)EmployeeShiftDay.MetarO   zEmployee Shift DayzEmployee Shift DaysNr   r\   r>   r5   r]   r#    r   r>   r]   r^   c                 Z    t        t        | j                        j                               S r8   )r.   r+   day
capitalizer`   s    r5   rb   zEmployeeShiftDay.__str__  s    1TXX;))+,,r>   N)rT   rU   rV   rW   r   rc   r  r%  r   r@   r+   ry   r   rn   r]   r.   rb   r\   r>   r5   r   r     sU     &

b#
6C'''t!I,WJ#%G7 7- -r>   r   c            
           e Zd ZdZ ej
                  ddd      Z ej                  ed      Z	 ej
                  ddd	d	e
g
      Z ej
                  dde
g      Z ej                  ed	 ed            Z ej"                  d      r( ej$                  dd	d	dej&                   ed            Z ed      Z G d d      ZdefdZ fdZ fdZ xZS )EmployeeShiftz
    EmployeeShift model
    rA   FrC   rI   rL   EmployeeShiftSchedule)r   r&   z40:00T)rC   rE   rI   rL   
validatorsz200:00)rC   rE   r+  r@   rs   
attendancezattendance.GraceTimeemployee_shiftz
Grace Time)rI   rL   r   r   rX   employee_shift__company_idc                   0    e Zd ZdZ ed      Z ed      Zy)EmployeeShift.MetarO   zEmployee ShiftzEmployee ShiftsNr   r\   r>   r5   r]   r0         	 )* 12r>   r]   r^   c                 ,    t        | j                        S r8   )r.   r-  r`   s    r5   rb   zEmployeeShift.__str__  s    4&&''r>   c                 z   t        |   |i | t        t        dd       }|r|j                  r|j                  j                  dd       }|j                  j                  dd       }t        j                  j                  ||      j                  | j                        j                         rt        d      y )Nr:   ry   r-  )r{   r-  r|   z2This employee shift already exists in this company)r~   r   r   r   r   r   r   r(  rn   r   r   r}   r   r   )ra   r   r   r:   rQ   r-  r   s         r5   r   zEmployeeShift.clean  s    t&v&.)T:w||ll**<>G$\\--.>EN%%,,'.~ -  DGG$	 &H  	r>   c                 J    t        |   |i |  | j                  |i | | S r8   r   r   s      r5   r   zEmployeeShift.save/  r   r>   )rT   rU   rV   rW   r   rc   r-  r   r   daysr6   weekly_full_time	full_timer@   r+   ry   r   is_installedr   r   grace_time_idr   rn   r]   r.   rb   r   r   r   r   s   @r5   r(  r(    s    &V%%N
 "6!!"2<STD'v''() !  h4H3II (''t!I,WJt&)))")nn<
 $$@AG3 3( ($ r>   r(  )CaseWhenc                   z    e Zd ZdZ ej
                  eej                  d ed            Z	 ej
                  e
ej                   ed            Z ej                  ddeg ed	      
      Z ej                  d ed            Z ej                  d ed            Z ej$                  d ed            Z ej$                  d ed       ed            Z ej                  dd ed       ed            Z ej,                  ed ed            Z ed      Z G d d      ZdefdZ fdZ xZS ) r*  z%
    EmployeeShiftSchedule model
    day_schedulez	Shift Dayr   Shiftr   z08:15   zMinimum Working Hours)rE   rC   r+  rX   Tz
Start Timer   zEnd TimeFzNight Shiftr   zEnable Automatic Check Outz+Enable this to trigger automatic check out.rE   rX   	help_textzAutomatic Check Out Timez^Time at which the horilla will automatically check out the employee attendance if they forget.)rI   rL   rX   rA  r@   rs   $shift_id__employee_shift__company_idc                       e Zd ZdZ ed      Z ed      ZddggZ e e	dd       e	d	d
       e	dd       e	dd       e	dd       e	dd       e	dd      d      gZ
y)EmployeeShiftSchedule.MetarO   zEmployee Shift SchedulezEmployee Shift Schedulesshift_idr%  r   r   )day__daythenr   r   r      r   r(   r      r   r?  r   r&   r   rD   N)rT   rU   rV   rW   r+   rX   rY   rZ   r:  r;  r   r\   r>   r5   r]   rD  `  s    	 23 :;&./hQ/ia0k2jq1hQ/jq1hQ/	
r>   r]   r^   c                 L    | j                   j                   d| j                   S N )rE  r-  r%  r`   s    r5   rb   zEmployeeShiftSchedule.__str__u  s"    --../q
;;r>   c                     | j                   r*| j                  r| j                   | j                  kD  | _        t        |   |i | y r8   )
start_timeend_timeis_night_shiftr~   r   r   s      r5   r   zEmployeeShiftSchedule.savex  s6    ??t}}"&//DMM"ADd%f%r>   ) rT   rU   rV   rW   r   r   r   r   r+   r%  r(  rE  rc   r6   minimum_working_hour	TimeFieldrN  rO  rd   rP  is_auto_punch_out_enabledauto_punch_out_timer   r@   ry   r   rn   r]   r.   rb   r   r   r   s   @r5   r*  r*  8  sf    &

..#{^	C !v  ajH ,6++()./	 "!!t!L/JJvT*FH(V((Q}EUVN 3 3 334AB!
 +&**12l
	 (''t!I,WJ#$JKG
 
*< <& &r>   r*  c                   j   e Zd ZdZ ej
                  d      Z ej                  dd ed            Z	 ej                  edej                   ed	      
      Z ej                  edej                   ed      
      Z ej                  edd      Z ed      Z G d d      ZdefdZd Zd Zy)RotatingShiftz
    RotatingShift model
    rA   rB   r   RotatingShiftAssignr   r   shift1zShift 1)r   r   rX   shift2zShift 2Tr   r   c                   0    e Zd ZdZ ed      Z ed      Zy)RotatingShift.MetarO   Rotating ShiftzRotating ShiftsNr   r\   r>   r5   r]   r[    r1  r>   r]   r^   c                 ,    t        | j                        S r8   r   r`   s    r5   rb   zRotatingShift.__str__  r   r>   c                 8   | j                   | j                  k(  rt        t        d            | j                  r| j                  j                  dg       ng }|r9t        | j                  j                        |d   k(  rt        t        d            |r9t        | j                   j                        |d   k(  rt        t        d            t        t        |      dz
        D ]3  }||   s	||dz      s||   ||dz      k(  s!t        t        d             y )Nz#Select different shift continuouslyadditional_shiftsr   r   r   )
rX  rY  r   r+   r   r   r.   r}   r/   r*   )ra   r_  r   s      r5   r   zRotatingShift.clean  s
   ;;$++%!!$I"JKK ##   $$%8"= 	 T[[^^!48I!8L!L!!$I"JKKT[[^^!48I"8M!M!!$I"JKKs,-12 	TA #(9!a%(@$Q'+<QU+CC)!,Q*RSS	Tr>   c                     t         j                  j                  | j                        }|j                  }|r9|j                  d      }|r"t
        j                  j                  |      }|S d }|S d }|S )Nr|   r_  r   )rV  rn   r   r   r   r(  r   )ra   rotating_shiftr   additional_shift_idsr_  s        r5   r_  zRotatingShift.additional_shifts  s    &..22dgg2>(88#2#6#67J#K #$1$9$9$@$@/ %A %! !  %)! !  !%  r>   N)rT   rU   rV   rW   r   rc   r   r   r+   r   r   r(  r   rX  rY  r   r   r   r   rn   r]   r.   rb   r   r_  r\   r>   r5   rV  rV  ~  s     6r*D(&((%::K V..y\	F V..y\	F 'f&&O
 $$QRG3 3 T*!r>   rV  c            
       8   e Zd ZdZ ej
                  dej                   ed            Z ej
                  e	ej                   ed            Z
 ej                  ej                  j                  j                   ed            Z ej                  d ed	      
      Z ej
                  eej                  dd ed            Z ej
                  eej                  dd ed            Z ej*                  dedd ed            Z ej0                  ddd ed            Z ej*                  ddedd ed            Z ej*                  dddde ed            Z ej<                  edd      Z  e!de"g      Z# e$d       Z% G d! d"      Z&d# Z'y$)%rW  z#
    RotatingShiftAssign model
    r   r   r   r\  r   r   Tr   r   current_shiftzCurrent Shiftr   rI   r   rX   
next_shiftz
Next Shiftr   Fr   r   r   r   )rI   rL   rE   rX   r   r   r   r   r   )rC   rL   rI   rE   r   rX   r   r   r   r   c                   8    e Zd ZdZ ed      Z ed      ZddgZy)RotatingShiftAssign.MetarO   zRotating Shift AssignzRotating Shift Assignsr   r   Nr   r\   r>   r5   r]   rh    s+    	 01 89')LMr>   r]   c                    | j                   r| j                  vt        j                  j	                  d| j                        }|j                         r;|j                         j                  | j                  k7  rt        t        d            | j                  t        j                  j                  j                         j                         k  rt        t        d            y )NT)r   employee_id__idr  r  )r   employee_id_idrW  rn   r   r   r  r}   r   r+   r  r  r  r  r  r   r	  s     r5   r   zRotatingShiftAssign.clean  s    >>d11=*22990C0C : H  X^^%5%8%8DGG%C%a(U&VWW??V\\22668==??!!$Q"RSS @r>   N)(rT   rU   rV   rW   r   r   r   r+   r   rV  rotating_shift_idr  r  r  r  r  r  r  r(  rd  rf  rc   r  r  r  r  r  r  r  r  r   r   r   r   r   r  r   rn   r]   r   r\   r>   r5   rW  rW    s    $&##v~~AjMK *))a@P>Q "!!%%)),J (v''T-@PQ%F%%..$'M #""..!|_J  vz]H +v**qq9K7L ,6++-. $6##+,L 'f&&O
 "
G $$QRGN N	Tr>   rW  c                   T    e Zd Z ej                  d      Z ej                         Zy)BaserequestFilezbase/request_filesrH   N)rT   rU   rV   r   rk   filerm   rn   r\   r>   r5   rn  rn  #  s#    6&:;DfnnGr>   rn  c            
           e Zd ZdZ ej
                  dej                  dd ed            Z ej
                  e	ej                  d ed      	      Z
 ej
                  e	ej                  ddd
 ed            Z ej                  dej                  j                  j                    ed            Z ej                  dd ed            Z ej&                  d ed            Z ej*                  d ed            Z ej*                  d ed            Z ej*                  d ed            Z ej*                  d      Z edeg      Z ed      Z G d d      Z fdZ d Z!d  Z"d! Z#d"e$fd#Z% xZ&S )$WorkTypeRequestz
    WorkTypeRequest model
    r   Twork_type_requestr   re  requested_work_typezRequesting Work Typer   previous_work_typezPrevious Work Typer   rI   rL   r   rX   Requested DaterI   rE   rX   Requested TillrI   rL   rX   Descriptionr   FPermanent Requestr   ApprovedCanceledrD   r   r   r   c                   :    e Zd ZdZ ed      Z ed      ZdZdgZy)WorkTypeRequest.MetarO   zWork Type RequestzWork Type Requests))approve_worktyperequestzApprove Work Type Request)cancel_worktyperequestzCancel Work Type Request-idN	rT   rU   rV   rW   r+   rX   rY   permissionsr   r\   r>   r5   r]   r  W  s3    	 ,- 45

 
r>   r]   c                     t        t        dd       }| j                  st        |   |i | y |r"t        |       t        j                  |d       y y Nr:   z$The request entry cannot be deleted.r   r   approvedr~   deleter=   r   warningra   r   r   r:   r   s       r5   r  zWorkTypeRequest.deletef  J    .)T:}}GND+F+w'  *PQ r>   c                    t         j                  j                  | j                  dd| j                  | j
                  g| j                  | j
                  g      j                  | j                        }|ryt         j                  j                  | j                  dd| j                  | j                        j                  | j                        }|ry| j
                  r_t         j                  j                  | j                  dd| j
                  | j
                        j                  | j                        }|ryt         j                  j                  | j                  dd| j                        }|ryyNTF)r   r  canceledrequested_date__rangerequested_till__ranger|   )r   r  r  requested_date__lterequested_till__gte)r   r  r  requested_date__exact)rr  rn   r   r   requested_daterequested_tillr   r}   )ra   !approved_work_type_requests_rangeapproved_work_type_requestsapproved_work_type_requests_2approved_permanent_reqs        r5   is_any_work_type_request_existsz/WorkTypeRequest.is_any_work_type_request_existso  so   ,;,C,C,J,J((#'#6#68K8K"L#'#6#68K8K"L -K -
 'TWW'
 	* -&5&=&=&D&D(( $ 3 3 $ 3 3 'E '
 'TWW'
 	$ ',;,C,C,J,J ,,$($7$7$($7$7 -K - gg! * -!0!8!8!?!?(("&"5"5	 "@ "
 "r>   c                 (   t        t        j                  dd       }|j                  j                  sW| j
                  t        j                  j                  j                         j                         k  rt        t        d            | j                  r-| j                  | j
                  k  rt        t        d            | j                         rt        t        d            | j                  s!| j                  st        t        d            y y )Nr:   r  4End date must be greater than or equal to start datez;A work type request already exists during this time period.!Requested till field is required.)r   r   r   useris_superuserr  r  r  r  r  r   r   r+   r  r  is_permanent_work_typera   r:   s     r5   r   zWorkTypeRequest.clean  s    -<<iN||((""V\\%:%:%>%>%@%E%E%GG%a(U&VWW4#6#69L9L#L!HI  //1!OP  **&&%a(K&LMM ' +r>   c                 t    | j                   rt        d      S | j                  rt        d      S t        d      S )NRejectedr}  	Requested)r  r+   r  r`   s    r5   request_statuszWorkTypeRequest.request_status  s;     }} jM	
 $(==!J-	
 78n	
r>   r^   c                 z    | j                   j                   d| j                   j                   d| j                   S Nz             r   r   employee_first_nameemployee_last_namer  r`   s    r5   rb   zWorkTypeRequest.__str__  D    ""667 8001T5H5H4IK 	Kr>   )'rT   rU   rV   rW   r   r   r   r+   r   r   work_type_idprevious_work_type_idr  r  r  r  r  r  r  rf   descriptionrd   r  r  r  work_type_changedr   r   r  r   rn   r]   r  r  r   r  r.   rb   r   r   s   @r5   rr  rr  (  s    $&##..(z]K %6$$..*-.	L .F--..)+, &V%%6<<00441EUCVN &V%%A.>,?N #&""1];KLK0V00A&9$: #v""5q}MH"v""5q}MH+++E:"
G $$QRG
 
R%NN"
K Kr>   rr  c                      e Zd ZdZddlmZ  ej                  eej                        Z
 ej                  eej                        Z ej                  d ed            Z ej                  ed      Z ej$                         Zd	efd
Zy)WorkTypeRequestCommentz&
    WorkTypeRequestComment Model
    r   r   r   TCommentr   rL   r^   c                     | j                    S r8   commentr`   s    r5   rb   zWorkTypeRequestComment.__str__      ,, r>   N)rT   rU   rV   rW   employee.modelsr   r   r   rr  CASCADE
request_idr   rf   r+   r  r   rn  filesrm   rn   r.   rb   r\   r>   r5   r  r    s     )"""?fnnMJ#&##HGKfDq|DG"F""?$?EfnnG! !r>   r  c            
           e Zd ZdZ ej
                  dej                  dd ed            Z ej
                  e	ej                  d ed      	      Z
 ej
                  e	ej                  ddd
 ed            Z ej                  dej                  j                  j                    ed            Z ej
                  dej                  ddd ed            Z ej&                  d ed            Z ej&                  d ed            Z ej                  dd ed            Z ej.                  d ed            Z ej&                  d ed            Z ej&                  d ed            Z ej&                  d ed            Z ej&                  d      Z edeg      Z e d      Z! G d d      Z"d  Z#d! Z$ fd"Z% fd#Z&d$e'fd%Z( xZ)S )&ShiftRequestz
    ShiftRequest model
    r   Tshift_requestr   re  requested_shiftzRequesting Shiftr   previous_shiftzPrevious Shiftrv  rw  rx  reallocate_shift_requestzReallocate EmployeeFr}  r   r~  ry  rz  r{  r   r|  rD   r   r   r   c                   :    e Zd ZdZ ed      Z ed      ZdZdgZy)ShiftRequest.MetarO   zShift RequestzShift Requests))approve_shiftrequestzApprove Shift Request)cancel_shiftrequestzCancel Shift Requestr  Nr  r\   r>   r5   r]   r    s2    	 ) 01

 
r>   r]   c                 @   t        t        j                  dd       }|j                  j                  sc| j
                  sW| j                  t        j                  j                  j                         j                         k  rt        t        d            | j                  r-| j                  | j                  k  rt        t        d            | j                         rt        t        d            | j                   s!| j                  st        t        d            y y )Nr:   r  r  zAAn approved shift request already exists during this time period.r  )r   r   r   r  r  r   r  r  r  r  r  r   r   r+   r  is_any_request_existsis_permanent_shiftr  s     r5   r   zShiftRequest.clean  s    -<<iN||((77t22V\\5J5J5N5N5P5U5U5WW%a(U&VWW4#6#69L9L#L!HI  %%'!UV  &&&&%a(K&LMM ' 'r>   c                    t         j                  j                  | j                  dd| j                  | j
                  g| j                  | j
                  g      j                  | j                        }|ryt         j                  j                  | j                  dd| j                  | j                        j                  | j                        }|ry| j
                  r_t         j                  j                  | j                  dd| j
                  | j
                        j                  | j                        }|ryt         j                  j                  | j                  dd| j                        }|ryyr  )r  rn   r   r   r  r  r   r}   )ra   approved_shift_requests_rangeapproved_shift_requestsapproved_shift_requests_2r  s        r5   r  z"ShiftRequest.is_any_request_exists  sm   (4(<(<(C(C((#'#6#68K8K"L#'#6#68K8K"L )D )
 'TWW'
 	& )"."6"6"="=(( $ 3 3 $ 3 3 #> #
 'TWW'
 	  #(4(<(<(C(C ,,$($7$7$($7$7 )D ) gg! & )!-!5!5!<!<(("&"5"5	 "= "
 "r>   c                 $    t        |   |i | y r8   )r~   r   r   s      r5   r   zShiftRequest.saveE  s    d%f%r>   c                     t        t        dd       }| j                  st        |   |i | y |r"t        |       t        j                  |d       y y r  r  r  s       r5   r  zShiftRequest.deleteH  r  r>   r^   c                 z    | j                   j                   d| j                   j                   d| j                   S r  r  r`   s    r5   rb   zShiftRequest.__str__Q  r  r>   )*rT   rU   rV   rW   r   r   r   r+   r   r(  rE  previous_shift_idr  r  r  r  r  r  reallocate_tord   reallocate_approvedreallocate_canceledr  rf   r  r  r  r  shift_changedr   r   r  r   rn   r]   r   r  r   r  r.   rb   r   r   s   @r5   r  r    s    $&##..$z]K !v  ..&)*	H *))..%'( &V%%6<<00441EUCVN &F%%../,-M .&--e!J-X-&--e!J-X%V%%A.>,?N #&""1];KLK,,,A&9$: #v""5q}MH"v""5q}MH'F''6M"
G $$QRG
 
N$%N&RK Kr>   r  c                      e Zd ZdZddlmZ  ej                  eej                        Z
 ej                  eej                        Z ej                  ed      Z ej                  d ed            Z ej$                         Zd	efd
Zy)ShiftRequestCommentz#
    ShiftRequestComment Model
    r   r  r  Tr  r  r   r^   c                     | j                    S r8   r  r`   s    r5   rb   zShiftRequestComment.__str__c  r  r>   N)rT   rU   rV   rW   r  r   r   r   r  r  r  r   r   rn  r  rf   r+   r  rm   rn   r.   rb   r\   r>   r5   r  r  V  s     )"""<6>>JJ#&##HGK"F""?$?EfDq|DGfnnG! !r>   r  c                       e Zd Z ej                  d      Z ej                  d      Z ej                  eddej                        Z
 ed      Zd Zy	)
TagsrJ   rB   TF)rI   editabler   ry   related_company_fieldc                     | j                   S r8   titler`   s    r5   rb   zTags.__str__o      zzr>   N)rT   rU   rV   r   rc   r  colorr   r@   r   ry   r   rn   rb   r\   r>   r5   r  r  g  sV    F+EF+E"""dUfnnJ $,GGr>   r  c            	           e Zd Z ej                  dd      Z ej                         Z ej                  e	ddej                   ed            Z ed      Zdefd	Zy
)HorillaMailTemplate   T)rC   uniquer@   rI   rL   r   rX   ry   r  r^   c                     | j                    S r8   r  r`   s    r5   rb   zHorillaMailTemplate.__str__  s    **r>   N)rT   rU   rV   r   rc   r  rf   bodyr   r@   r  r+   ry   r   rn   r.   rb   r\   r>   r5   r  r  s  sg    F48E6D"""..y\J $,GG r>   r  c                       e Zd ZdZ ej
                  dd ed            Z ej                  d ed            Z	 ej                  dd ed            Z ej
                  dd ed	            Z ej
                  dd ed
            Z ej
                  dd ed            Z ej                  d ed            Z ej                  d ed            Z ej                  d ed            Z ej                  d ed            Z ej                  d ed            Z ej*                  eej.                  dd      Zd Zd Zd fdZ G d d      Z xZS )DynamicEmailConfigurationz?
    SingletonModel to keep the mail server configurations
    T   z
Email Host)rI   rC   rX   z
Email Portr   zDefault From EmailzEmail Host UsernamezDisplay NamezEmail Authentication PasswordzUse TLSr   FzUse SSLzFail SilentlyzPrimary Mail ServerzEmail Send Timeout (seconds))r   rI   rL   c                     | j                   r | j                  rt        t        d            | j                  s#| j
                  st        dt        d      i      y y )NzZ"Use TLS" and "Use SSL" are mutually exclusive, so only set one of those settings to True.ry   zThis field is required)use_ssluse_tlsr   r+   ry   
is_primaryr`   s    r5   r   zDynamicEmailConfiguration.clean  sV    <<DLL!A  t!<3K1L"MNN (7r>   c                     | j                   S r8   )usernamer`   s    r5   rb   z!DynamicEmailConfiguration.__str__  s    }}r>   c                    | j                   r0t        j                  j                  d      j	                  d       t        j                  j                         sd| _         t        |   |i | t        j                  j                  | j                        j                  | j                        }|j                         r| j                          y )NT)r  F)ry   r|   )r  r  rn   r   updater   r~   r   ry   r   r}   r  )ra   r   r   servers_same_companyr   s       r5   r   zDynamicEmailConfiguration.save  s    ??%--444ELL  M  )00779"DOd%f%8@@GG  H  

'TWW'
 	  &&(KKMr>   c                       e Zd Z ed      Zy)DynamicEmailConfiguration.MetazEmail ConfigurationN)rT   rU   rV   r+   rX   r\   r>   r5   r]   r    s    ./r>   r]   r^   N)rT   rU   rV   rW   r   rc   r+   hostSmallIntegerFieldport
EmailField
from_emailr  display_namepasswordrd   r  r  fail_silentlyr  timeoutOneToOneFieldr@   r  ry   r   rb   r   r]   r   r   s   @r5   r  r    s    6#AlOTD#6##AlOLD"""c2F0GJ  v,-H $6##~&L  v67H "f!!$Qy\JG!f!!%a	lKG'F''AoDVWM$$$A&;$<J 'f&&"@ AG &%%6>>DJ	O 0 0r>   r  ) z	---------requested_dayszLeave Requested Daysequalz
Equal (==)notequalzNot Equal (!=)r/   RangeltzLess Than (<)gtzGreater Than (>)lezLess Than or Equal To (<=)gezGreater Than or Equal To (>=)	icontainsContainsc            	           e Zd Z ej                  eej                        Z ej                  de	      Z
 ej                  dedd      Z ej                  ddd ed            Z ej                  ddd ed	            Z ej                  ddd ed
            Z ej"                         Z ej                  eddej                   ed            ZdefdZ fdZ fdZd Z xZS )MultipleApprovalConditionr  rF   r!  T)rC   r   rI   rL   d   zCondition Value)rC   rI   rL   rX   zStarting ValuezEnding Valuer@   r  r^   c                 8    | j                    d| j                   S rK  )condition_fieldcondition_operatorr`   s    r5   rb   z!MultipleApprovalCondition.__str__	  s!    &&'q)@)@(ABBr>   c                     | j                   rt        j                  j                  | j                  | j
                  | j                  | j                   | j                        j                  | j                        }|rt        t        d            | j
                  dk(  r| j                  dk7  r9| j                   st        dt        d      i      	 t        | j                         }n| j                  r| j                  st        dt        d	      i      	 t        | j                        }	 t        | j                        }||k(  rt        dt        d      i      ||k  rt        dt        d      i      t!        | D  |i | y # t        $ r}t        dt        d      i      d }~ww xY w# t        $ r}t        dt        d
      i      d }~ww xY w# t        $ r}t        dt        d      i      d }~ww xY w)N)rz   r  r  condition_valuery   r|   z3A condition with the provided fields already existsr  r/   r  z0Please enter a numeric value for condition valuezlPlease enter a valid numeric value for the condition value when the condition field is Leave Requested Days.z$Please specify condition value rangezkPlease enter a valid numeric value for the starting value when the condition field is Leave Requested Days.ziPlease enter a valid numeric value for the ending value when the condition field is Leave Requested Days.z<End value must be different from the start value in a range.z:End value must be greater than the start value in a range.)r  r  rn   r   rz   r  r  ry   r   r   r   r+   floatr0   condition_start_valuecondition_end_valuer~   r   )	ra   r   r   instancefloat_valuer4   start_value	end_valuer   s	           r5   r   zMultipleApprovalCondition.clean  s9   088???? $ 4 4#'#:#: $ 4 4?? @  gg!  %KL  #33&&'1++)0! R3 	"'(<(<"=K 119Q9Q)0! F3 	"'(B(B"CK	 %d&>&> ?I )+)0! ^3  +)0! \3  	t&v&m " )0! !O3 & " )0! !N3  " )0! !L3 sH   F F2 0G 	F/F**F/2	G;GG	G="G88G=c                 n    | j                   dk7  rd | _        d | _        nd | _        t	        |   |i | y )Nr/   )r  r  r  r  r~   r   r   s      r5   r   zMultipleApprovalCondition.save]  s:    ""g-)-D&'+D$#'D d%f%r>   c                 $   g }ddl m} t        j                  j	                  | j
                        j                  d      }|D ]I  }|j                  }|s|j                  n|j                  j                  |      }|j                  |       K |S )Nr   r  )condition_idsequencer|   )r  r   MultipleApprovalManagersrn   r   r   order_byr   reporting_managerr   append)	ra   r   r   managersr   querysetqueryemp_idemployees	            r5   approval_managersz+MultipleApprovalCondition.approval_managerse  s    ,+33:: ; 

(:
 	  	&E&&F  ''%%))V)4 
 OOH%	& r>   )rT   rU   rV   r   r   rr   r  rz   rc   FIELD_CHOICEr  CONDITION_CHOICEr  r+   r  r  r  rm   rn   r@   ry   r.   rb   r   r   r-  r   r   s   @r5   r  r    s   """:HJ&f&&O *)) 0t4 'f&&()	O -F,,'(	 +&**~&	 fnnG"""..y\JC CO'b&r>   r  c                       e Zd Z ej                  eej                        Z ej                  dd      Z	 ej                  dd      Z
 ej                  ddd      Z ej                         Zd Zy)	r$  r  FrI   rL   Tr  r)  c                 v    | j                   }|r*| j                  j                  dd      j                         }|S )Nr+   rL  )r   r&  replacer  )ra   managers     r5   get_managerz$MultipleApprovalManagers.get_manager  s6    "",,44S#>DDFGr>   N)rT   rU   rV   r   r   r  r  r"  r  r#  r   rc   r&  rm   rn   r5  r\   r>   r5   r$  r$  x  sq    $6$$!V^^L #v""U;H%&%%4t<K(((Cd$OfnnGr>   r$  c            
            e Zd ZdZddlmZ ddlmZ  ej                  eej                  ddd ed            Z ej                  d	 ed
      g      Z ej                         Z fdZd Z xZS )DynamicPaginationz4
    model for storing pagination for employees
    r   )r
   )MinValueValidatorTdynamic_paginationr
   )r   rL   rI   r   rX   rA   r   )rE   r+  c                 l    t        t        dd       }|j                  }|| _        t	        |   |i | y )Nr:   )r   r   r  user_idr~   r   )ra   r   r   r:   r  r   s        r5   r   zDynamicPagination.save  s2    .)T:||d%f%r>   c                 8    | j                    d| j                   S )N|)r;  
paginationr`   s    r5   rb   zDynamicPagination.__str__  s    ,,q 122r>   )rT   rU   rV   rW   django.contrib.auth.modelsr
   django.core.validatorsr8  r   r  r  r+   r;  r  r>  rm   rn   r   rb   r   r   s   @r5   r7  r7    ss     08"f""..)vYG %$$R=Nq=Q<RSJfnnG&3r>   r7  c                   <    e Zd ZdZ ej
                  d      Zd Zy)
AttachmentzE
    Attachment model for multiple attachments in announcements.
    zattachments/ro  c                 .    | j                   j                  S r8   )rp  r   r`   s    r5   rb   zAttachment.__str__  s    yy~~r>   N)rT   rU   rV   rW   r   rk   rp  rb   r\   r>   r5   rB  rB    s      6n5Dr>   rB  c                   \    e Zd ZdZ ej
                  ddd      Z ej                         Zy)AnnouncementExpirezb
    This model for setting a expire days for announcement if no expire date for announcement
    TrJ   rI   rL   rE   N)	rT   rU   rV   rW   r   r  r5  rm   rn   r\   r>   r5   rE  rE    s-     6DbADfnnGr>   rE  c                      e Zd ZdZddlmZ  ej                  d      Z ej                  d      Z
 ej                  edd	      Z ej                  dd
      Z ej                  edd	      Z ej                  ed      Z ej                  ed      Z ej                  edd      Z ej.                  d      Z ed      Zd Zd Zd Zy)Announcementz;
    Announcement Model for storing all announcements.
    r   r  r  rB   T)rI   announcement_attachments)r   rL   r1  announcement_employeesr  announcement)rL   r   FrD   ry   r  c                 :    | j                   j                  d      S )zO
        This method is used to get the view count of the announcement
        T)viewed)announcementview_setr   r`   s    r5   	get_viewszAnnouncement.get_views  s     ((//t/<<r>   c                     t         j                  j                  | j                  d      }g }|D ]  }|j	                  |j
                          |S )NT)announcement_id__idrM  )AnnouncementViewrn   r   r}   r'  r  )ra   	viewed_by
viewed_empr   s       r5   rS  zAnnouncement.viewed_by  sT    $,,33 $ 4 
	 
 	&Aaff%	&r>   c                     | j                   S r8   r  r`   s    r5   rb   zAnnouncement.__str__  r  r>   N)rT   rU   rV   rW   r  r   r   rc   r  rf   r  r   rB  attachmentsr  expire_date	employeesrr   rz   r   r   r@   ry   rd   disable_commentsr   rn   rO  rS  rb   r\   r>   r5   rH  rH    s     )F,E"&""-K(&((!;4K #&""D9K&&&7tI (''
$?J)6))+TBL'''#J
 +v**59#,GG=r>   rH  c                       e Zd ZdZddlmZ  ej                  eej                        Z
 ej                  eej                        Z ej                  d ed      d      Z ej                         Zy	)
AnnouncementCommentz#
    AnnouncementComment Model
    r   r  r  Tr  rF   )rI   rX   rC   N)rT   rU   rV   rW   r  r   r   r   rH  r  announcement_idr   rf   r+   r  rm   rn   r\   r>   r5   r[  r[    se     )'f''OO#&##HGKfDq|PSTGfnnGr>   r[  c                       e Zd ZdZ ej
                  eej                        Z ej
                  e	ej                        Z
 ej                  d      Z ej                  dd      Z ej                         Zy)rR  z!
    Announcement View Model
    r  FrD   T)auto_now_addrI   N)rT   rU   rV   rW   r   r   r
   r  r  rH  rK  rd   rM  DateTimeField
created_atrm   rn   r\   r>   r5   rR  rR    sm     6TV^^<D$6$$\V^^LL V  /F%%%4dCJfnnGr>   rR  c                   X   e Zd ZdZddgZ ej                  d      Z ej                  d      Z	 ej                         Z ej                         Z ej                  de      Z ej                  d	      Z ej                          Z ej$                  eej(                  dd
      Zy)EmailLogz 
    EmailLog Keeping model
    )sentSent)failedFailedrF   rB   r&   r!  T)r^  Fr   rI   r  N)rT   rU   rV   rW   statusesr   rc   subjectrf   r  r  r   tostatusr_  r`  rm   rn   r   r@   r  ry   r\   r>   r5   rb  rb     s     !"67Hf#.G6s+D"""$J				BVH=F%%%48JfnnG"""6>>uJr>   rb  c                       e Zd ZdZg dZ ej                  eej                        Z	 ej                  de      Zd Zy)DriverViewedz-
    Model to store driver viewed status
    ))	dashboardrn  )pipelinero  )settingsrp  r  r   r!  c                 P    | j                   j                  j                  dd      S )zD
        This method is used to access all the viewd driver
        rM  T)flat)r  driverviewed_setvalues_listr`   s    r5   user_viewedzDriverViewed.user_viewed  s$     yy))55hT5JJr>   N)rT   rU   rV   rW   r   r   r   r
   r  r  rc   rM  ru  r\   r>   r5   rm  rm    sB    G
 6TV^^<DVW=FKr>   rm  c                       e Zd ZddlmZ  ej                  eej                        Z ej                   e
d      edd      Zd Zy)	DashboardEmployeeChartsr   r  r  zExcluded ChartsT)rX   rE   rL   rI   c                      | j                    dS )Nz	 - charts)r,  r`   s    r5   rb   zDashboardEmployeeCharts.__str__.  s    --	**r>   N)rT   rU   rV   r  r   r   r   r  r,  r   r+   listchartsrb   r\   r>   r5   rw  rw  &  sC    ( v  V^^DHV()4t$F+r>   rw  c                       e Zd Z ej                  d      Z ej                  eddej                  d      Z	 ej                         Zd Zy)BiometricAttendanceFrD   Tbiometric_enabled_company)rI   r  r   r   c                     | j                    S r8   )r8  r`   s    r5   rb   zBiometricAttendance.__str__=  s    ##$%r>   N)rT   rU   rV   r   rd   r8  r   r@   r   ry   rm   rn   rb   r\   r>   r5   r|  r|  2  sN    &6&&u5L"""..0J fnnG&r>   r|  c                  
    dg iS )Nallowed_ipsr\   r\   r>   r5   default_additional_datar  A  s    2r>   c                   l    e Zd ZdZ ej
                  d      Z ej                  dde      Z	d Z
d Zy)	AttendanceAllowedIPa  
    Represents client IP addresses that are allowed to mark attendance.
    Usage:
        - This model is used to store IP addresses that are permitted to access the attendance system.
        - It ensures that only authorized IP addresses can mark attendance.
    FrD   TrF  c                     | j                   j                  dg       }|D ]  }	 t        j                  |        y# t        $ r t        d|       w xY w)zo
        Validate that all entries in `allowed_ips` are either valid IP addresses or network prefixes.
        r  z&Invalid IP address or network prefix: N)r   r   	ipaddress
ip_networkr0   r   )ra   r  ips      r5   r   zAttendanceAllowedIP.cleanR  sg     **..}bA 	UBU$$R(	U  U%(Nrd&STTUs	   ;Ac                      d| j                    S )NzAttendanceAllowedIP - )
is_enabledr`   s    r5   rb   zAttendanceAllowedIP.__str__]  s    ''899r>   N)rT   rU   rV   rW   r   rd   r  r   r  r   r   rb   r\   r>   r5   r  r  E  s@     %$$U3J&f&&'>O	U:r>   r  c                   h    e Zd Z ej                  d ed       ed            Z G d d      Zd Zy)	TrackLateComeEarlyOutTEnablez[By enabling this, you track the late comes and early outs of employees in their attendance.r@  c                   ,    e Zd Z ed      Z ed      Zy)TrackLateComeEarlyOut.MetazTrack Late Come Early OutzTrack Late Come Early OutsNrw   r\   r>   r5   r]   r  j  s    45 <=r>   r]   c                 P    | j                   rt        d      n
t        d      }d| S )NenableddisabledzTracking late come early out )	is_enabler+   )ra   trackings     r5   rb   zTrackLateComeEarlyOut.__str__n  s$    #'>>1Y<q}.xj99r>   N)	rT   rU   rV   r   rd   r+   r  r]   rb   r\   r>   r5   r  r  a  s8    ###x[i
I> >:r>   r  c                   d   e Zd Z ej                  dd ed            Z ej                   ed            Z ej                  dd ed      	      Z	 ej                  d ed
            Z ej                  edej                   ed            Z ed      Zd Zddej&                  fdZy)HolidaysrJ   FName)rC   rI   rX   r   )rX   TzEnd Daterz  	Recurringr   r@   )rI   r   rX   ry   r  c                     | j                   S r8   )r   r`   s    r5   rb   zHolidays.__str__  s    yyr>   Nr^   c                 t    | xs t        j                         } t        j                  j	                  | |       S )at  
        Retrieve holidays that overlap with the given date (default is today).

        Args:
            today (date, optional): The date to check for holidays. Defaults to the current date.

        Returns:
            QuerySet: A queryset of `Holidays` instances where the given date falls between
                    `start_date` and `end_date` (inclusive).
        )start_date__lteend_date__gte)r   todayr  rn   r   )r  s    r5   today_holidayszHolidays.today_holidays  s0     %&&uE&RRr>   r8   )rT   rU   rV   r   rc   r+   r   r  r  end_daterd   	recurringr   r@   r   ry   r   rn   rb   QuerySetr  r\   r>   r5   r  r  s  s    6rAfIND!!!q?JvTAjMRH###E+OI"""..y\	J $,GGSfoo Sr>   r  c                       e Zd Z ej                  dedd      Z ej                  de      Z ej                  e
dej                        Z ed      Z G d d	      Zd
 Zy)CompanyLeavesr  T)rC   r   rL   rI   r!  )rI   r   ry   r  c                       e Zd ZdZy)CompanyLeaves.Meta)based_on_weekbased_on_week_dayN)rT   rU   rV   rZ   r\   r>   r5   r]   r    s    @r>   r]   c                     t        t              j                  | j                         dt        t              j                  | j
                         S )Nz | )r   	WEEK_DAYSr   r  WEEKSr  r`   s    r5   rb   zCompanyLeaves.__str__  s>    y/%%d&<&<=>c$u+//RVRdRdBeAfggr>   N)rT   rU   rV   r   rc   r  r  r  r  r   r@   r   ry   r   rn   r]   rb   r\   r>   r5   r  r    sj    $F$$TM )((CK"""7PJ#,GGA Ahr>   r  c                       e Zd ZdZ ej
                  dej                  dddd      Z ej                  d      r  ej
                  d	ej                  dd
      Z ej                  d      rh ej
                  ddej                  d      Z ej
                  dej                  ddd      Z ej                  dd      Z ej"                  d      Z ej                  dd      Zd fdZ G d d      Z xZS )PenaltyAccountsz(
    LateComeEarlyOutPenaltyAccount
    r   penalty_accountsFr   T)r   r   r  rX   rI   r,  z%attendance.AttendanceLateComeEarlyOutrg  leavezleave.LeaveRequest)rI   r   r  zleave.LeaveTypez
Leave type)r   rL   rI   rX   g        )rE   rI   rD   c                    t         |           t        j                  d      r.| j                  s"| j
                  rt        dt        d      i      t        j                  d      r.| j                  r"| j
                  st        dt        d      i      | j
                  s"| j                  st        dt        d      i      | j
                  s| j                  r"| j                  st        dt        d      i      y )Nr  leave_type_idz+Specify the leave type to deduct the leave.minus_leaveszCIf a leave type is chosen for a penalty, minus leaves are required.z3Either minus leaves or a penalty amount is requiredzLeave type is required)
r~   r   r   r8  r  r  r   r+   penalty_amountdeduct_from_carry_forward)ra   r   s    r5   r   zPenaltyAccounts.clean  s    W%d.@.@TEVEV! !$Q"RS  W%$*<*<TEVEV!"A]%    )<)<!#QM&  !?!?$$!?A6N4O"PQQr>   c                       e Zd ZdgZy)PenaltyAccounts.Metaz-created_atN)rT   rU   rV   r   r\   r>   r5   r]   r    s	    !?r>   r]   r  )rT   rU   rV   rW   r   r   r   r   r   r8  r  late_early_idleave_request_id
DO_NOTHINGr  
FloatFieldr  rd   r  r  r   r]   r   r   s   @r5   r  r    s    $&##..'K t&)))3nn	
 t!,6,, tv~~PU
 *))''%
 )v((4@$7F$7$7$F!&V&&s>N:# #r>   r  c                   |    e Zd ZddlmZ  ej                  eej                  d      Z ej                  d      Z
y)NotificationSoundr   r  notification_sound)r   r   FrD   N)rT   rU   rV   r  r   r   r  r  r,  rd   sound_enabledr\   r>   r5   r  r    s7    (#v##FNN9MH (F''6Mr>   r  )senderc                    |r]|j                   }t        j                  d      rX|rUt        dd      } |       }|j                  rH|j                  j                          d|_        |j                  j                  j                  |_	        n{|j                  r:d|j                  j                   |_        |j                  j                  |_	        n5dt        j                          |_        t        j                         |_	        d|_        d|_        |j                   |_        d|_        |j%                          d|_        |j&                  j)                  |j*                         |j%                          t        j                  d	      r|j,                  r|j.                  r|j*                  j0                  j3                  |j,                  
      j5                         }t7        |j.                  dz        dz  }|j8                  st;        d|j<                  |z
        |_        nt;        d|j>                  |z
        |_        |j%                          yyyyy)zS
    This is post save method, used to create deduction and cut availabl leave dayspayroll	deduction)r[   modelz penaltyzLeave penalty zPenalty on FTr  )r  rH  r   N) r  r   r8  r   r  get_type_displayr  attendance_idattendance_dateone_time_dater  r  r   r  include_active_employeesis_fixedamountonly_show_under_employeer   specific_employeesaddr   r  r  available_leaver   r  roundr  maxavailable_dayscarryforward_days)	r  r  createdr   r  	Deductionpenalty	availableunits	            r5   &create_deduction_cutleave_from_penaltyr    s   
 !00Y'N/);WIkG%%#+#9#9#J#J#L"MX V**88HH % **"01J1J1S1S0T U(0(A(A(J(J%"-hnn.>-? @(0(8%/4G,#G%44GN/3G,LLN/4G,&&**8+?+?@LLN g&&&%% ,,<<CC&44 D eg  ..23a7D55+.q93K3Kd3R+T	(.1	33d:/	+ NN & ' '5 r>   is_new_employeeFrD   )brW   r  r   r   r   typingr   r  django.appsr   django.contribr   r?  r	   r
   django.core.exceptionsr   	django.dbr   django.db.models.signalsr   django.dispatchr   django.utils.translationr   r+   base.horilla_company_managerr   horillar   horilla.horilla_middlewaresr   horilla.methodsr   horilla.modelsr   horilla_audit.modelsr   r   r  r  r6   r=   r@   rr   r   r   r   r   r/   r.   r  r'  r  r  r   r  Modelr   r(  django.db.modelsr:  r;  r*  rV  rW  rn  rr  r  r  r  r  r  r  r.  r/  r  r$  r7  rB  rE  rH  r[  rR  rb  rm  rw  r|  r  r  r  r  r  r  r  r  add_to_classrd   )r   s   0r5   <module>r     s    . .    # 9 2  . $ 6 > ' 6 3 ' B 	!L/!M
!L/!M
!L/	 	!H+!I,!K.!J-!H+!J-!H+	K !l !D$$ $$NU, U8Hl H0&| &RQ%| Q%h ',Arl3SVSV3 :' (q{)!K.!:q{:q{ ajq|)WT\ WTt*< *Z-v|| -,BL BJ (C&L C&LI!L I!XVT, VTrfll 
HKl HKV!\ !"OK< OKd!, !"	< 	,  O0 O0f q/01
 ao#$%aj	1_	1 !	1)*+	1,-.!J- 	 P Pfv||  3 3:  +< +\
, 
	v|| 	v|| $K6<< K(	+l 	+&&,, &:&,, :8:L :$S| S>hL hA#l A#H7 7 
)O,- --`   #%8V%8%8%G H}. 4s   6Q 