
    vgA                        d Z ddl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mZmZmZmZmZmZ  G d d	ej(                        Z G d
 dej                        Z G d de      Z G d de      Z G d de      Z G d dej                        Z G d de      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  G d  d!e      Z!y)"z
Module: filters.py

This module contains custom Django filters and filter sets for
the PMS (Performance Management System) app.
    N)forms)
DateFilter)	FilterSet)reload_queryset)	AnonymousFeedbackBonusPointSettingEmployeeBonusPointEmployeeKeyResultEmployeeObjectiveFeedback	KeyResultMeetings	Objectivec                       e Zd ZdZd Zy)DateRangeFilterz
    A custom Django filter for filtering querysets based on date ranges.

    This filter allows you to filter a queryset based on date ranges such as 'today',
    'yesterday', 'week', or 'month' in the 'created_at' field of model.
    c                 Z   |r|dk(  rOt         j                   j                         j                         }|j                  d      }|j	                  |      }|dk(  rZt         j                  j                         }|t        j                  d      z
  }|j                  d      }|j	                  |      }|dk(  rtt         j                  j                         }|t        j                  |j                               z
  }|t        j                  d      z   }|j	                  ||g	      }|S |d
k(  rvt         j                  j                         }t        j                  |j                  |j                  d      }|t        j                  d      z   }	|j	                  ||	g	      }|S )Ntodayz%Y-%m-%d)created_at__startswith	yesterday   )daysweek   )created_at__rangemonth   )
datetimenowdatestrftimefilterr   	timedeltaweekdayyearr   )
selfqsvaluer   formatted_dater   start_of_weekend_of_weekstart_of_monthend_of_months
             /var/www/horilla/pms/filters.pyr!   zDateRangeFilter.filter&   sa    ))--/446!&
!;YYnYE# ++-!H$6$6A$>>	!*!3!3J!?YYnYE ++- %(:(:(P P+h.@.@a.HHYY-1MYN 	 '! ++-!)uzz5;;!J-0B0B0KKYY.,1OYP	    N)__name__
__module____qualname____doc__r!    r.   r-   r   r      s    r.   r   c                        e Zd Z fdZ xZS )CustomFilterSetc                 B   t        |   |i | t        | j                  j                         | j                  j                  j                         D ]  \  }}| j                  |   }|j                  j                  }t        |t        j                  t        j                  t        j                  f      r)|j                  j                  j                  ddi       nt        |t        j                   f      r(|j                  j                  j                  ddi       nt        |t        j"                        r(|j                  j                  j                  ddi       nt        |t        j$                  t        j&                  f      r(|j                  j                  j                  ddi       nAt        |t        j(                        r'|j                  j                  j                  ddi       t        |t*        j,                        sd|_         y )Nclasszoh-input w-100z/oh-select oh-select-2 select2-hidden-accessiblezoh-switch__checkbox	icontains)super__init__r   formfieldsitemsfiltersfieldwidget
isinstancer   NumberInput
EmailInput	TextInputattrsupdateSelectTextareaCheckboxInputCheckboxSelectMultipleModelChoiceFielddjango_filters
CharFilterlookup_expr)r%   argskwargs
field_namer?   filter_widgetr@   	__class__s          r-   r:   zCustomFilterSet.__init__C   s   $)&)		(()!%!1!1!7!7!9 	0J LL4M"((//F**E,<,<eooN ""))74D*EFFU\\O4""))!R
 FU^^5""))74D*EF''00 ""))74I*JKFU%;%;=""))!R
 %!:!:;$/!=	0r.   )r/   r0   r1   r:   __classcell__rS   s   @r-   r5   r5   B   s    !0 !0r.   r5   c                   V    e Zd ZdZ ej
                  d      Z G d d      ZdefdZ	y)	ActualObjectiveFilterz
    ActualObjectiveFilter
    search_methodmethodc                       e Zd ZeZg dZy)ActualObjectiveFilter.Meta)managersarchive	assigneesduration!employee_objective__key_result_idN)r/   r0   r1   r   modelr<   r3   r.   r-   Metar\   n   s    
r.   rc   r'   c                 \   |j                  d      }|j                  j                  j                         }|D ]c  }||j	                  |      |j	                  |      z  |j	                  |      z  |j	                  |      z  |j	                  |      z  z  }e |j                         S )G
        This method is used to search employees and objective
         )(managers__employee_first_name__icontains)'managers__employee_last_name__icontains))assignees__employee_first_name__icontains)(assignees__employee_last_name__icontainstitle__icontainssplitrb   objectsnoner!   distinctr%   queryset_r'   valuesemptyrn   s          r-   rX   z#ActualObjectiveFilter.search_methodx   s     S!&&++- 	EO//%/PQ//E/RS //5/QR //5/9	:E	 ~~r.   N
r/   r0   r1   r2   rL   rM   searchrc   strrX   r3   r.   r-   rW   rW   g   s1     '^&&o>F
 
   r.   rW   c                      e Zd ZdZ ej
                  d      Z ej
                  d      Z ej
                  d      Z ej
                  d      Z	 ej
                  d      Z
 ed	      Z e ej                  d
dd            Z e ej                  d
dd            Z e ej                  d
dd            Z e ej                  d
dd            Z G d d      ZdefdZy)ObjectiveFilterz
    Custom filter set for EmployeeObjective records.

    This filter set allows to filter EmployeeObjective records based on various criteria.
    idrQ   key_result_idprogress_percentageobjective_id__managersrX   rY   
created_atr   oh-input  w-100typer7   rE   r@   c                       e Zd ZdZeZg dZy)ObjectiveFilter.MetaT
        A nested class that specifies the model and fields for the filter.
        )		objectivestatusemployee_idr   
start_date
updated_atend_dater^   objective_idN)r/   r0   r1   r2   r   rb   r<   r3   r.   r-   rc   r      s    	 "

r.   rc   r'   c                     |j                  d      }|j                  j                  j                         }|D ]=  }||j	                  |      |j	                  |      z  |j	                  |      z  z  }? |S )zI
        This method is used to search in managers and objective
        rf   )objective_id__title__icontains)6objective_id__managers__employee_first_name__icontains)5objective_id__managers__employee_last_name__icontains)rn   rb   ro   rp   r!   rr   s          r-   rX   zObjectiveFilter.search_method   s     S!&&++- 		EuE//KP "  //JO " 	E		 r.   N)r/   r0   r1   r2   rL   rM   employee_objectivera   'employee_objective__progress_percentager]   rx   r   created_at_date_ranger   r   	DateInputr   r   r   r   rc   ry   rX   r3   r.   r-   r{   r{      s    322dC(A(A(A")% /Hn.G.G(/+ )~((4LMH&^&&o>F+|Duf?P%QRJ uf?P%QRJ uf?P%QRJ uf?P%QRH

 
$ r.   r{   c                        e Zd ZdZ ej
                  d      Z ed      Z e	 e
j                  ddd	      
      Z e	 e
j                  ddd	      
      Z G d d      Zdddd fdZ xZS )FeedbackFilterz
    Custom filter set for Feedback records.

    This filter set allows to filter Feedback records based on various criteria.
    r8   )rN   r   r}   r   r   r   r   r   c                       e Zd ZdZeZdZy)FeedbackFilter.Metar   __all__N)r/   r0   r1   r2   r   rb   r<   r3   r.   r-   rc   r      s    	 r.   rc   N)requestprefixc                4    t         t        |   ||||       y )N)datars   r   r   )r9   r   r:   )r%   r   rs   r   r   rS   s        r-   r:   zFeedbackFilter.__init__   s     nd,'& 	- 	
r.   )NN)r/   r0   r1   r2   rL   rM   review_cycler   r   r   r   r   r   r   rc   r:   rT   rU   s   @r-   r   r      s     ->,,EL+|Duf?P%QRJ uf?P%QRH
 
D 
 
r.   r   c                       e Zd ZdZ ed      Z ej                  dd ej                  ddi            Z
 ej                  dd	 ej                  ddi            Z G d
 d      Zy)AnonymousFeedbackFilterz
    Custom filter set for AnonymousFeedback records.

    This filter set allows to filter AnonymousFeedback records based on various criteria.
    r   r}   gter   r   r   rQ   rN   r@   ltec                       e Zd ZdZeZdZy)AnonymousFeedbackFilter.Metar   r   N)r/   r0   r1   r2   r   rb   r<   r3   r.   r-   rc   r     s    	 "r.   rc   N)r/   r0   r1   r2   r   r   rL   r   r   r   r   r   rc   r3   r.   r-   r   r      sv     ,|D***uff%56J
 )~((uff%56H r.   r   c                        e Zd Z G d d      Zy)KeyResultFilterc                       e Zd ZeZdZy)KeyResultFilter.Metar   N)r/   r0   r1   r
   rb   r<   r3   r.   r-   rc   r         !r.   rc   N)r/   r0   r1   rc   r3   r.   r-   r   r     s     r.   r   c                   V    e Zd ZdZ ej
                  d      Z G d d      ZdefdZ	y)	ActualKeyResultFilterz(
    Filter through KeyResult model
    rX   rY   c                       e Zd ZeZg dZy)ActualKeyResultFilter.Meta)progress_typetarget_valuer`   
company_idN)r/   r0   r1   r   rb   r<   r3   r.   r-   rc   r     s    Lr.   rc   r'   c                     |j                  d      }|j                  j                  j                         }|D ]  }||j	                  |      z  } |j                         S )re   rf   rk   rm   rr   s          r-   rX   z#ActualKeyResultFilter.search_method  s_     S!&&++- 	FEX__e_DEE	F ~~r.   Nrw   r3   r.   r-   r   r     s3     '^&&o>FM M	  	 r.   r   c                       e Zd ZdZg dZy)ObjectiveReGroupz:
    Class to keep the field name for group by option
    )) select)r   Owner)r   StatusN)r/   r0   r1   r2   r<   r3   r.   r-   r   r   +  s    Fr.   r   c                      e Zd ZdZ ej
                  d      Z ej                  dd ej                  ddi      	      Z
 ej                  dd
 ej                  ddi      	      Z ej                  dd ej                  ddi      	      Z ej                  dd
 ej                  ddi      	      Z G d d      ZdefdZy)EmployeeObjectiveFilterz0
    Filter through EmployeeObjective model
    rX   rY   r   r   r   r   r   r   r   r   c                       e Zd ZeZg dZy)EmployeeObjectiveFilter.Meta)r   r^   r~   r   r   r   N)r/   r0   r1   r   rb   r<   r3   r.   r-   rc   r   R  s    !
r.   rc   r'   c                    |j                  d      }|j                  j                  j                         }|D ]=  }||j	                  |      z  |j	                  |      z  |j	                  |      z  }? |j                         S )re   rf   +employee_id__employee_first_name__icontains*employee_id__employee_last_name__icontains)objective__icontainsrm   rr   s          r-   rX   z%EmployeeObjectiveFilter.search_method]  s     S!&&++- 	E??u?UW??e?TV ???>@ 	 ~~r.   N)r/   r0   r1   r2   rL   rM   rx   r   r   r   start_date_fromstart_date_tillend_date_fromend_date_tillrc   ry   rX   r3   r.   r-   r   r   7  s     '^&&o>F/n//uff%56O
 0n//uff%56O
 .N--uff%56M
 .N--uff%56M	
 	
   r.   r   c                   8   e Zd Z ej                  dd      Z ej                  dd ej                  ddi            Z	 ej                  dd ej                  ddi            Z
 ej                  dd	 ej                  ddi            Z G d
 d      Zy)MeetingsFiltertitler8   )rQ   rN   r   r   r   r   	date__gte	date__ltec                       e Zd ZeZg dZy)MeetingsFilter.Meta)
r   managerquestion_template	is_active.employee_id__employee_work_info__department_id+employee_id__employee_work_info__company_id0employee_id__employee_work_info__job_position_id-employee_id__employee_work_info__work_type_id)employee_id__employee_work_info__shift_id5employee_id__employee_work_info__reporting_manager_idN)r/   r0   r1   r   rb   r<   r3   r.   r-   rc   r     s    
r.   rc   N)r/   r0   r1   rL   rM   rx   r   r   r   r   date_greater	date_lessrc   r3   r.   r-   r   r   n  s    &^&&'{SF$>$$uff%56D
 ->,,uff%56L
 *))uff%56I
 
r.   r   c                   0    e Zd ZdZ G d d      ZdefdZy)BonusPointSettingFilter0
    Filter through BonusPointSetting model
    c                       e Zd ZeZdZy)BonusPointSettingFilter.Metar   N)r/   r0   r1   r   rb   r<   r3   r.   r-   rc   r     r   r.   rc   r'   c                     |j                  d      }|j                  j                  j                         }|D ]*  }||j	                  |      z  |j	                  |      z  }, |j                         S re   rf   r   r   rm   rr   s          r-   rX   z%BonusPointSettingFilter.search_method  x     S!&&++- 	E??u?UW??e?TV 	 ~~r.   Nr/   r0   r1   r2   rc   ry   rX   r3   r.   r-   r   r     s    4    r.   r   c                   0    e Zd ZdZ G d d      ZdefdZy)EmployeeBonusPointFilterr   c                       e Zd ZeZdZy)EmployeeBonusPointFilter.Metar   N)r/   r0   r1   r	   rb   r<   r3   r.   r-   rc   r     s    "r.   rc   r'   c                     |j                  d      }|j                  j                  j                         }|D ]*  }||j	                  |      z  |j	                  |      z  }, |j                         S r   rm   rr   s          r-   rX   z&EmployeeBonusPointFilter.search_method  r   r.   Nr   r3   r.   r-   r   r     s        r.   r   )"r2   r   djangorL   r   r   base.filtersr   base.methodsr   
pms.modelsr   r   r	   r
   r   r   r   r   r   Filterr   r5   rW   r{   r   r   r   r   r   r   r   r   r   r3   r.   r-   <module>r      s        % " (
 
 
!n++ !H"0n.. "0J  I   FDo DN
_ 
@n66 8o  I  .	 	4 i 4 n 
Y  
\, i , ^ y  r.   