
    siI                        d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ 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)m*Z* d dl+m,Z, d dl-m.Z.  G d de&      Z/ G d de&      Z0 eee/      d        Z1 G d de&      Z2 G d d e&      Z3 G d! d"e&      Z4 G d# d$e&      Z5 G d% d&e&      Z6 G d' d(e&      Z7 G d) d*e&      Z8 G d+ d,e&      Z9y)-    N)literal_eval)Iterable)date	timedelta)apps)User)models)	post_save)receiver)reverse_lazy)	timesince)gettext_lazy)HorillaCompanyManager)Company)Employee)horilla_middlewares)_thread_locals)get_horilla_model_class)HorillaModelupload_path)HorillaAuditInfoHorillaAuditLogrender_template)notifyc                   :    e Zd ZdZd ed      fd ed      fgZ ej                  d      Z ej                  d      Z
 ej                  e      Z ej                  d	de
      Z ej                  eej"                  dd      Z ed      Zd Z fdZ xZS )Offboarding
    Offboarding model
    ongoingOngoing	completed	Completed   
max_length   
   )r%   defaultchoicesTr   )	on_deletenullverbose_name
company_idc                     | j                   S Ntitleselfs    6/var/www/python-projects/worksol/offboarding/models.py__str__zOffboarding.__str__/       zz    c                     | j                    }t        |   |i | |r@g d}|D ]7  }t               }| |_        |d   |_        |d   |_        |j                          9 y )N))zExit interview	interview)zWork Handoverhandover)FNFfnf)Farewellother)Archivedarchivedr      )pksupersaveOffboardingStageoffboarding_idr1   type)r3   argskwargsis_newstagesstagenew	__class__s          r4   rD   zOffboarding.save2   sn    WWd%f%F   &(%)"!!H	 8
 	r7   )__name__
__module____qualname____doc___statusesr	   	CharFieldr1   	TextFielddescriptionManyToManyFieldr   managersstatus
ForeignKeyr   CASCADEr-   r   objectsr5   rD   __classcell__rN   s   @r4   r   r      s     AiL)K;+HIHF+E"&""c2K%v%%h/HVYQF"""..	J $L1G r7   r   c            	       z   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d ed      fgZ ej                  d      Z ej                  de      Z	 ej                  eej                        Z ej                  e      Z ej"                  dd      ZdefdZd Zd Zd Zd Zy)rE   r   notice_periodzNotice periodr<   zFnF Settlementr>   Otherr9   	Interviewr:   zWork handoverr@   r?   r#   r$      )r%   r)   r*   r   F)r(   editablereturnc                 ,    t        | j                        S r/   )strr1   r2   s    r4   r5   zOffboardingStage.__str__[   s    4::r7   c                      | j                   dk(  S )zF
        This method is to check the stage is archived or not
        r@   )rG   r2   s    r4   is_archived_stagez"OffboardingStage.is_archived_stage^   s     yyJ&&r7   c                 6    t        d       d| j                   S )z7
        This method is used to get delete url
        zgeneric-deletez'?model=offboarding.OffboardingStage&pk=r   rB   r2   s    r4   get_delete_urlzOffboardingStage.get_delete_urld   s%     /011XY]Y`Y`Xabbr7   c                 f    t        dd| j                  i       d| j                  j                   S )z7
        This method is used to get update url
        zcreate-offboarding-stagerB   rI   z?offboarding_id=)r   rB   rF   r2   s    r4   get_update_urlzOffboardingStage.get_update_urlj   s5     94/RSScdhdwdwdzdzc{||r7   c                 :    t        d       d| j                   }|S )z=
        This method is used to get add employee url
        zadd-offboarding-employee
?stage_id=)r   idr3   urls     r4   get_add_employee_urlz%OffboardingStage.get_add_employee_urlp   s$     89:*TWWIN
r7   N)rO   rP   rQ   rR   rS   typesr	   rU   r1   rG   r[   r   r\   rF   rX   r   rY   IntegerFieldsequenceri   r5   rk   rn   rq   rw    r7   r4   rE   rE   G   s    
 
!O,-	"#$	!G*	an%	Q'(	Qz]#E F+E6r59D&V&&{fnnMN%v%%h/H"v""1u=H 'c}r7   rE   )senderc                 h    |r0t               }d|_        ||_        d|_        |j	                          yy)zT
    This is post save method, used to create initial stage for the recruitment
    zNotice Periodra   N)rE   r1   rF   rG   rD   )r|   instancecreatedrI   initial_stages        r4   create_initial_stager   y   s8    
 (*-'/$, r7   c                   6    e Zd ZdZ ej
                  e      Zy)OffboardingStageMultipleFilez&
    OffboardingStageMultipleFile
    )	upload_toN)rO   rP   rQ   rR   r	   	FileFieldr   
attachmentr{   r7   r4   r   r      s     "!!K8Jr7   r   c                       e Zd ZdZddgZ ej                  eej                  d      Z	 ej                  eej                  dd      Z ej                  d	      Z ej                  d
edd      Z ej"                  d	      Z ej"                  dd      Z ed      ZdefdZd Zd Zd Zd Zd Zd Zd Z fdZd Z d Z!d Z"d Z#d Z$d Z%d  Z& xZ'S )!OffboardingEmployeez7
    OffboardingEmployee model / Employee on stage
    )daydays)monthMonthr   r*   r,   StageTr*   r,   r+   )r+   r'   r   )r%   r)   r(   r+   )r+   blank+employee_id__employee_work_info__company_idrelated_company_fieldrg   c                 6    | j                   j                         S r/   )employee_idget_full_namer2   s    r4   r5   zOffboardingEmployee.__str__   s    --//r7   c                     | j                   j                  j                   d| j                   j                  j                   S )zZ
        Return subtitle containing both department and job position information.
         / r   employee_work_infodepartment_idjob_position_idr2   s    r4   detail_subtitlez#OffboardingEmployee.detail_subtitle   s;     ""55CCDCHXHXHkHkH{H{G|}}r7   c                 V    | j                   j                         }t        d| |d      S )zM
        This method for get custom column for stage in detail view.
        z'cbv/exit_process/detail_view_tasks.html)r~   taskspathcontext)employeetask_setallr   )r3   r   s     r4   detail_view_task_customz+OffboardingEmployee.detail_view_task_custom   s3     %%))+: 
 	
r7   c                 6    t        dd| j                  i       S )z@
        This method is used to get individual view url
        zoffboarding-individual-viewrB   rp   rm   r2   s    r4   get_individual_urlz&OffboardingEmployee.get_individual_url   s     <dDGG_UVWr7   c                     | j                   }t        j                         }|r?||k(  rt        d      n.||k  rt        d      n|rt        d      dz   t	        ||      z   nd}|rS dS )zU
        This method for get custom column for notice period in detail view.
        todayzNotice period endedIn  )notice_period_endsr   r   rS   r   )r3   r   r   cols       r4   get_notice_period_colz)OffboardingEmployee.get_notice_period_col   s|    
 "44

 &. '
 *E1 +, . $#	%9K(LL  )s0b0r7   c           	          ddl m} t        d|  || j                  j                  d| j                  j
                  i      | j                  j                  j                  j                         d      S )zO
        This method for get custom column for stage in Pipeline view.
        r   )StageSelectFormz(cbv/exit_process/pipeline_stage_col.htmlstage_id)offboardinginitial)employee
stage_formrK   r   )offboarding.formsr   r   r   rF   rB   offboardingstage_setr   )r3   r   s     r4   get_stage_colz!OffboardingEmployee.get_stage_col   sd     	6; - $ < <')9)9: --66KKOOQ

 
	
r7   c                     | j                   j                  d      j                         }| j                   j                         j                         }| d| }d| d| d| d}|S )zU
        This method for get custom column for task status in Pipeline view.
        r!   )rZ   r   z\
            <div class="oh-checkpoint-badge oh-checkpoint-badge--primary" title="Completed z of z tasks">
                z
            </div>
        )r   filtercountr   )r3   completed_taskstotal_taskstask_statusr   s        r4   get_task_status_colz'OffboardingEmployee.get_task_status_col   s     //66k6JPPR++//1779()[M:\\k[llpq|p} ~ 	
 
r7   c                 6    t        d| | j                  d      S )zP
        This method for get custom column for action in Pipeline view.
        z)cbv/exit_process/pipeline_action_col.html)r   rL   r   )r   r   r2   s    r4   get_action_colz"OffboardingEmployee.get_action_col   s      <!%>
 	
r7   c                 .   |j                  d      rs|j                  d      rbt        |dd       }t        j                  j                  || j                  | j                        j                         }t        d| ||d      S t        | -  |      }|S )Nget__task   )task_id__idemployee_id_idtask_id__stage_idz cbv/exit_process/tasks_cols.html)r~   tasktask_id)
startswithendswithr   EmployeeTaskr]   r   rt   r   firstr   rC   __getattribute__)r3   namer   r   valuerN   s        r4   r   z$OffboardingEmployee.__getattribute__  s    ??6"t}}W'="4":.G''..##ww"&-- /  eg	  #2!4GD  (.r7   c                    | j                   j                  }|j                  j                         j	                  d      }t        j                  |D cg c]  }|j                  |j                  d c}      }|S c c}w )z?
        This method is used to get ordered group json
        rz   )rt   rL   )	r   rF   r   r   order_byjsondumpsrt   r1   )r3   r   offboarding_stagesrL   ordered_group_jsons        r4   r   z&OffboardingEmployee.ordered_group_json  sy     mm22(==AACLLZX!ZZ 0
   (("[[
 "!s    A<c                 6    | j                   j                  rdS dS )zM
        This method is used to get title for the archive in actions
        Archivez
Un-Archive)r   	is_activer2   s    r4   get_archive_titlez%OffboardingEmployee.get_archive_title$  s     !,,66yHLHr7   c                 6    t        dd| j                  i       S )>
        This method is used to get the mail send url
        zsend-mail-employeeemp_idrp   rm   r2   s    r4   get_mail_send_urlz%OffboardingEmployee.get_mail_send_url*  s     3Xtww<OPQRr7   c                 6    t        dd| j                  i       S )zG
        This method is used to get the employee note view url
        zview-offboarding-noter   rp   rm   r2   s    r4   get_notes_urlz!OffboardingEmployee.get_notes_url0  s     
 3]DGG<TUV	
r7   c                 6    t        dd| j                  i       S )r   zemployee-archiveobj_idrp   rm   r2   s    r4   get_archive_urlz#OffboardingEmployee.get_archive_url8  s     18TWW:MNOPr7   c                 f    t        dd| j                  i       d| j                  j                   S )r   zadd-employeerB   rp   rs   )r   rB   r   rt   r2   s    r4   get_edit_urlz OffboardingEmployee.get_edit_url>  s3     ~tTWWoFGzRVR_R_RbRbQcddr7   c                 L    t        d       d| j                  j                   dS )r   zget-manager-inz?employee_id=z&offboarding=True)r   r   rt   r2   s    r4   get_managing_record_urlz+OffboardingEmployee.get_managing_record_urlD  s,     /01t?O?O?R?R>SSdeer7   )(rO   rP   rQ   rR   UNITr	   OneToOneFieldr   r\   r   r[   rE   r   ry   ra   rU   unit	DateFieldnotice_period_startsr   r   r]   ri   r5   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r^   r_   s   @r4   r   r      s    /0D&&&&FNNK !v  FNNtH (F''T2M6r4tTD+6++6)))t4@#KG0 0~
X12
$
"""IS
Qefr7   r   c                       e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  eej                  d	      Z
 ej                  d
d      Z ej                  dd      Z ej                         Z ej                  ded      Z ej                  eej                  dd      Z ed      Zd Zd Zd Zd Zd Zd Zd Zd Z fdZd Z xZ S )ResignationLetterz,
    Resignation Request Employee model
    	requested	RequestedapprovedApprovedrejectedRejectedr   r   d   T)r%   r+   r&   )r+   r%   r'   r%   r)   r(   F)r*   rf   r+   r   r   c                 ^    t        | j                        j                  | j                        S )z 
        Display status
        )dictrT   getrZ   r2   s    r4   
get_statuszResignationLetter.get_statusc  s"     DMM"&&t{{33r7   c                      t        dd| i      S )7
        This method for get custome coloumn .
        zcbv/resignation/options.htmlr~   r   r   r2   s    r4   option_columnzResignationLetter.option_columni      
 /&
 	
r7   c                      t        dd| i      S )r   zcbv/resignation/actions.htmlr~   r   r   r2   s    r4   actions_columnz ResignationLetter.actions_columns  r  r7   c                      t        dd| i      S )6
        This method for get custome column .
        z cbv/resignation/description.htmlr~   r   r   r2   s    r4   description_colz!ResignationLetter.description_col}  s    
 3&
 	
r7   c                      t        dd| i      S )r  z'cbv/resignation/detail_description.htmlr~   r   r   r2   s    r4   detail_description_colz(ResignationLetter.detail_description_col  s    
 :&
 	
r7   c                     | j                   j                  j                   d| j                   j                  j                   S )z&
        Detail view subtitle
        z /
          r   r2   s    r4   resgnation_subtitlez%ResignationLetter.resgnation_subtitle  sF    
 $$77EEG H//??
@D 	Dr7   c                 8    t        dd| j                  i      }|S )!
        Detail view url
        z resignation-requests-detail-viewrB   rp   rm   ru   s     r4   get_detail_urlz ResignationLetter.get_detail_url  s     =tTWWoV
r7   c                 8    t        dd| j                  i      }|S )r  z$tab-resignation-requests-detail-viewrB   rp   rm   ru   s     r4   get_detail_tab_urlz$ResignationLetter.get_detail_tab_url  s"     2D$''?
 
r7   c                 D    t        |   |i | | j                  dk(  r	 y )Nr   )rC   rD   rZ   )r3   rH   rI   rN   s      r4   rD   zResignationLetter.save  s&    d%f%;;*$r7   c                    t         j                  j                  | j                        j	                         }|r|n	t               }| j                  |_        t
        j                  j                  d      j                  |      j	                         |_        t        j                  d      r%t        dd      j                  j	                         nd}	 |s|r|t        |j                        z   n|}||_        ||_        |r|rt        |t               st        |t               st#        |j$                  |j&                  |j(                        t#        |j$                  |j&                  |j(                        z
  }|j*                  }|d	kD  r|nd|_        |d	kD  rd
nd|_        |j/                          y#  |}Y xY w)zL
        This method is used to convert/add employee to offboarding
        )r   
created_at)rF   payrollpayrollgeneralsetting)	app_labelmodelN)r   r   yearr   r   )r   r]   r   r   r   rE   r   r   r   is_installedr   r   ra   r   r   
isinstanceri   r   r   r   r  r   r   rD   )r3   r   r   r   offboarding_employeedefault_notice_enddiffss          r4   to_offboarding_employeez)ResignationLetter.to_offboarding_employee  s     3::AA((  B  

%' 	 %9 >Q>S 	 ,0+;+;($$--l;V;V/UW 	%   + $#+Bgeeg 		4% * )95G5U5U+VV+ # 5I12D/ "3S9137&**(..',, (,,*00)..	E JJE:?!) .16 %!!#/	4!3s   F9 9F?)!rO   rP   rQ   rR   rS   rT   r	   r[   r   r\   r   rU   r1   rV   rW   r   planned_to_leave_onrZ   r   offboarding_employee_idr   r]   r   r   r  r  r  r
  r  r  rD   r  r^   r_   s   @r4   r   r   K  s   
 
an%	Qz]#	Qz]#H
 $&##FNNK F$7E"&""=K*&**,VX{SF/f//v~~D $KG4



D8$r7   r   c                       e Zd ZdZ ej
                  d      Z ej                  e      Z	 ej                  eej                  ddd      Z G d d      Zd	efd
Zy)OffboardingTaskz
    OffboardingTask model
       r$   r   T)r*   r,   r+   r   c                       e Zd ZddgZy)OffboardingTask.Metar1   r   NrO   rP   rQ   unique_togetherr{   r7   r4   Metar$    s    "J/r7   r'  rg   c                     | j                   S r/   r0   r2   s    r4   r5   zOffboardingTask.__str__  r6   r7   N)rO   rP   rQ   rR   r	   rU   r1   rX   r   rY   r[   rE   PROTECTr   r'  ri   r5   r{   r7   r4   r!  r!    sh     F+E%v%%h/H v  ..H0 0 r7   r!  c                   h    e Zd ZdZ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      Z
 ej                  ded      Z ej                  eej                        Z ej                  ddd      Z edeg      Z G d d      Z fdZ xZS )r   z
    EmployeeTask model
    todoTodoin_progresszIn progressstuckStuckr!   r"   r   Tr   r#   r   re   Fr&   )r+   rf   r%   history_set)related_namebasesc                       e Zd ZddgZy)EmployeeTask.Metar   r   Nr%  r{   r7   r4   r'  r4    s    ()4r7   r'  c                    t        |   |i | t        t        dd       }t	        j
                  |j                  j                  | j                  j                  j                  d| j                  j                   d    dd	       y )NrequestzOffboarding task "z" has been assignedz offboarding/offboarding-pipelineinformation)	recipientverbverb_arverb_deverb_esverb_frredirecticon)rC   rD   getattrr   r   senduseremployee_getr   employee_user_idr   r1   )r3   rH   rI   r6  rN   s       r4   rD   zEmployeeTask.save  sz    d%f%.)T:LL%%&&22CC%dll&8&8%99LM7
	
r7   )rO   rP   rQ   rR   rS   rT   r	   r[   r   r\   r   rU   rZ   r!  r   rV   rW   r   r   historyr'  rD   r^   r_   s   @r4   r   r     s    
 
6	-()	!G*	an%	H $&##..	K VXvNFf6>>JG"&""uMK"
G5 5
 
r7   r   c                       e Zd ZdZ ej
                  d      Z ej                  d      Z ej                  e
ej                        Z ej                  e      Zy)
ExitReasonz
    ExitReason model
    2   r$   r&   re   N)rO   rP   rQ   rR   r	   rU   r1   rV   rW   r[   r   r\   r  rX   r   attachmentsr{   r7   r4   rG  rG  /  s^     F+E"&""c2K/f//v~~ )&(()EFKr7   rG  c                   J    e Zd ZdZ ej
                  edd      Z ej                  ddd      Z	 ej                  eej                  dd      Z ej                  eej                  dd      Z ej                  eej$                  dd      Z G d d	      Z fd
Z xZS )OffboardingNotez
    OffboardingNote
    TF)r   rf   r&   )r+   r   r%   )r*   r+   rf   c                       e Zd ZdgZy)OffboardingNote.Metaz-created_atN)rO   rP   rQ   orderingr{   r7   r4   r'  rM  O  s	    !?r7   r'  c                     t        t        j                  dd       }|r|j                  j                  }|| _        | j                  r| j                  j                  | _        t        | $  |i |S )Nr6  )
r@  r   r   rB  rC  note_byr   r   rC   rD   )r3   rH   rI   r6  
updated_byrN   s        r4   rD   zOffboardingNote.saveR  sa    -<<iN 22J%DL ,,55DMw|T,V,,r7   )rO   rP   rQ   rR   r	   rX   r   rI  rV   rW   r[   r   SET_NULLrP  r   r\   r   rE   r)  r   r'  rD   r^   r_   s   @r4   rK  rK  <  s     )&(($D5K #&""DSIKfFOO$G $&##v~~D5K !v  FNNH# #- -r7   rK  c                   t    e Zd ZdZ ej
                  d      Z ej                  eej                  d      Z
y)OffboardingGeneralSettingz$
    OffboardingGeneralSettings
    F)r(   T)r*   r+   N)rO   rP   rQ   rR   r	   BooleanFieldresignation_requestr[   r   r\   r-   r{   r7   r4   rT  rT  \  s6     .&--e<"""7fnn4PJr7   rT  ):r   astr   collections.abcr   datetimer   r   django.appsr   django.contrib.auth.modelsr   	django.dbr	   django.db.models.signalsr
   django.dispatchr   django.urlsr   django.utils.timesincer   django.utils.translationr   rS   base.horilla_company_managerr   base.modelsr   employee.modelsr   horillar   horilla.horilla_middlewaresr   horilla.methodsr   horilla.modelsr   r   horilla_audit.modelsr   r   horilla_views.cbv_methodsr   notifications.signalsr   r   rE   r   r   r   r   r!  r   rG  rK  rT  r{   r7   r4   <module>rl     s      $ $  +  . $ $ , 6 >  $ ' 6 3 4 B 5 (
', 'T/| /d 
)K(	 )	9< 9zf, zfz]$ ]$@l ,+
< +
\
G 
G-l -@Q Qr7   