B
    b                 @   s   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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mZ G dd deZee
G dd dejZ dS )    )	ModelForm)gettext_lazy)ModelChoiceField)adminconfig)TrainingTrainingCategory)AddTrainingTrainingApproveTrainingRevoke)forms)Employee)get_current_company_id)Q)
C_ATT_RULE)STATUS_VALIDSTATUS_RESIGN_PENDINGc                   s   e Zd ZejedddZejeddZejeddZ	e
edej dZejed	d
dZ fddZG dd dZ  ZS )TrainingChangeFormZtraining_field_employeeT)labelZdisabledZtraining_field_startTime)r   Ztraining_field_endTimeZtraining_field_trainingCategory)r   querysetZtraining_field_applyReasonF)r   requiredc                s`   t t| j|| t }tjj|d| jd _d| jd j	j
d< | jjr\t| jj| jd _d S )N)
company_idcategoryTempreadonly)superr   __init__r   r   objectsfilterfieldsr   ZwidgetZattrsinstanceZpkstrZemployeeinitial)selfargskwargsr   )	__class__ 8G:\easytimepro\master/mysite/att\admin\training_admin.pyr      s    zTrainingChangeForm.__init__c               @   s   e Zd ZeZdZdS )zTrainingChangeForm.Meta)
start_timeend_timer   apply_reasonN)__name__
__module____qualname__r   Zmodelr   r'   r'   r'   r(   Meta#   s   r/   )r,   r-   r.   r   Z	CharField_r   ZDateTimeFieldr)   r*   r   r   r   get_querysetr   Z	TextFieldr+   r   r/   __classcell__r'   r'   )r&   r(   r      s   r   c                   sD   e Zd ZdZejd ZeZe	e
egZdZdd Z fddZ  ZS )TrainingAdmin)idZget_emp_codeZget_emp_first_nameZget_emp_last_nameZget_emp_deptZget_emp_jobr   r)   r*   r+   Z
apply_timeaudit_statusZget_audit_reasonZ
audit_timeZlast_approver)r   r)   r*   r5   )z-idc             C   s   dS )NFr'   )r#   requestr'   r'   r(   has_add_permission3   s    z TrainingAdmin.has_add_permissionc       	         s   |j j}|j j}|j j}|j j}tt| |j|d}|j j	s|
 rX|j| d}|
 r~tjj| d}|j|d}|
 r|j| d}tt|d}|dkr|ttdtd dB ttdB }|S )	N)Zemployee__company_id)Zemployee__department__in)Zarea__in)Zemployee__in)Zemployee__position__in
resign_emp0)Zemployee__status)userZcurrent_companyZget_auth_deptZget_auth_areaZget_auth_posr   r3   r1   r   Zis_superuserexistsallr   r   r!   r   getr   r   r   )	r#   r6   r   Z	auth_deptZ	auth_areaZauth_posZqsZemp_list_by_arear8   )r&   r'   r(   r1   6   s&     zTrainingAdmin.get_queryset)r,   r-   r.   Zlist_displayr   ZEMPLOYEE_LIST_FILTERZlist_filterr   Zformr	   r
   r   ZactionsZorderingr7   r1   r2   r'   r'   )r&   r(   r3   (   s   

r3   N)!Zdjango.formsr   Zdjango.utils.translationr   r0   r   mysiter   r   Zmysite.att.modelsr   r   Zmysite.att.actionsr	   r
   r   Zmysite.adminr   Z&mysite.personnel.models.model_employeer   Zmysite.att.utilsr   Zdjango.db.modelsr   Zmysite.att.global_cacher   Zmysite.admin.modelsr   r   r   registerZZKModelAdminr3   r'   r'   r'   r(   <module>   s   