
    vgB|                        d Z ddlmZmZm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m Z m!Z!m"Z"m#Z#m$Z$m%Z%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l0m1Z1 ddl2m3Z3m4Z4 d Z5 G d dejl                        Z7 G d de/      Z8 G d dejl                        Z9 G d de/      Z: G d d e/      Z; G d! d"e/      Z< G d# d$e/      Z= G d% d&e/      Z> G d' d(e/      Z? G d) d*e/      Z@ G d+ d,e/      ZA G d- d.e/      ZB G d/ d0e/      ZCdd1lDmEZE  eEj                  d2        eEj                  d3        eEj                  d4       y5)6zE
models.py

This module is used to register models for employee app

    )datedatetime	timedelta)apps)settings)
PermissionUser)ValidationError)default_storage)models)QuerySet)	post_save)receiver)gettext)gettext_lazy)HorillaCompanyManager)Company
DepartmentEmployeeShiftEmployeeTypeJobPositionJobRoleWorkTypevalidate_time_format)format_timestrtime_seconds)horilla_middlewares)get_horilla_model_class)HorillaModelget_diff)HorillaAuditInfoHorillaAuditLogc                     | S )z9
    Method to implement reporting manager_validator
     )values    #/var/www/horilla/employee/models.pyreporting_manager_validatorr(   +   s	     L    c            
           e Zd ZdZ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fZ ej                  ddd      Z	 ej                  eej                  ddd ed            Z ej                  dd ed            Z ej                  ddd ed            Z ej"                  ddd      Z ej&                  dd      Z ej                  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      Z ej                  d"dd      Z ej8                  dd#      Z ej                  d$ded%      Z ej                  ddd       Z ej@                  dd#      Z! ej                  ddded&      Z" ej@                  dd'      Z# ej                  ddd      Z$ ej                  d"dd      Z% ej                  d"dd      Z& ejN                  d(      Z( ejR                  dd#      Z* ejN                  dddd)      Z+ ejN                  dddd)      Z, e-d*+      Z.d, Z/d- Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z>d< Z?d=e@fd>ZAd? ZB G d@ dA      ZCdB ZDdC ZEdD ZF fdEZG xZHS )FEmployeez
    Employee model
    maleMalefemaleFemaleotherOthersingleSinglemarriedMarrieddivorcedDivorced2   T)
max_lengthnullblankemployee_getr	   	on_deleter;   r:   related_nameverbose_name   Fz
First Namer9   r:   r@   z	Last Namer9   r:   r;   r@   zemployee/profile	upload_tor:   r;      )r9   unique   r9   r9   r;   r:         r:   r;   
   )r9   r:   choicesdefault)r9   r;   r:   rO   rP   r;   r:   rP   )rP   r:   r;   editableemployee_work_info__company_idrelated_company_fieldc                 N    d}| j                   r| j                   j                  }|S )zV
        This method is used to return the profile image path of the employee
        F)employee_profileurl)selfrY   s     r'   	get_imagezEmployee.get_imageu   s(       ''++C
r)   c                 h    | j                   r| j                   d| j                    S | j                  S )z7
        Method will return employee full name
         )employee_last_nameemployee_first_namerZ   s    r'   get_full_namezEmployee.get_full_name~   s@     && '')4+B+B*CD	
 ))	
r)   c                 2    t        t        | dd      dd      S )zK
        This method is used to return the company of the employee
        employee_work_infoN
company_idgetattrr`   s    r'   get_companyzEmployee.get_company   s     wt%94@,PTUUr)   c                     | j                         r| j                         n-t        j                  j                  d      j	                         }|r|j
                  }|r|S dS y)NT)hqzMMM. D, YYYY)rg   r   objectsfilterfirstdate_format)rZ   companyrm   s      r'   get_date_formatzEmployee.get_date_format   sa     ! ''4'0668 	 !--K"-;A>Ar)   c                 2    t        t        | dd      dd      S )zP
        This method is used to return the job position of the employee
        rc   Njob_position_idre   r`   s    r'   get_job_positionzEmployee.get_job_position   s#     D.57H$
 	
r)   c                 2    t        t        | dd      dd      S )zN
        This method is used to return the department of the employee
        rc   Ndepartment_idre   r`   s    r'   get_departmentzEmployee.get_department   s     wt%94@/SWXXr)   c                 2    t        t        | dd      dd      S )I
        This method is used to return the shift of the employee
        rc   Nshift_idre   r`   s    r'   	get_shiftzEmployee.get_shift   s     wt%94@*dSSr)   c                 F    t        t        | dd      d| j                        S )rw   rc   Nemail)rf   r{   r`   s    r'   get_mailzEmployee.get_mail   s!     wt%94@'4::VVr)   c                 "    | j                         S N)r|   r`   s    r'   	get_emailzEmployee.get_email   s    }}r)   c                 2    t        t        | dd      dd      S )zM
        This method is used to return the work type of the employee
        rc   Nwork_type_idre   r`   s    r'   get_work_typezEmployee.get_work_type   s     wt%94@.RVWWr)   c                 2    t        t        | dd      dd      S )Q
        This method is used to return the employee type of the employee
        rc   Nemployee_type_idre   r`   s    r'   get_employee_typezEmployee.get_employee_type   s#     D.57I4
 	
r)   c                 2    t        t        | dd      dd      S )r   rc   Nreporting_manager_idre   r`   s    r'   get_reporting_managerzEmployee.get_reporting_manager   s#     D.57Mt
 	
r)   c                     d| j                          d}| j                  rA| j                  j                  }t        j                  |      r| j                  j
                  }|S )zV
        Method will retun the api to the avatar or path to the profile image
        z!https://ui-avatars.com/api/?name=z&background=random)ra   rX   namer   existsrY   )rZ   rY   full_filenames      r'   
get_avatarzEmployee.get_avatar   s`    
 00B0B0D/EEWX 	    1166M%%m4++//
r)   c                 >   t        j                         }t        j                  d      r| j                  j                  ||      nt               j                         }t        d      }|j                         rY|j                  d      j                         rt        d      }|S |j                  d      rt        d      }|S t        d	      }|S t        j                  d
      r5| j                  j                  |      j                         rt        d      }|S )zM
        This method is used to get the leave status of the employee
        leave)start_date__lteend_date__gtezExpected workingapproved)statuszOn Leave	requestedzWaiting ApprovalzCanceled / Rejected
attendanceattendance_datez
On a break)r   todayr   is_installedleaverequest_setrk   r   none_r   employee_attendances)rZ   r   leaves_requestsr   s       r'   get_leave_statuszEmployee.get_leave_status   s    

   ) !!((e(T" 	
 %&!!#%%Z%8??A:  !''{';-.  01  l+))00 % 1 fh |_Fr)   c                    t        j                  d      rt        j                         }|t	        d      z
  }d}d}t        | j                  j                  ||g      j                  d            }t        |      dk(  r|d   d}}nt        |      dk(  r|\  }}nd	\  }}|}|s|}t        t        |d
d            }d}d}	|r|j                         }t        d||z
        }	t        |      t        |	      ||	|dudS i S )zO
        This method is used to the employees current day shift status
        r      daysN)attendance_date__inr   r      )NNminimum_hour0)forecasted_at_workforecasted_pending_hoursforecasted_at_work_seconds forecasted_pending_hours_secondshas_attendance)r   r   r   r   r   listr   rk   order_bylenr   rf   get_at_work_from_activitiesmaxr   )
rZ   r   	yesterdaytoday_attendanceyesterday_attendanceattendancesr   minimum_hour_secondsat_workr   s
             r'   get_forecasted_at_workzEmployee.get_forecasted_at_work   s9    \*NN$E	q 11I##' ))00)2E(: 1 (,-K ;1$9DQ&6$[!Q&9D6$&69C6$&6)J#1
#2
NC8$  G'($$@@B'*1/Cg/M'O$ '2'&:,78P,Q.54L",D"8  Ir)   c                 z    | j                   j                  t        j                               j	                         S )zF
        This method will returns employees todays attendance
        r   )r   rk   r   r   rl   r`   s    r'   get_today_attendancezEmployee.get_today_attendance#  s3     ((//$NN, 0 

%'	r)   c           
         t        j                  d      ret        dd      }t        dd      }|j                  j	                  | j
                        }|j                  j	                  | j
                        }nd}d}t        j                  d      ret        dd      }t        dd      }|j                  j	                  | j
                        }|j                  j	                  | j
                  	      }nd}d}t        j                  j	                  | j
                  
      }	|	j                         sI|r|j                         s7|r|j                         s%|r|j                         s|r|j                         syg }
g }|	j                         r|
j                  t        d      dd       |j                         r|
j                  t        d      dd       |j                         r|
j                  t        d      dd       |j                         r|
j                  t        d      dd       |j                         r|
j                  t        d      dd       d|
i}	 dt        d      fgt        j                  j	                  d      j                  ddd      D cg c]  \  }}}||r| d| n|f c}}}z   }||d <   |S c c}}}w #  Y |S xY w)!a  
        Determine whether an employee is eligible for archiving based on their
        involvement in various processes.

        Returns:
            dict or bool: A dictionary containing a list of related models
                        if the employee is not eligible for archiving,
                        otherwise, False.

        This method checks the employee's association with different models,
        such as reporting manager, recruitment stage, onboarding stage, onboarding task,
        and recruitment manager. If the employee is not associated with any of these,
        they are considered eligible for archiving. If they are associated,
        a dictionary is returned with a list of related models of that employee.
        
onboardingonboardingstageonboardingtaskemployee_idNrecruitmentstage)stage_managers)recruitment_managers)r   FzReporting managerr   )r@   
field_namezRecruitment managerr   zRecruitment stage managerrecruitment_stage_managerszOnboarding stage manageronboarding_stage_managerzOnboarding task manageronboarding_task_managerrelated_models z---Choose employee---T)	is_activeidr_   r^   r]   employee_choices)r   r   r   rj   rk   pkEmployeeWorkInformationr   appendr   r+   values_list)rZ   OnboardingStageOnboardingTaskonboarding_stage_queryonboarding_task_queryRecruitmentStagerecruitment_stage_queryrecruitment_manager_queryreporting_manager_queryr   related_model_fieldsrelated_models_dictr   
first_name	last_nameREPLACE_EMPLOYEE_CHOICESs                    r'   get_archive_conditionzEmployee.get_archive_condition+  s
     \*5lDUVO4\CSTN%4%<%<%C%CPTPWPW%C%X"$2$:$:$A$Adgg$A$V!%)"$(!]+1-OK+M7CE&+mm&:&:$''&:&R#(3(;(;(B(B%)WW )C )% '+#(,%"9"A"A"H"H!% #I #
 $**,',C,J,J,L&+A+H+H+J%*?*F*F*H).G.N.N.PN#% &--/%%()*=(>&< )//1%%()*?(@&< '--/%%()*E(F&B &,,.%%()*D(E&@ %++-%%()*C(D&? !.#-/3J1K,L+M
 ?G>N>N>U>U"& ?V ?!k$(=?STQ Q
 ;Z $7@:,a	{3jQ ,( ;S#$67 '&Q&&s   *AK ,K
K K Kreturnc                     | j                   | j                   nd}| j                  d| j                   dnd}| j                   d| d| S )Nr   ()r]   )r^   badge_idr_   )rZ   r   r   s      r'   __str__zEmployee.__str__  s[    '+'>'>'JD##PR 	 .2]]-Faa(B**+1YKq
CCr)   c                    t        j                  d      rt        dd      }t        t        j
                  dd      }|t        |d      r|j                  mt        j                         j                         }|t        d      z
  }|j                  j                  ||d      j                  d	d
      }t        |d|       |j                  }| j                   |v S y)zZ
        This method is used to check if the user is in the list of online users.
        r   requestNworking_employeesr   r   T)attendance_date__gteattendance_date__lte!attendance_clock_out_date__isnullr   )flatF)r   r   r   rf   r   _thread_localshasattrr   r   nowr   r   rj   rk   r   setattrr   )rZ   
Attendancer   r   r   r   s         r'   check_onlinezEmployee.check_online  s     \*0|LJ1@@)TRG")<=008$LLN//1E %	q(9 9I(2(:(:(A(A-6-2:> )B ) "k-dk;	 &
 G%8:KL$+$=$=!ww"333r)   c                   n    e Zd ZdZdZdZdgZ ej                  dg ej                  d      d	      gZ
y
)Employee.Metaz#
        Recruitment model
        )r_   r^   r{   ))change_ownprofilezUpdate own profile)view_ownprofilezView Own Profiler_   r   F)badge_id__isnullunique_badge_id)fields	conditionr   N)__name__
__module____qualname____doc__unique_togetherpermissionsorderingr   UniqueConstraintQconstraintsr%   r)   r'   Metar     sQ    	 Q

 "
 $F##"|"&((E:&
r)   r  c                    | j                   }t        j                         }t        |j                  |j                  |j
                        }||k  r.t        |j                  dz   |j                  |j
                        }||z
  j                  S )zC
        This method will calculate the day until birthday
        r   )dobr   r   yearmonthdayr   )rZ   birthdayr   next_birthdays       r'   days_until_birthdayzEmployee.days_until_birthday  si     88

UZZF5  aNM%+++r)   c                     ddl m} |j                  j                  | j	                               j                  d      j                         S )z;
        This method is used to get last send mail
        r   )EmailLog)to__icontainsz-created_at)base.modelsr  rj   rk   r|   r   rl   )rZ   r  s     r'   get_last_sent_mailzEmployee.get_last_sent_mail  s<     	) ##$--/#BXm$UW	
r)   c                 F    t         j                  j                  |       }|S )z
        Function to get all Employee objects of subordinates reporting to a given manager.
        :param manager: Employee object who is the reporting manager.
        :return: QuerySet of Employee objects.
        )(employee_work_info__reporting_manager_id)r+   rj   rk   )rZ   subordinatess     r'   get_subordinate_employeesz"Employee.get_subordinate_employees  s*      ''..59 / 
 r)   c                 p   t         j                  j                  | j                        j	                         }t        |   |i | t        t        j                  dd       }|r4| j                  s(| j                         durd| _
        t        |   |i | | }|rN|j                  |j                  k7  r5|j                  |j                  _        |j                  j                          |j                  | j                  }| j                  }|j                  r|j                  j                    nd}t"        j                  j%                  ||||      }	|	s"t"        j                  j%                  |||      }	|	| _        t&        j                  j)                  d      }
t&        j                  j)                  d	      }|	j*                  j-                  |       |	j*                  j-                  |
       t/        | d
      s0t0        j                  j3                  |        | j                         S | S )N)r   r   FT)usernamer{   passwordis_new_employee)r  r{   r  r   )codenamer   rc   r   )r+   rj   rk   r   rl   supersaverf   r   r   r   r   r{   employee_user_idr  phoner  r	   create_userr   getuser_permissionsaddr   r   get_or_create)rZ   argskwargsprev_employeer   employeer  r  is_new_employee_flaguserr   r   	__class__s               r'   r  zEmployee.save  s    !((//477/;AACd%f%-<<iN4>>d.H.H.JRW.W!DNGL$)&)]00HNNB19H%%.%%**,$$,zzHzzH ,, --=== !
 <<++!! 4	 , D ||//%X 0  %)D! * 2 2 6 6@S 6 T(0044>O4PO!!%%o6!!%%&78t12#++99d9K99;r)   )Ir   r   r   r   transchoice_genderchoice_maritalr   	CharFieldr   OneToOneFieldr	   CASCADEr   r   r_   r^   
ImageFieldrX   
EmailFieldr{   r!  	TextFieldaddresscountrystatecityzip	DateFieldr	  genderqualificationIntegerField
experiencemarital_statuschildrenemergency_contactemergency_contact_nameemergency_contact_relationBooleanFieldr   	JSONFieldadditional_infois_from_onboardingis_directly_convertedr   rj   r[   ra   rg   ro   rr   ru   ry   r|   r   r   r   r   r   r   r   r   r   strr   r   r  r  r  r  r  __classcell__r-  s   @r'   r+   r+   2   sx   
 
v	5?#	%.!M 
5?#	E)$%	U:&'N
  v2DEH+v++..#vY +&**U< *))TAkN )v(($4t FT:EFE f#TEGf"DtDGFTBE6rDAD
&

bt4
@C
&

D
1CVD-F %F$$$TJM$$$$d;J%V%%TnhN #v""D9H(((BTN-V--$dS!1!1!1RdRV!W###D1I&f&&D=O,,,Du 0F//Du $>G
V
YTWX

6*Xc'JD D2
 
*	,

	. .r)   r+   c                   z    e Zd ZdZ ej
                  dd ed            Z ej
                  dd      Zde	fd	Z
y
)EmployeeTagz
    EmployeeTag Model
    r8   TTitlerB   rK   )r9   r:   r   c                     | j                    S r~   titler`   s    r'   r   zEmployeeTag.__str__       **r)   N)r   r   r   r   r   r1  r   rS  colorrK  r   r%   r)   r'   rO  rO    sC     FAgJOEF6E r)   rO  c            
           e Zd ZdZ ej
                  eej                  dd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                  eej                  d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                  eej                  ddd ed            Z ej                  eej                  dd ed            Z ej2                  ed ed            Z ej8                  ddd ed            Z ej<                  ddd ed            Z ej8                  ddd      Z  ej                  e!ejD                  dd ed            Z# ejH                  dd ed            Z% ejH                  dd      Z& ejN                  ddd ed            Z( ejN                  ddd ed             Z) ejT                  dd!      Z+ ejX                  ddd"      Z- e.d#e/g$      Z0 e1       Z2d%e3fd&Z4 fd'Z5 fd(Z6d) Z7d* Z8 xZ9S )+r   z'
    EmployeeWorkInformation model
    Trc   r+   r=   zJob Position)r>   r:   r;   r@   r   z	Work TypezEmployee TypezJob Rolereporting_managerzReporting Managerr   )r>   r;   r:   r@   zEmployee tagr;   r@   r8   zWork LocationrC   rF   Email)r9   r;   r:   r@   rJ   ShiftzJoining Date)r:   r;   r@   rQ   r   zBasic Salary)r:   r;   rP   r@   zSalary Per HourrM   )r:   r;   rP   history_setr?   basesr   c                 8    | j                    d| j                   S )N - )r   rq   r`   s    r'   r   zEmployeeWorkInformation.__str__  s!    ""#3t';';&<==r)   c                 D    | j                          t        |   |i | y r~   )
full_cleanr  r  rZ   r'  r(  r-  s      r'   r  zEmployeeWorkInformation.save  s    d%f%r)   c                 2    t        |   |i | d| _        y )NF)r  __init__skip_historyrb  s      r'   rd  z EmployeeWorkInformation.__init__  s    $)&)!r)   c                     t        |       S zS
        This method is used to return the tracked history of the instance
        r    r`   s    r'   trackingz EmployeeWorkInformation.tracking       ~r)   c                     | j                   }|yt        j                         j                         }||z
  }|j                  }|dz  }|| _        | j                          | S )zT
        This method is to calculate the default value for experience field
        r   g     v@)date_joiningr   r   r   r   r@  r  )rZ   joining_datecurrent_datedelta
total_daysr@  s         r'   experience_calculatorz-EmployeeWorkInformation.experience_calculator  sd     ((||~**, |+ ZZ
  %'
$		r)   ):r   r   r   r   r   r2  r+   r3  r   r   
ForeignKeyr   PROTECTrq   r   rt   r   r   r   r   r   job_role_idr   r   rd   ManyToManyFieldrO  tagsr1  locationr5  r{   mobiler   
DO_NOTHINGrx   r<  rk  contract_end_dater?  basic_salarysalary_hourrG  rH  
FloatFieldr@  r#   r"   historyr   rj   rK  r   r  rd  rh  rp  rL  rM  s   @r'   r   r   $  s    '&&&..)z]K (f''..~&O &F%%..|_M %6$$..{^L )v((..' $&##..z]K -6,,..(*+ #""..y\J "6!!4a.?D  vD1_;MH FdAgJE VF
 !v  ##wZH $6##An,=L )((t$?&6&&qq7HL &&%%qq9J7KK 'f&&D=O"""D!DJ"
G $%G> >&"r)   r   c            	          e Zd ZdZ ej
                  eej                  dd ed            Z	 ej                  d      Z ej                  dddd	
      Z ej                  d      Z ej                  d      Z ej                  ddd      Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  dddd      Z ej*                  dd      Z ed      ZdefdZd Zy)EmployeeBankDetailsz#
    EmployeeBankDetails model
    Temployee_bank_detailsr+   )r>   r:   r?   r@   r8   rI   Fr   )r9   r:   r;   rP      rJ   )r9   r;   zBank Code #1)r9   r@   zBank Code #2rC   rM   +employee_id__employee_work_info__company_idrU   r   c                 8    | j                    d| j                   S )N-)r   	bank_namer`   s    r'   r   zEmployeeBankDetails.__str__  s    ""#1T^^$455r)   c                     | j                   ]t        j                  j                  | j                        j                  | j                         }|rt        dt        d      i      y y )Nr   )account_numberr  zCBank details for an employee with this account number already exist)r  r  rj   excluder   rk   r
   r   )rZ   bank_detailss     r'   cleanzEmployeeBankDetails.clean  su    *.66>> ,, ? fD$7$7f8  %(!a+  	 +r)   N)r   r   r   r   r   r2  r+   r3  r   r   r1  r  r  branchr6  r7  r8  r9  r:  any_other_code1any_other_code2rG  rH  r   rj   rK  r   r  r%   r)   r'   r  r    s+    '&&&..,z]K !  B/I%V%%	N V,Ff#.Gf"DtDGF$7E6r6D&f&&">RO&f&&D>O 'f&&D=O#KG6 6r)   r  c                   ^    e Zd Z ej                  ddd      Z ej                         Zd Zy)	NoteFileszemployee/NoteFilesT)rE   r;   r:   c                 R    | j                   j                  j                  d      d   S )N/)filesr   splitr`   s    r'   r   zNoteFiles.__str__  s     zz$$S)"--r)   N)	r   r   r   r   	FileFieldr  Managerrj   r   r%   r)   r'   r  r    s,    F';4dSEfnnG.r)   r  c                      e Zd ZdZ ej
                  eej                  d      Z ej                   e
d      dd      Z ej                  ed      Z ej
                  eej                  	      Z ed
      ZdefdZy)EmployeeNotez
    EmployeeNote model
    employee_name)r>   r?   Descriptionr  T)r@   r9   r:   r;   r>   r  rU   r   c                     | j                    S r~   )descriptionr`   s    r'   r   zEmployeeNote.__str__  s    ""#$r)   N)r   r   r   r   r   rq  r+   r3  r   r6  r   r  rt  r  
note_files
updated_byr   rj   rK  r   r%   r)   r'   r  r    s     $&##..$K
 #&""}%#DK (''	>J"""8v~~FJ#KG% %r)   r  c                   6    e Zd ZdZ ej
                  d      Zy)PolicyMultipleFilez$
    PoliciesMultipleFile model
    zemployee/policies)rE   N)r   r   r   r   r   r  
attachmentr%   r)   r'   r  r    s     "!!,?@Jr)   r  c                   (    e Zd ZdZ ej
                  d      Z ej                         Z ej                  d      Z
 ej                  edd      Z ej                  ed      Z ej                  ed ed	      
      Z ed      Z fdZ xZS )Policyz
    Policies model
    r8   rI   TrR   F)r;   rS   r  r   rX  rd   c                 t    t        |   |i | | j                  j                         j                          y r~   )r  deleteattachmentsallrb  s      r'   r  zPolicy.delete  s/    ''%%'r)   )r   r   r   r   r   r1  rS  r6  bodyrF  is_visible_to_allrt  r+   specific_employeesr  r  r   r   rd   r   rj   r  rL  rM  s   @r'   r  r    s     F+E6D+++D9///uU(&(();4HK'''t!I,WJ#L1G( (r)   r  c                      e Zd ZdZd ed      fd ed      fd ed      fd ed	      fd
 ed      fgZ ej                  eej                  ddd      Z
 ej                  dd      Z ej                  dedd      Z ej                  dd      Z ej                   ddd      Z edeg      Z ed      Zd Zd Z eee      d        Zy) 
BonusPointzS
    Model representing bonus points for employees with associated conditions.
    z==equals>zgrater than<z	less thanz>=zgreater than or equalz<=zless than or equalTbonus_point)r>   r;   r:   r?   r   z&Use negative numbers to reduce points.)rP   	help_textd   )r9   rO   r;   r:   rQ   r  )r;   r:   r9   r[  r\  r  rU   c                 :    | j                    d| j                   dS )Nr_  z Points)r   pointsr`   s    r'   r   zBonusPoint.__str__E  s     ""#3t{{m7;;r)   c                     t        |       S rg  r    r`   s    r'   rh  zBonusPoint.trackingH  ri  r)   )senderc                     t         j                  j                  |j                        j	                         s!t         j                  j                  |       yy)a  
        Creates a BonusPoint instance for a newly created Employee if one doesn't already exist.

        Args:
            sender (Employee): The model class (Employee) sending the signal.
            instance (Employee): The instance of the Employee model triggering the
                                post-save signal.
            **_kwargs: Additional keyword arguments passed by the signal.
        )employee_id__idr   N)r  rj   rk   r   r   create)r  instance_kwargss      r'   bonus_post_savezBonusPoint.bonus_post_saveN  sE     !!(((ELLN%%(%; Or)   N)r   r   r   r   r   
CONDITIONSr   r2  r+   r3  r   r?  r  r1  encashment_conditionredeeming_pointsr6  reasonr#   r"   r}  r   rj   r   rh  r   r   r  r%   r)   r'   r  r     s&   
 
q{	a	an	q()*	q%&'J '&&&.."K !V  EF ,6++
$T +v**DAVDtDF"
G $KG< i)< *<r)   r  c                       e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  d	      Z ej                  d
e      Z	 ej                  d ed      d      ZdefdZ G d d      Zy)
Actiontypez
    Action type model
    warningWarning
suspension
Suspension	dismissal	Dismissalr8   rI   rK   )r9   rO   FzEnable login block :z[If is enabled, employees log in will be blocked based on period of suspension or dismissal.)rP   r@   r  r   c                     | j                    S r~   rR  r`   s    r'   r   zActiontype.__str__p  rT  r)   c                   ,    e Zd Z ed      Z ed      Zy)Actiontype.MetazAction TypezAction TypesN)r   r   r   r   r@   verbose_name_pluralr%   r)   r'   r  r  s  s    '/r)   r  N)r   r   r   r   r.  choice_actionsr   r1  rS  action_typerF  r   block_optionrK  r   r  r%   r)   r'   r  r  ]  s    
 
E)$%	u\*+	eK()N F+E"&""b.IK&6&&-.oL 0 0r)   r  c                      e Zd ZdZd ed      fd ed      fgZ ej                  e ed            Z	 ej                  eej                        Z ej                  d	
      Z ej                   ded      Z ej$                  dd      Z ej                   dddeg      Z ej,                  d      Z ej0                  ddd      Z ed      ZdefdZ G d d      Zy)DisciplinaryActionz
    Disciplinary model
    r   DayshoursHours	Employees)r@   r  r  rI   rN   )r9   rO   rP   Tr   )r:   rP      z00:00)r9   rP   r:   
validators)r:   zemployee/disciplinerD   r  r   c                     | j                    S r~   )actionr`   s    r'   r   zDisciplinaryAction.__str__  s    ++r)   c                       e Zd ZdgZy)DisciplinaryAction.Metaz-idN)r   r   r   r  r%   r)   r'   r  r    s	    7r)   r  N)r   r   r   r   r   rO   r   rt  r+   r   rq  r  r3  r  r6  r  r1  unit_inr?  r   r   r  r<  
start_dater  r  r   rj   rK  r   r  r%   r)   r'   r  r  x  s    &	"Waj$9:G(&((+OKVzV^^DF"&""c2Kf"gvNG6D!4DF()	E "!!t,J!!!'d$J $$QRG    r)   r  c                       e Zd ZdZ ej
                  dd      Z ej                  edej                        Z
 ed      Zy)	EmployeeGeneralSettingz 
    EmployeeGeneralSetting
       PEP)r9   rP   T)r:   r>   rd   N)r   r   r   r   r   r1  badge_id_prefixrq  r   r3  rd   r   rj   r%   r)   r'   r  r    sA     'f&&!UCO"""7PJ#L1Gr)   r  c                   X    e Zd ZdZ ej
                  d      Z ej                         Zy)ProfileEditFeaturez
    ProfileEditFeature
    FrR   N)	r   r   r   r   r   rF  
is_enabledr  rj   r%   r)   r'   r  r    s)     %$$U3JfnnGr)   r  )ACCESSBILITY_FEATURE)gender_chartzCan view Gender Chart)department_chartzCan view Department Chart)employees_chartzCan view Employees ChartN)Gr   r   r   r   django.appsr   django.confr   django.contrib.auth.modelsr   r	   django.core.exceptionsr
   django.core.files.storager   	django.dbr   django.db.models.queryr   django.db.models.signalsr   django.dispatchr   django.utils.translationr   r   r   r.  base.horilla_company_managerr   r  r   r   r   r   r   r   r   r   !employee.methods.duration_methodsr   r   horillar   horilla.methodsr   horilla.modelsr   horilla_audit.methodsr!   horilla_audit.modelsr"   r#   r(   Modelr+   rO  r   r  r  r  r  r  r  r  r  r  r  accessibility.accessibilityr  r   r%   r)   r'   <module>r     sH   / .    7 2 5  + . $ 1 : >	 	 	 K ' 3 ' * B
cv|| cL	, 	Lfll L^0, 0f. .%< %.A A(\ (&:< :<z0 06 <2\ 2  =    E F    M N    K Lr)   