
    siߣ                     X   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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/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z? ddl@mAZA d ZB G d dej                        ZD G d de8      ZE G d  d!ej                        ZF G d" d#e8      ZG G d$ d%e8      ZH G d& d'e8      ZI G d( d)e8      ZJ G d* d+e8      ZK G d, d-e8      ZL G d. d/e8      ZM G d0 d1e8      ZN G d2 d3e8      ZO G d4 d5e8      ZPdd6lQmRZR  eRj                  d7        eRj                  d8        eRj                  d9        eRj                  d:       y;)<zE
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JsonResponse)static)reversereverse_lazy)gettext)gettext_lazy)HorillaCompanyManager)Company
DepartmentEmployeeShiftEmployeeTypeJobPositionJobRoleWorkTypevalidate_time_format)format_timestrtime_seconds)horilla_middlewares)_thread_locals)get_horilla_model_class)HorillaModelhas_xssupload_pathget_diff)HorillaAuditInfoHorillaAuditLogrender_templatec                     | S )z9
    Method to implement reporting manager_validator
     )values    3/var/www/python-projects/worksol/employee/models.pyreporting_manager_validatorr2   0   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"                  e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j:                  dd#      Z ej                  d$ded%      Z ej                  ddd      Z  ejB                  dd#      Z" ej                  ddded&      Z# ejB                  dd'      Z$ ej                  d(dd      Z% ej                  d"dd      Z& ej                  d"dd      Z' ejP                  d)      Z) ejT                  dd#      Z+ ejP                  dddd*      Z, ejP                  dddd*      Z- e.d+,      Z/d- Z0dXd.Z1d/ Z2d0e3fd1Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z>d< Z?d= Z@d> ZAd? ZBd@ ZCdAdBlDmEZE dC ZFdD ZGdE ZHdF ZIdG ZJd0eKfdHZLdI ZMdJ ZNdK ZOdL ZPdM ZQdN ZRdO ZSdP ZTdQ ZU G dR dS      ZVdT ZWdU ZXdV ZY fdWZZ xZ[S )YEmployeez
    Employee model
    maleMalefemaleFemaleotherOthersingleSinglemarriedMarrieddivorcedDivorced2   T
max_lengthnullblankemployee_getr	   	on_deleterF   rE   related_nameverbose_name   Fz
First NamerD   rE   rK   z	Last NamerD   rE   rF   rK   	upload_torE   rF      )rD   unique   rD   )rD   rF   rE   d         rE   rF   
   )rD   rE   choicesdefault)rD   rF   rE   rZ   r[   rF   rE      r[   )r[   rE   rF   editableemployee_work_info__company_idrelated_company_fieldc                     | j                   S )z1
        to get contact no of candidates
        )phoneselfs    r1   get_contactzEmployee.get_contactx   s     zzr3   c                    i }t        |xs g       j                  t        | dg             }| j                  j	                         D ]z  }t        |t        j                  t        j                  f      s.|j                  |vs=t        | |j                  d       }|sWt        |      sct        d      ||j                  <   | |rt        |      y )Nxss_exempt_fieldszPotential XSS content detected.)setuniongetattr_meta
get_fields
isinstancer   	CharField	TextFieldnamer&   r
   )rf   excludeerrorstotal_excludefieldr0   s         r1   clean_fieldszEmployee.clean_fields~   s     GMr*00?RTV1WXZZ**, 		E56#3#3V5E5E"FGJJm3ejj$7WU^)89*F5::&		 !&)) r3   c                 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rf   rz   s     r1   	get_imagezEmployee.get_image   s(       ''++C
r3   returnc                 R    | j                   r| j                   j                  d      S y )Nz%d %b)dobstrftimere   s    r1   get_employee_dobzEmployee.get_employee_dob   s!    8888$$W--r3   c                 h    | j                   r| j                   d| j                    S | j                  S )z7
        Method will return employee full name
         )employee_last_nameemployee_first_namere   s    r1   get_full_namezEmployee.get_full_name   s@     && '')4+B+B*CD	
 ))	
r3   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rl   re   s    r1   get_companyzEmployee.get_company   s     wt%94@,PTUUr3   c                     | j                         r| j                         n-t        j                  j                  d      j	                         }|r|j
                  }|r|S dS y)NT)hqzMMM. D, YYYY)r   r   objectsfilterfirstdate_format)rf   companyr   s      r1   get_date_formatzEmployee.get_date_format   sa     ! ''4'0668 	 !--K"-;A>Ar3   c                 2    t        t        | dd      dd      S )zP
        This method is used to return the job position of the employee
        r   Njob_position_idr   re   s    r1   get_job_positionzEmployee.get_job_position   s#     D.57H$
 	
r3   c                     t        t        dd       }|r]t        |d      rQt        |j                  d      r;t        | d      r.| j                  j
                  |j                  j                  k(  ryyy)NrequestuserrG   r   z]style="color: inherit; text-decoration: none; background-color: hsl(38.08deg 100% 50% / 8%);" )rl   r#   hasattrr   r   reporting_manager_idrG   )rf   r   s     r1   	diff_cellzEmployee.diff_cell   se    .)T:(n5 23++@@<<,,- wr3   c                 2    t        t        | dd      dd      S )zN
        This method is used to return the department of the employee
        r   Ndepartment_idr   re   s    r1   get_departmentzEmployee.get_department   s     wt%94@/SWXXr3   c                 2    t        t        | dd      dd      S )zI
        This method is used to return the shift of the employee
        r   Nshift_idr   re   s    r1   	get_shiftzEmployee.get_shift   s     wt%94@*dSSr3   c                     | j                         }t        j                         j                  d      j	                         }|sy|j
                  j                  |      j                         }|r|S dS )zS
        This method is used to check if the employee has a shift assigned
        z%AN)day__day)r   r   todayr   loweremployeeshiftschedule_setr   r   )rf   shiftdayschedules       r1   get_shift_schedulezEmployee.get_shift_schedule   se      nn''-335229939GMMO#x--r3   c                 V    t        | dd      }t        |dd      }||S | j                  S )z
        This method is used to return the employee's email, checking work email first
        then falling back to personal email.
        r   Nemail)rl   r   )rf   	work_info
work_emails      r1   get_mailzEmployee.get_mail   s5    
 D"6=	Y6
'3zCCr3   c                 "    | j                         S N)r   re   s    r1   	get_emailzEmployee.get_email   s    }}r3   c                 2    t        t        | dd      dd      S )zM
        This method is used to return the work type of the employee
        r   Nwork_type_idr   re   s    r1   get_work_typezEmployee.get_work_type   s     wt%94@.RVWWr3   c                 2    t        t        | dd      dd      S )Q
        This method is used to return the employee type of the employee
        r   Nemployee_type_idr   re   s    r1   get_employee_typezEmployee.get_employee_type  s#     D.57I4
 	
r3   c                 2    t        t        | dd      dd      S )r   r   Nr   r   re   s    r1   get_reporting_managerzEmployee.get_reporting_manager	  s#     D.57Mt
 	
r3   c                     | j                   r?t        j                  | j                   j                        r| j                   j                  S t        d      S )Nzimages/ui/default_avatar.jpg)ry   r   existsrr   rz   r   re   s    r1   
get_avatarzEmployee.get_avatar  sB      _%;%;D<Q<Q<V<V%W((,,,455r3   c                 @   t        j                         }t        j                  d      r| j                  j                  ||      nt               j                         }t        d      }|j                         rV|j                  d      j                         rt        d      }nt|j                  d      rt        d      }nVt        d	      }nJt        j                  d
      r5| j                  j                  |      j                         rt        d      }d| 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 breakzH<span class="oh-recruitment_tag" style="font-size: 0.5rem; color: red;">z</span>)r   r   r   is_installedleaverequest_setr   r   none_r   employee_attendances)rf   r   leaves_requestsr   s       r1   get_leave_statuszEmployee.get_leave_status  s    

   ) !!((e(T" 	
 %&!!#%%Z%8??A: ''{';-.01l+))00 % 1 fh |_FYZ`Yaahiir3   r   r   c                      t        dd| i      S )zC
        View to return the HTML for the send mail button.
        z!cbv/dashboard/offline_action.htmlinstancepathcontextr,   re   s    r1   send_mail_buttonzEmployee.send_mail_button4  s    
 4&
 	
r3   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   r   order_bylenr!   rl   get_at_work_from_activitiesmaxr    )
rf   r   	yesterdaytoday_attendanceyesterday_attendanceattendancesr   minimum_hour_secondsat_workr   s
             r1   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  Ir3   c                 x    | j                         }|j                  d      }|j                  d      }d| d| dS )Nr   r   zT
                <span class="oh-recuritment_tag" style="font-size: .5rem;">At work z[</span>
                <span class="oh-recuritment_tag" style="font-size: .5rem;">Pending z</span>
            )r   get)rf   forecasted_infor   r   s       r1   get_custom_forecasted_info_colz'Employee.get_custom_forecasted_info_colj  s]    557,001EF#2#6#67Q#R TTfSg hTTlSm n 	r3   c                 z    | j                   j                  t        j                               j	                         S )zF
        This method will returns employees todays attendance
        r   )r   r   r   r   r   re   s    r1   get_today_attendancezEmployee.get_today_attendancet  s3     ((//$NN, 0 

%'	r3   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       |r-|j                         r|
j                  t        d      dd       |r-|j                         r|
j                  t        d      dd       |r-|j                         r|
j                  t        d      dd       |r-|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   )rK   
field_namezRecruitment managerr   zRecruitment stage managerrecruitment_stage_managerszOnboarding stage manageronboarding_stage_managerzOnboarding task manageronboarding_task_managerrelated_modelsr   z---Choose employee---T	is_activeidr   r   r   employee_choices)r   r   r$   r   r   pkEmployeeWorkInformationr   appendr   r5   values_list)rf   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                    r1   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#% &--/%%()*=(>&< )-F-M-M-O%%()*?(@&< '+B+I+I+K%%()*E(F&B &*@*G*G*I%%()*D(E&@ %)>)E)E)G%%()*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   2AK! 4K
K! K! !K&c                     | j                   | j                   nd}| j                  d| j                   dnd}| j                   d| d| S Nr   ()r   r   badge_idr   rf   r  r"  s      r1   __str__zEmployee.__str__  s[    '+'>'>'JD##PR 	 .2]]-Faa(B**+1YKq
CCr3   c                     | j                   | j                   nd}| j                  d| j                   dnd}| j                   d| d| S r  r!  r#  s      r1   employee_name_with_badge_idz$Employee.employee_name_with_badge_id  s]     (,'>'>'JD##PR 	 .2]]-Faa(B**+1YKq
CCr3   c                 8    t        dd| j                  i      }|S )/
        This method to get update url
        zemployee-view-updateobj_idkwargsr   r
  r{   s     r1   get_update_urlzEmployee.get_update_url  s     18TWW:MN
r3   c                 8    t        dd| j                  i      }|S )z1
        This method to get archive  url
        zemployee-archiver)  r*  r,  r{   s     r1   get_archive_urlzEmployee.get_archive_url  s     -x6IJ
r3   c                 8    t        dd| j                  i      }|S )4
        This method to get individual  url
        zemployee-view-individualr)  r*  r,  r{   s     r1   get_individual_urlzEmployee.get_individual_url  s     5x>QR
r3   c                 8    t        dd| j                  i      }|S )r1  zprofile-newr
  r*  r,  r{   s     r1   get_profile_urlzEmployee.get_profile_url  s     =$A
r3   c                     t        d      }|S )z0
        This method to get delete  url
        generic-deleter   r{   s     r1   get_delete_urlzEmployee.get_delete_url       +,
r3   c                      t        dd| i      S )@
        This method for get custom column for actions.
        z(cbv/employees_view/employee_actions.htmlr   r   r,   re   s    r1   employee_actionszEmployee.employee_actions  s    
 ;&
 	
r3   c                     | j                   ryy)z 
        archive status
        Archivez
Un-Archiver  re   s    r1   archive_statuszEmployee.archive_status  s     >>r3   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   r   Nworking_employeesr   r   T)attendance_date__gteattendance_date__lte!attendance_clock_out_date__isnullr   )flatF)r   r   r$   rl   r"   r#   r   rA  r   nowr   r   r   r   r  setattrr
  )rf   
Attendancer   r   r   rA  s         r1   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r3   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	conditionrr   N)__name__
__module____qualname____doc__unique_togetherpermissionsorderingr   UniqueConstraintQconstraintsr/   r3   r1   MetarK  ?  sQ    	 Q

 "
 $F##"|"&((E:&
r3   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   )r   r   r   yearmonthr   r   )rf   birthdayr   next_birthdays       r1   days_until_birthdayzEmployee.days_until_birthdayT  si     88

UZZF5  aNM%+++r3   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.modelsrd  r   r   r   r   r   )rf   rd  s     r1   get_last_sent_mailzEmployee.get_last_sent_mail_  s<     	) ##$--/#BXm$UW	
r3   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)r5   r   r   )rf   subordinatess     r1   get_subordinate_employeesz"Employee.get_subordinate_employeesk  s*      ''..59 / 
 r3   c                 r   t        |   |i | t        t        j                  dd       }|r4| j
                  s(| j                         durd| _        t        |   |i | | }|j                  
| j                  }t        | 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	      s0t(        j                  j+                  | 
       | j                         S | S )Nr   FT)usernamer   passwordis_new_employee)rm  r   rn  rL  )codenamerM  r   r   )supersaverl   r"   r#   r  r  employee_user_idr   strrd   ro  r	   r   create_userr   r   user_permissionsaddr   r  get_or_create)rf   argsr+  r   employeerm  rn  is_new_employee_flagr   rL  rM  	__class__s              r1   rr  zEmployee.savev  s   
 	d%f%-<<iN4>>d.H.H.JRW.W!DNGL$)&)$$,zzH4::H ,, --=== !
 <<++!! 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;r3   r   )\rR  rS  rT  rU  transchoice_genderchoice_maritalr   rp   r"  OneToOneFieldr	   CASCADEr   rs  r   r   
ImageFieldr'   ry   
EmailFieldr   rd   rq   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   r   rg   rw   r|   anyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   django.httpr   r   r   r   r   r  rt  r$  r&  r-  r/  r2  r4  r8  r<  r?  rI  r\  rb  rg  rk  rr  __classcell__r|  s   @r1   r5   r5   7   s   
 
v	5?#	%.!M 
5?#	E)$%	U:&'N
  v2DEH+v++..#vY +&**U< *))TAkN )v((;TQUVFT:EFE f#TEGf#TEGF$dCE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	.DX

6
j8 )
*Xc'JD DD
 2
 
*	,

	+ +r3   r5   c                       e Zd ZdZ ej
                  dd ed            Z ej
                  dd      Zde	fd	Z
d
 Zd Zd Zd Zy)EmployeeTagz
    EmployeeTag Model
    rB   TTitlerM   rV   rD   rE   r}   c                     | j                    S r   titlere   s    r1   r$  zEmployeeTag.__str__      **r3   c                 8    dj                  | j                        S )z5
        to return color into correct format
        zq<span style="height: 25px; width: 25px; background-color: {}; border-radius: 50%; display: inline-block;"></span>)formatcolorre   s    r1   
color_spanzEmployeeTag.color_span  s    
X
&
	r3   c                 8    t        dd| j                  i      }|S )r(  zemployee-tag-update-formr
  r*  r,  r{   s     r1   r-  zEmployeeTag.get_update_url  s     5tTWWoN
r3   c                 8    t        dd| j                  i      }|S )/
        This method to get delete url
        zemployee-tag-deleter)  r*  r,  r{   s     r1   r8  zEmployeeTag.get_delete_url  s     0(DGG9LM
r3   c                     | j                   S r   r  re   s    r1   get_instance_idzEmployeeTag.get_instance_id  s    wwr3   N)rR  rS  rT  rU  r   rp   r   r  r  rt  r$  r  r-  r8  r  r/   r3   r1   r  r    sW     FAgJOEF6E r3   r  c            
       H    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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j4                  ed ed            Z ej:                  ddd ed            Z ej                  eej                  dd ed            Z  ejB                  ddd ed            Z" ej:                  ddd ed            Z# ejH                  dd ed            Z% ejH                  dd e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+ Z8d, Z9d- Z:d. Z; xZ<S )/r  z'
    EmployeeWorkInformation model
    Tr   r5   rH   r   )rI   rE   rF   rK   zJob PositionzJob Rolereporting_managerzReporting ManagerShiftz	Work TypezEmployee TypezEmployee tagrF   rK   rB   zWork LocationrN   r   )rI   rF   rE   rK   rQ   z
Work Email)rD   rF   rE   rK   z
Work PhonezJoining Date)rE   rF   rK   zContract End Date)rF   rE   rK   r   zBasic Salary)rE   rF   r[   rK   zSalary Per HourrX   )rE   rF   r[   history_setrJ   basesr}   c                 8    | j                    d| j                   S )N - )r   r   re   s    r1   r$  zEmployeeWorkInformation.__str__4  s!    ""#3t';';&<==r3   c                 D    | j                          t        |   |i | y r   )
full_cleanrq  rr  rf   ry  r+  r|  s      r1   rr  zEmployeeWorkInformation.save7  s    d%f%r3   c                 2    t        |   |i | d| _        y )NF)rq  __init__skip_historyr  s      r1   r  z EmployeeWorkInformation.__init__;  s    $)&)!r3   c                      g d}t         fd|D              }t        |      }|dkD  r||z  dz  nd}t        |d      S )N)r   r   r   r   job_role_idr   r   locationr   mobiler   date_joiningcontract_end_datebasic_salarysalary_hourc              3   <   K   | ]  }t        |      d  y w)Nr   r   ).0r  rf   s     r1   	<genexpr>z=EmployeeWorkInformation.calculate_progress.<locals>.<genexpr>R  s"      $
743L3XA$
s   r   rU   r   )sumr   round)rf   fields_to_focuscompleted_field_counttotal_fieldspercents   `    r1   calculate_progressz*EmployeeWorkInformation.calculate_progress?  s\    
$ !$ $
 /$
 !
 ?+<H1<L"\1S8RS 	 Wa  r3   c                      t        dd| i      S )zC
        This method for get custome coloumn for progress.
        zcbv/dashboard/progress.htmlr   r   r,   re   s    r1   progress_colz$EmployeeWorkInformation.progress_col[  s    
 .&
 	
r3   c                 8    t        dd| j                  i      }|S )z!
        To get edit url
        zupdate-emp-workinfor
  r*  r   r
  r{   s     r1   get_edit_urlz$EmployeeWorkInformation.get_edit_urle  s    
 +T477OD
r3   c                     t        |       S zS
        This method is used to return the tracked history of the instance
        r(   re   s    r1   trackingz EmployeeWorkInformation.trackingm       ~r3   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@)r  r   rF  r   r   r  rr  )rf   joining_datecurrent_datedelta
total_daysr  s         r1   experience_calculatorz-EmployeeWorkInformation.experience_calculators  sd     ((||~**, |+ ZZ
  %'
$		r3   )=rR  rS  rT  rU  r   r  r5   r  r   r   
ForeignKeyr   PROTECTr   r   r   r   r  r   r   
DO_NOTHINGr   r   r   r   r   ManyToManyFieldr  tagsrp   r  r   r   r  r   r  r  r  r  r  r  r  r  r  
FloatFieldr  r+   r*   historyr   r   rt  r$  rr  r  r  r  r  r  r  r  r  s   @r1   r  r    s    '&&&..)z]K &F%%..|_M (f''..~&O $&##..z]K -6,,..(*+ !v  ##wZH %6$$..{^L )v((..' "6!!4a.?D  vD1_;MH #""..y\J FdAlOE VdAlOF $6##An,=L )((A.A,B '6&&qq7HL &&%%qq9J7KK 'f&&D=O"""D!DJ"
G $%G> >&"!8
r3   r  c            	       4   e Zd ZdZ ej
                  eej                  dd ed            Z	 ej                  dd      Z ej                  ddd	      Z ej                  d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j                  ddd      Z ej                  dddd      Z ej*                  dd      Z ed      Z G d d      ZdefdZd Zy)EmployeeBankDetailsz#
    EmployeeBankDetails model
    Temployee_bank_detailsr5   )rI   rE   rJ   rK   rB   r  FrC      zBank Code #1)rD   rK   rE   zBank Code #2rN   rX   +employee_id__employee_work_info__company_idra   c                   ,    e Zd Z ed      Z ed      Zy)EmployeeBankDetails.MetazEmployee Bank DetailsNrR  rS  rT  r   rK   verbose_name_pluralr/   r3   r1   r\  r    s    01 78r3   r\  r}   c                 8    | j                    d| j                   S )N-)r   	bank_namere   s    r1   r$  zEmployeeBankDetails.__str__  s    ""#1T^^$455r3   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  r   rs   r   r   r
   r   )rf   bank_detailss     r1   cleanzEmployeeBankDetails.clean  su    *.66>> ,, ? fD$7$7f8  %(!a+  	 +r3   N)rR  rS  rT  rU  r   r  r5   r  r   r   rp   r  r  branchrq   r  r  r  r  any_other_code1any_other_code2r  r  r   r   r\  rt  r$  r  r/   r3   r1   r  r    sC    '&&&..,z]K !  BT:I%V%%N
 V$7Ff#D9Gf"4tDGFTBE6rDAD&f&&NO 'f&&D>O 'f&&D=O#KG9 96 6r3   r  c                   ^    e Zd Z ej                  edd      Z ej                         Zd Z	y)	NoteFilesT)rP   rF   rE   c                 R    | j                   j                  j                  d      d   S )N/)filesrr   splitre   s    r1   r$  zNoteFiles.__str__  s     zz$$S)"--r3   N)
rR  rS  rT  r   	FileFieldr'   r  Managerr   r$  r/   r3   r1   r  r    s+    F{$TJEfnnG.r3   r  c                      e Zd ZdZ ej
                  eej                  d      Z ej                   e
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)rI   rJ   DescriptionT)rK   rE   rF   rI   r  ra   r}   c                     | j                    S r   )descriptionre   s    r1   r$  zEmployeeNote.__str__  s    ""#$r3   N)rR  rS  rT  rU  r   r  r5   r  r   rq   r   r  r  r  
note_files
updated_byr   r   rt  r$  r/   r3   r1   r  r    s     $&##..$K
 #&""-0@tLK'''	>J"""8v~~FJ#KG% %r3   r  c                   6    e Zd ZdZ ej
                  e      Zy)PolicyMultipleFilez$
    PoliciesMultipleFile model
    )rP   N)rR  rS  rT  rU  r   r  r'   
attachmentr/   r3   r1   r  r    s     "!!K8Jr3   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 G d d      Z fdZ xZS )Policyz
    Policies model
    rB   rT   Tr^   F)rF   r_   r  r   r  r   c                   ,    e Zd Z ed      Z ed      Zy)Policy.Metar  PoliciesNr  r/   r3   r1   r\  r    s    {
mr3   r\  c                 t    t        |   |i | | j                  j                         j                          y r   )rq  deleteattachmentsallr  s      r1   r  zPolicy.delete  s/    ''%%'r3   )rR  rS  rT  rU  r   rp   r  rq   bodyr  is_visible_to_allr  r5   specific_employeesr  r  r   r   r   r   r   r\  r  r  r  s   @r1   r  r    s     F+E6D+++D9///uU(&(();4HK'''t!I,WJ#L1G, ,( (r3   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)rI   rF   rE   rJ   r   z&Use negative numbers to reduce points.)r[   	help_textrU   )rD   rZ   rF   rE   r\   r  )rF   rE   rD   r  r  r  ra   c                 :    | j                    d| j                   dS )Nr  z Points)r   pointsre   s    r1   r$  zBonusPoint.__str__"  s     ""#3t{{m7;;r3   c                     t        |       S r  r(   re   s    r1   r  zBonusPoint.tracking%  r  r3   )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  r   r   r  r   create)r$  r   _kwargss      r1   bonus_post_savezBonusPoint.bonus_post_save+  sE     !!(((ELLN%%(%; Or3   N)rR  rS  rT  rU  r   
CONDITIONSr   r  r5   r  r   r  r"  rp   encashment_conditionredeeming_pointsrq   reasonr+   r*   r  r   r   r$  r  r   r   r)  r/   r3   r1   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)< *<r3   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 G d d      ZdefdZd Zd Zd Zd Zd Zy)
Actiontypez
    Action type model
    warningWarning
suspension
Suspension	dismissal	DismissalrB   rT   rV   )rD   rZ   FzEnable login block :z[If is enabled, employees log in will be blocked based on period of suspension or dismissal.)r[   rK   r   c                   ,    e Zd Z ed      Z ed      Zy)Actiontype.MetazAction TypezAction TypesNr  r/   r3   r1   r\  r7  M  s    '/r3   r\  r}   c                     | j                    S r   r  re   s    r1   r$  zActiontype.__str__Q  r  r3   c                     | j                   ryy)z%
        To get block option
        YesNo)block_optionre   s    r1   get_block_optionzActiontype.get_block_optionT  s     r3   c                 ^    t        | j                        j                  | j                        S )z%
        Display action type
        )dictchoice_actionsr   action_typere   s    r1   get_action_type_displayz"Actiontype.get_action_type_display\  s&     D''(,,T-=-=>>r3   c                 8    t        dd| j                  i      }|S )r(  zupdate-action-typer
  r*  r,  r{   s     r1   r-  zActiontype.get_update_urlb  s     /twwH
r3   c                     t        d      }|S )r  r6  r7  r{   s     r1   r8  zActiontype.get_delete_urli  r9  r3   c                     | j                   S )z.
        To get instance in list view
        r  re   s    r1   r  zActiontype.get_instance_idp  s     wwr3   N)rR  rS  rT  rU  r}  r@  r   rp   r  rA  r  r   r<  r\  rt  r$  r=  rB  r-  r8  r  r/   r3   r1   r/  r/  :  s    
 
E)$%	u\*+	eK()N F+E"&""b.IK&6&&-.oL0 0 ?r3   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                  edd      Z ed      ZdefdZ G d d      Zd Z d Z!d Z"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)y$)%DisciplinaryActionz
    Disciplinary model
    r   DayshoursHours	Employees)rK   r  r  rT   rY   )rD   rZ   r[   Tr   )rE   r[      z00:00)rD   r[   rE   
validators)rE   rO   r  r}   c                     | j                    S r   actionre   s    r1   r$  zDisciplinaryAction.__str__  s    ++r3   c                       e Zd ZdgZy)DisciplinaryAction.Metaz-idN)rR  rS  rT  rX  r/   r3   r1   r\  rR    s	    7r3   r\  c                      t        dd| i      S )A
        This method for get custom column for employee.
        z*cbv/disciplinary_actions/employee_col.htmlr   r   r,   re   s    r1   employee_columnz"DisciplinaryAction.employee_column      
 =&
 	
r3   c                      t        dd| i      S )rT  z*cbv/disciplinary_actions/action_taken.htmlr   r   r,   re   s    r1   action_taken_colz#DisciplinaryAction.action_taken_col  rV  r3   c                 2    | j                   j                  ryy)z%
        block option column
        r:  r;  )rP  r<  re   s    r1   block_option_colz#DisciplinaryAction.block_option_col  s     ;;##r3   c                      t        dd| i      S )zD
        This method for get custom column for action date.
        z)cbv/disciplinary_actions/action_date.htmlr   r   r,   re   s    r1   action_date_colz"DisciplinaryAction.action_date_col      
 <&
 	
r3   c                 &    d| j                    d}|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=randomrO  r{   s     r1   r   zDisciplinaryAction.get_avatar  s     2$++>PQ
r3   c                      t        dd| i      S )zD
        This method for get custom column for attachments.
        z)cbv/disciplinary_actions/attachments.htmlr   r   r,   re   s    r1   attachments_colz"DisciplinaryAction.attachments_col  r]  r3   c                      t        dd| i      S )r;  z%cbv/disciplinary_actions/actions.htmlr   r   r,   re   s    r1   actionszDisciplinaryAction.actions  s    
 8&
 	
r3   c                      t        dd| i      S )r;  z+cbv/disciplinary_actions/detail_action.htmlr   r   r,   re   s    r1   detail_actionsz!DisciplinaryAction.detail_actions  s    
 >&
 	
r3   c                     | j                   j                         }dj                  |D cg c]  }t        |       c}      }|S c c}w )z,
        interviewer in detail view
        z<br>)r   r  joinrt  )rf   	employeesrz  employee_names_strings       r1   employee_detailz"DisciplinaryAction.employee_detail  sB     $$((*	 &9,UxS],U V$$ -Vs   Ac                 8    t        dd| j                  i      }|S )z
        detail view
        z disciplinary-actions-detail-viewr
  r*  r  r{   s     r1   dis_action_detail_viewz)DisciplinaryAction.dis_action_detail_view  s     8$Q
r3   N)*rR  rS  rT  rU  r   rZ   r   r  r5   r   r  r/  r  rP  rq   r  rp   unit_inr  r   r   rI  r  
start_dater  r'   r  r   r   rt  r$  r\  rU  rX  rZ  r\  r   r`  rb  rd  ri  rk  r/   r3   r1   rG  rG  w  s/    &	"Waj$9:G(&((+OKVzV^^DF"&""c2Kf"gvNG6D!4DF()	E "!!t,J!!!Kd$OJ#$QRG    





%r3   rG  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)rD   r[   T)rE   rI   r   N)rR  rS  rT  rU  r   rp   badge_id_prefixr  r   r  r   r   r   r/   r3   r1   ro  ro    sA     'f&&!UCO"""7PJ#L1Gr3   ro  c                   X    e Zd ZdZ ej
                  d      Z ej                         Zy)ProfileEditFeaturez
    ProfileEditFeature
    Fr^   N)	rR  rS  rT  rU  r   r  
is_enabledr   r   r/   r3   r1   rt  rt    s)     %$$U3JfnnGr3   rt  )ACCESSBILITY_FEATURE)gender_chartzCan view Gender Chart)department_chartzCan view Department Chart)employees_chartzCan view Employees Chart)birthday_viewzCan view BirthdaysN)TrU  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   r  r   django.templatetags.staticr   django.urlsr   r   django.utils.translationr   r   r   r}  base.horilla_company_managerr   rf  r   r   r   r   r   r   r   r   !employee.methods.duration_methodsr    r!   horillar"   horilla.horilla_middlewaresr#   horilla.methodsr$   horilla.modelsr%   r&   r'   horilla_audit.methodsr)   horilla_audit.modelsr*   r+   horilla_views.cbv_methodsr-   r2   Modelr5   r  r  r  r  r  r  r  r  r/  rG  ro  rt  accessibility.accessibilityrv  r  r/   r3   r1   <module>r     so   / .    7 2 5  + . $ $ - - 1 : >	 	 	 K ' 6 3 = = * B 5
j	v|| j	Z#, #L|fll |~5, 5p. .%< %*9 9(\ (.:< :<z: :zt tn2\ 2  =    E F    M N    K L    C Dr3   