B
    bp7                 @   s  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 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 G dd de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZ G dd de	jZ!G dd  d e	j"Z#G d!d" d"e	j"Z$G d#d$ d$e	j"Z%G d%d& d&e	j"Z&G d'd( d(e	j"Z'G d)d* d*e	j"Z(G d+d, d,ej)Z*dS )-    N)Count)make_password)gettext_lazy)serializers)Employee)Position)
Department)Area)Resign)db_const)util_serializersc               @   s6   e Zd ZejdddZejdddZG dd dZdS )SimpleEmployeeSerializerzdepartment.dept_nameT)source
allow_nullzposition.position_namec               @   s   e Zd ZeZdZdS )zSimpleEmployeeSerializer.Meta)	idemp_code
first_name	last_name	hire_date	dept_name
departmentpositionposition_nameN)__name__
__module____qualname__r   modelfields r   r   NG:\easytimepro\master/mysite/personnel\api\serializers\employee_serializers.pyMeta   s   r    N)r   r   r   r   	CharFieldr   r   r    r   r   r   r   r      s
   r   c               @   sJ   e Zd ZejdddZe ZejdddZdZ	dd Z
G dd	 d	Zd
S )EmployeeFilterSerializerzdepartment.dept_nameT)r   r   zposition.position_name)r   c             C   s*   |j  }|r"ddd |D S d S d S )N,c             S   s   g | ]
}|j qS r   )	area_name).0arear   r   r   
<listcomp>*   s    z:EmployeeFilterSerializer.get_area_name.<locals>.<listcomp>)r&   alljoin)selfobjareasr   r   r   get_area_name'   s    
z&EmployeeFilterSerializer.get_area_namec               @   s   e Zd ZeZdZdS )zEmployeeFilterSerializer.Meta)r   r   r   r   r   r   r   r   r   r&   r$   N)r   r   r   r   r   r   r   r   r   r   r    .   s   r    N)r   r   r   r   r!   r   SerializerMethodFieldr$   r   Zfilter_fieldsr-   r    r   r   r   r   r"      s   r"   c               @   s   e Zd ZG dd dZdS )PositionSerializerc               @   s   e Zd ZeZdddgZdS )zPositionSerializer.Metar   Zposition_coder   N)r   r   r   r   r   r   r   r   r   r   r    6   s   r    N)r   r   r   r    r   r   r   r   r/   4   s   r/   c               @   s   e Zd ZG dd dZdS )DepartmentSerializerc               @   s   e Zd ZeZdddgZdS )zDepartmentSerializer.Metar   Z	dept_coder   N)r   r   r   r   r   r   r   r   r   r   r    =   s   r    N)r   r   r   r    r   r   r   r   r0   ;   s   r0   c               @   s   e Zd ZG dd dZdS )AreaSerializerc               @   s   e Zd ZeZdddgZdS )zAreaSerializer.Metar   Z	area_coder$   N)r   r   r   r	   r   r   r   r   r   r   r    D   s   r    N)r   r   r   r    r   r   r   r   r1   B   s   r1   c               @   sp   e Zd Ze Ze ZeddZe	
 Ze	
 Ze	
 Ze	
 ZG dd dZdd Zdd Zd	d
 Zdd ZdS )EmployeeSerializerT)manyc            '   @   sb   e Zd ZeZddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'g'Zd(S ))zEmployeeSerializer.Metar   r   r   r   nicknamedevice_passwordcard_nor   r   r   genderbirthdayverify_modeemp_typecontact_tel
office_telmobilenationalcityaddresspostcodeemail	enroll_snssnreligion
enable_attenable_overtimeenable_holidaydev_privilegeself_password	flow_roler&   
app_statusapp_roleupdate_timefingerprintfacepalmvl_faceN)r   r   r   r   r   r   r   r   r   r   r    R   s   

r    c             C   s>   |j jdddtd}|r:ddd |D }|S dS )	N   )bio_type	major_verr   r#   c             S   s   g | ]}d | qS )z	Ver %s:%sr   )r%   bior   r   r   r'   d   s    z6EmployeeSerializer.get_fingerprint.<locals>.<listcomp>-)biodata_setfiltervalues_listannotater   r)   )r*   r+   biosoutputr   r   r   get_fingerprinta   s
    z"EmployeeSerializer.get_fingerprintc             C   s>   |j jdddtd}|r:ddd |D }|S dS )	N   )rT   rU   r   r#   c             S   s   g | ]}d | qS )z	Ver %s:%sr   )r%   rV   r   r   r   r'   k   s    z/EmployeeSerializer.get_face.<locals>.<listcomp>rW   )rX   rY   rZ   r[   r   r)   )r*   r+   r\   r]   r   r   r   get_faceh   s
    zEmployeeSerializer.get_facec             C   s>   |j jdddtd}|r:ddd |D }|S dS )	N   )rT   rU   r   r#   c             S   s   g | ]}d | qS )z	Ver %s:%sr   )r%   rV   r   r   r   r'   r   s    z/EmployeeSerializer.get_palm.<locals>.<listcomp>rW   )rX   rY   rZ   r[   r   r)   )r*   r+   r\   r]   r   r   r   get_palmo   s
    zEmployeeSerializer.get_palmc             C   s>   |j jdddtd}|r:ddd |D }|S dS )	N	   )rT   rU   r   r#   c             S   s   g | ]}d | qS )z	Ver %s:%sr   )r%   rV   r   r   r   r'   y   s    z2EmployeeSerializer.get_vl_face.<locals>.<listcomp>rW   )rX   rY   rZ   r[   r   r)   )r*   r+   r\   r]   r   r   r   get_vl_facev   s
    zEmployeeSerializer.get_vl_faceN)r   r   r   r0   r   r/   r   r1   r&   r   r.   rO   rP   rQ   rR   r    r^   r`   rb   rd   r   r   r   r   r2   I   s   
r2   c               @   s0   e Zd Ze Ze ZeddZG dd dZ	dS )EmployeeExportSerializerT)r3   c            $   @   s\   e Zd ZeZddddddddd	d
dddddddddddddddddddddd d!d"d#d$g$Zd%S )&zEmployeeExportSerializer.Metar   r   r   r   r4   r5   r6   r   r   r   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r&   rL   rM   Zenable_whatsappZ
enable_smsN)r   r   r   r   r   r   r   r   r   r   r       s   

r    N)
r   r   r   r0   r   r/   r   r1   r&   r    r   r   r   r   re   ~   s   
re   c               @   s"   e Zd Zdd ZG dd dZdS )EmployeeCreateSerializerc             C   s   | dd|d< |d s d|d< | dd|d< | dd|d< |d sPd|d< |d dsnt|d |d< | dd	|d< | d
d|d
< | dd|d< | dstj |d< |S )NrL   r   rM   rS   rJ   Z123456Zpbkdf2_r9   rF   TrI   r   )get
startswithr   datetimedateZtoday)r*   attrsr   r   r   validate   s    
z!EmployeeCreateSerializer.validatec            "   @   s   e Zd ZeZddddddddd	d
dddddddddddddddddddddd d!d"g"Zd#d$d%d&d'd(id'd)id'd)id'd*d+d, ejD id'd*d-d, ej	D id'd*d.d, ej
D id'd*d/d, ejD id'd*d0d, ejD id1	Zd2S )3zEmployeeCreateSerializer.Metar   r   r   r   r4   r5   r6   r   r   r   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r&   rL   rM   TFzDepartment ForeignKey)requiredr   	help_textro   ZManyToManyFieldzDefault today;c             C   s   g | ]}t |qS r   )str)r%   ir   r   r   r'      s    z(EmployeeCreateSerializer.Meta.<listcomp>c             C   s   g | ]}t |qS r   )rq   )r%   rr   r   r   r   r'      s    c             C   s   g | ]}t |qS r   )rq   )r%   rr   r   r   r   r'      s    c             C   s   g | ]}t |qS r   )rq   )r%   rr   r   r   r   r'      s    c             C   s   g | ]}t |qS r   )rq   )r%   rr   r   r   r   r'      s    )	r   r&   r   r9   r:   rF   rI   rL   rM   N)r   r   r   r   r   r   r)   r   EMPTYPE_CHOICESZBOOLEANSZPRIV_CHOICESZ
APP_STATUSZAPP_ROLEextra_kwargsr   r   r   r   r       s&   


r    N)r   r   r   rm   r    r   r   r   r   rf      s   rf   c               @   s4   e Zd Zeje ddZdd ZG dd dZdS )EmployeeEditSerializerF)rn   c             C   s   t j  |d< |S )NrN   )rj   Znow)r*   rl   r   r   r   rm      s    zEmployeeEditSerializer.validatec            !   @   sd   e Zd ZeZddddddddd	d
dddddddddddddddddddddd d!g!Zdd"d"d#iZd$S )%zEmployeeEditSerializer.Metar   r   r   r4   r5   r6   r   r   r   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r&   rL   rM   F)rn   r   N)r   r   r   r   r   r   rt   r   r   r   r   r       s   

r    N)	r   r   r   r   ZManyRelatedFieldr!   r&   rm   r    r   r   r   r   ru      s   ru   c               @   s4   e Zd Zeje dZe Zdd Z	dd Z
dS )"EmployeeAdjustDepartmentSerializer)childc             C   sB   t t|}x0|D ](}tjj|d stdd| iqW |S )N)r   	employeesz(Invalid pk "%s" - object does not exist.)listsetr   objectsrY   existsr   ValidationError)r*   rx   employeer   r   r   validate_employees   s    
z5EmployeeAdjustDepartmentSerializer.validate_employeesc             C   s(   t jj|d s$tdd| i|S )N)r   r   z(Invalid pk "%s" - object does not exist.)r   r{   rY   r|   r   r}   )r*   r   r   r   r   validate_department   s    z6EmployeeAdjustDepartmentSerializer.validate_departmentN)r   r   r   r   	ListFieldr!   rx   IntegerFieldr   r   r   r   r   r   r   rv      s
   rv   c               @   s4   e Zd Zeje dZe Zdd Z	dd Z
dS ) EmployeeAdjustPositionSerializer)rw   c             C   sB   t t|}x0|D ](}tjj|d stdd| iqW |S )N)r   rx   z(Invalid pk "%s" - object does not exist.)ry   rz   r   r{   rY   r|   r   r}   )r*   rx   r~   r   r   r   r      s    
z3EmployeeAdjustPositionSerializer.validate_employeesc             C   s(   t jj|d s$tdd| i|S )N)r   r   z(Invalid pk "%s" - object does not exist.)r   r{   rY   r|   r   r}   )r*   r   r   r   r   validate_position  s    z2EmployeeAdjustPositionSerializer.validate_positionN)r   r   r   r   r   r!   rx   r   r   r   r   r   r   r   r   r      s
   r   c               @   s<   e Zd Zeje dZeje dZdd Z	dd Z
dS )EmployeeAdjustAreaSerializer)rw   c             C   sB   t t|}x0|D ](}tjj|d stdd| iqW |S )N)r   rx   z(Invalid pk "%s" - object does not exist.)ry   rz   r   r{   rY   r|   r   r}   )r*   rx   r~   r   r   r   r     s    
z/EmployeeAdjustAreaSerializer.validate_employeesc             C   sB   t t|}x0|D ](}tjj|d stdd| iqW |S )N)r   r,   z(Invalid pk "%s" - object does not exist.)ry   rz   r	   r{   rY   r|   r   r}   )r*   r,   r&   r   r   r   validate_areas  s    
z+EmployeeAdjustAreaSerializer.validate_areasN)r   r   r   r   r   r!   rx   r   r,   r   r   r   r   r   r   r     s   r   c               @   sF   e Zd Zeje dZejej	d
dd ej	D dZdd ZdS )	EmployeeAdjustEmptypeSerializer)rw   rp   c             C   s   g | ]}t |qS r   )rq   )r%   Zchoicer   r   r   r'   ,  s    z*EmployeeAdjustEmptypeSerializer.<listcomp>)choicesro   c             C   sB   t t|}x0|D ](}tjj|d stdd| iqW |S )N)r   rx   z(Invalid pk "%s" - object does not exist.)ry   rz   r   r{   rY   r|   r   r}   )r*   rx   r~   r   r   r   r   .  s    
z2EmployeeAdjustEmptypeSerializer.validate_employeesN)r   r   r   r   r   r!   rx   ChoiceFieldr   rs   r)   r:   r   r   r   r   r   r   &  s   r   c               @   sJ   e Zd Zeje dZe Zej	e
jdZe Ze Zdd ZdS )EmployeeAdjustResignSerializer)rw   )r   c             C   sf   t t|}xT|D ]L}tjj|d s:tdd| itjj|d rtdd| iqW |S )N)r   rx   z(Invalid pk "%s" - object does not exist.)Zemployee_idzEmployee "%s" exist in resign.)	ry   rz   r   r{   rY   r|   r   r}   r
   )r*   rx   r~   r   r   r   r   @  s    
z1EmployeeAdjustResignSerializer.validate_employeesN)r   r   r   r   r   r!   rx   Z	DateFieldZresign_dater   r   Z	LEAVETYPEZresign_typereasonBooleanFieldZ
disableattr   r   r   r   r   r   7  s   r   c               @   s`   e Zd Zeje dZejddZejddZ	ejddZ
ejddZejddZdd ZdS ) EmployeeDelbiotemplateSerializer)rw   F)defaultc             C   sB   t t|}x0|D ](}tjj|d stdd| iqW |S )N)r   rx   z(Invalid pk "%s" - object does not exist.)ry   rz   r   r{   rY   r|   r   r}   )r*   rx   r~   r   r   r   r   V  s    
z3EmployeeDelbiotemplateSerializer.validate_employeesN)r   r   r   r   r   r   rx   r   Zfinger_printrP   Zfinger_veinrQ   rR   r   r   r   r   r   r   L  s   r   c               @   s   e Zd ZG dd dZdS )EmployeeActionSerializerc               @   s   e Zd ZeZdZdS )zEmployeeActionSerializer.Meta))deleter   )sync_hronize_to_devicer   )enable_app_accountr   )disable_app_accountr   N)r   r   r   r   r   Zaction_type_choicesr   r   r   r   r    a  s   r    N)r   r   r   r    r   r   r   r   r   _  s   r   )+rj   Zdjango.db.modelsr   Zdjango.contrib.auth.hashersr   Zdjango.utils.translationr   _Zrest_frameworkr   Z&mysite.personnel.models.model_employeer   Z&mysite.personnel.models.model_positionr   Z(mysite.personnel.models.model_departmentr   Z"mysite.personnel.models.model_arear	   Z$mysite.personnel.models.model_resignr
   Zmysite.personnelr   Z mysite.personnel.api.serializersr   ZModelSerializerr   r"   r/   r0   r1   r2   re   rf   ru   Z
Serializerrv   r   r   r   r   r   ZObjectActionSerializerr   r   r   r   r   <module>   s6   52