
    vg(                         d Z ddlZddl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 ddlmZmZmZ dd	lmZ dd
lmZ ddlmZ  G d de      Z G d d      Z G d de      Z G d de      Z G d de      Zy)zG
filters.py

This page is used to register filter for employee models

    N)forms)gettext)
CharFilter)DefaultAccessibility)DisciplinaryActionEmployeePolicy)	FilterSetHorillaFilterSetfilter_by_name)_thread_locals)Document)getattributec                       e Zd ZdZ ej
                  d      Z ej
                  d      Z ej                  dd e	d      fd e	d	      fd
 e	d      fd e	d      fgd e
j                  ddddd            Z ej
                  d      Z ej
                  d      Z ej
                  d      Z ej
                  dd      Z ej                  ddddg      Z ej                  dd ddg      Z ej                  d!d"ddg      Z ej(                  d#d$ e
j*                  d%d&i      '      Z ej(                  d#d( e
j*                  d%d&i      '      Z ej(                  d) e
j*                  d%d&i      *      Z ej(                  d+ e
j*                  d%d&i      *      Z G d, d-      Zd. Zd/ Z fd0Zd1 Z xZS )2EmployeeFilterz}
    Filter set class for Candidate model

    Args:
        FilterSet (class): custom filter set class to apply styling
    r   method	search_inzSearch FieldemployeezSearch in : Employeereporting_managerzSearch in : Reporting manager
departmentzSearch in : Departmentjob_positionzSearch in : Job Positionfilter_by_name_and_field   zoh-input__iconz`border: none; overflow: hidden; display: flex; position: absolute; z-index: 999; margin-left:8%;z$('.filterButton')[0].click();)sizeclassstyleonclickattrs)labelchoicesr   widget	icontains)lookup_expr-employee_work_info__department_id__department
field_namer%   	is_activez	Is Active)TYes)FNo)r(   r!   r"   is_from_onboardingzIs From Onboardingis_directly_convertedzIs Directly Convertedcandidate_get__probation_endgtetypedate)r(   r%   r#   ltenot_in_yet_func)r   r#   not_out_yet_funcc                       e Zd ZdZeZg dZy)EmployeeFilter.Metaz7
        Meta class to add the additional info
        )employee_first_nameemployee_last_nameemailbadge_idphonecountrygenderr)   #employee_work_info__job_position_id!employee_work_info__department_idr    employee_work_info__work_type_id$employee_work_info__employee_type_idemployee_work_info__job_role_id(employee_work_info__reporting_manager_idemployee_work_info__company_idemployee_work_info__shift_idemployee_work_info__tagsemployee_user_id__groups"employee_user_id__user_permissionsN)__name__
__module____qualname____doc__r   modelfields     $/var/www/horilla/employee/filters.pyMetar6   h   s    	 
rP   rR   c                 v    |j                  |      }|j                  |d      }||z  j                         }|S )I
        The method to filter out the not check-in yet employees
        )%employee_attendances__attendance_dateFrU   2employee_attendances__attendance_clock_out__isnull)excludefilterdistinct)selfqueryset_value	queryset1	queryset2s         rQ   r3   zEmployeeFilter.not_in_yet_func   sQ     $$27 % 
	 OO27?D $ 
	
 	)335rP   c                 ,    |j                  |d      }|S )rT   TrV   )rY   )r[   r\   r]   r^   s       rQ   r4   zEmployeeFilter.not_out_yet_func   s$     ??27?C # 
 rP   c           	         ddl m} t        j                  j	                  d      j                         }|rb|j                  rVt        t        dd      }t        |j                  dd      }|r,|j                  j                         r|j	                  |      }| j                  j                  }i }|j                         D ]Q  \  }}	t        |	t         t"        j$                  j&                  j(                  j*                  f      sE|	sHd	|	v sM|	||<   S |rZ |       }
|j                         D ]/  \  }}|D ]%  }	|	d	k(  r|
 |di | d
diz  }
|
 |di ||	iz  }
' 1 |j	                  |
      S t,        | ]  |      S )zz
        Override the default filtering behavior to handle None option and filter queryset for reporting manager.
        r   )Qemployee_view)featurerequestNemployee_get)rC   not_set__isnullTrO   )django.db.modelsrc   r   objectsrY   firstexclude_allgetattrr   userr   existsformcleaned_dataitems
isinstancelistdjangodbmodelsqueryQuerySetsuperfilter_queryset)r[   r\   rc   accessibilityrf   r   datanot_set_dictkeyr^   	q_objectsvalues	__class__s               rQ   r|   zEmployeeFilter.filter_queryset   s    	' -44;;# < 

%' 	 ]66ni>Gw||^TBHH66==?#??=E + 
 yy%%**, 	.JC%$		(8(8(>(>(G(G!HIY%/(-L%	.
 I+113 7V# 7E	)!Q%BSE*:D)A%BB	!Q%6#u%66		77 ??9--w&x00rP   c           	          j                         | j                  j                  d      r|S fd}t        t	        dt        ||                  }|j	                  |      S )z(
        Employee search method
        search_fieldc                 n    t        t        | d            j                         }|v r| j                  S d S )Nget_full_name)strr   lowerpk)instanceresultr^   s     rQ   
_icontainsz1EmployeeFilter.filter_by_name.<locals>._icontains   s2    h@AGGIF"'6/8;;;t;rP   N)id__in)r   r~   getru   rY   map)r[   r\   namer^   r   idss      `  rQ   r   zEmployeeFilter.filter_by_name   sU     99==(O	< 6$J 9:;c**rP   ) rI   rJ   rK   rL   django_filtersr   searchr   ChoiceFilterr]   r   Selectselected_search_fieldr7   r8   r<   r   r)   r,   r-   
DateFilter	DateInputprobation_fromprobation_till
not_in_yetnot_out_yetrR   r3   r4   r|   r   __classcell__)r   s   @rQ   r   r      s6    '^&&.>?F,>,,K@L7N77123 !$C"DE1567Q9:;	
 *u||){;	
$ 4.33L222{K'n''K@G***BJ
 ,++
I 544'"
 8N77*%
 /^..1uff%56N
 /^..1uff%56N +** uff%56J ,.++!uff%56K

 
:(#1J+rP   r   c                       e Zd ZdZg dZy)EmployeeReGroupz:
    Class to keep the field name for group by option
    )) select)r>   zJob Position)r?   
Department)rE   Shift)r@   z	Work Type)rB   zJob Role)rC   zReporting Manager)rD   CompanyN)rI   rJ   rK   rL   rN   rO   rP   rQ   r   r      s    	FrP   r   c                   L    e Zd ZdZ ej
                  dd      Z G d d      Zy)PolicyFilterz&
    PolicyFilter filterset class
    titler$   r'   c                       e Zd ZeZdZy)PolicyFilter.Meta__all__N)rI   rJ   rK   r	   rM   rN   rO   rP   rQ   rR   r      s    rP   rR   N)rI   rJ   rK   rL   r   r   r   rR   rO   rP   rQ   r   r      s'     '^&&'{SF rP   r   c                   8    e Zd ZdZ edd      Z G d d      Zy)DocumentRequestFilterz.
    Custom filter for Document Requests.
    r   r$   r'   c                       e Zd ZdZeZg dZy)DocumentRequestFilter.MetazT
        A nested class that specifies the model and fields for the filter.
        )employee_iddocument_request_idstatus employee_id__employee_first_nameemployee_id__employee_last_nameemployee_id__is_activeemployee_id__gender0employee_id__employee_work_info__job_position_id.employee_id__employee_work_info__department_id-employee_id__employee_work_info__work_type_id1employee_id__employee_work_info__employee_type_id,employee_id__employee_work_info__job_role_id5employee_id__employee_work_info__reporting_manager_id+employee_id__employee_work_info__company_id)employee_id__employee_work_info__shift_idN)rI   rJ   rK   rL   r   rM   rN   rO   rP   rQ   rR   r      s    	 
rP   rR   N)rI   rJ   rK   rL   r   r   rR   rO   rP   rQ   r   r      s     7DF
 
rP   r   c                       e Zd ZdZ ee      Z ej                   e	j                  ddi            Z G d d      Zy	)
DisciplinaryActionFilterz1
    Custom filter for Disciplinary Action.

    r   r0   r1   r   )r#   c                       e Zd ZeZdgZg dZy)DisciplinaryActionFilter.Metaz-id)	r   actionr   r   r   r   r   r   r   N)rI   rJ   rK   r   rM   orderingrN   rO   rP   rQ   rR   r   %  s    "7

rP   rR   N)rI   rJ   rK   rL   r   r   r   r   r   r   r   
start_daterR   rO   rP   rQ   r   r     sB    
 ~.F***uff%56J
 
rP   r   )rL   rv   r   r   django.utils.translationr   r]   r   accessibility.modelsr   employee.modelsr   r   r	   horilla.filtersr
   r   r   horilla.horilla_middlewaresr   horilla_documents.modelsr   3horilla_views.templatetags.generic_template_filtersr   r   r   r   r   r   rO   rP   rQ   <module>r      st       1 % 6 @ @ G G 6 - LB+% B+J "	9 	
I 
@
y 
rP   