B
    b3                 @   s.  d dl Z d dlmZ d dl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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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j%Z&G dd deZ'G dd dej(eZ)dS )    N)datetime)Count	Aggregate	TextField)Q)	TruncDate)gettext_lazyactivate)	FilterSet)mixinsserializers)APIException)STATUS_VALID)NoneSerializer)ReportUtilGenericViewSetReportGenericFilter)short_date_format)Transaction)CHOICE_GENDER)
C_ATT_RULE)r   STATUS_RESIGN_PENDINGc               @   s  e Zd ZejedddZejeddddZejedd	ddZejed
dddZ	ej
eddZejeddddZejeddddZejeddddZejeddddZej
eddZejeddddZej
eddZdd Zdd Zd d! ZG d"d# d#Zd$S )%"TotalTempDetectionReportSerializerZreport_column_empCodeemp__emp_code)labelsourceZreport_column_firstNameemp__first_nameT)r   r   Z
allow_nullZreport_column_lastNameemp__last_nameZreport_column_nickNameemp__nicknameZreport_column_gender)r   Zreport_column_departmentCodeemp__department__dept_codeZreport_column_departmentNameemp__department__dept_nameZreport_column_positionCodeemp__position__position_codeZreport_column_positionNameemp__position__position_nameZreport_column_attendanceDateZreport_column_punchTimestimesr   )r   r   defaultZreport_column_tempSetc             C   s   t t|d |d S )Nemp__gender)dictr   get)selfobj r)   LG:\easytimepro\master/mysite/att\api\views\view_report_totaltempdetection.py
get_gender+   s    z-TotalTempDetectionReportSerializer.get_genderc             C   s   | dd }|sdS t|S )N
punch_date )r&   r   )r'   r(   att_dater)   r)   r*   get_att_date.   s    z/TotalTempDetectionReportSerializer.get_att_datec             C   s   ddl m} g }|dd }|dd }t|tj }t|tj }tj	j
|||dd}x2|D ]*}	|	jrj|	j}
||
|	j}|t| qjW d|}|S )Nr   )temperature_updater,   emp_id)r1   Zpunch_time__gteZpunch_time__ltez-punch_timez, )mysite.att.utilsr0   r&   r   Zcombinemintimemaxr   objectsfilterorder_byZtemperature
company_idappendstrjoin)r'   r(   r0   temp_setr,   r1   Zpuch_time_startZpuch_time_endZtransZtranZcelsiusZtemperature_based_on_unitr)   r)   r*   get_temp_set4   s    


z/TotalTempDetectionReportSerializer.get_temp_setc               @   s   e Zd ZeZdZdS )z'TotalTempDetectionReportSerializer.Meta)emp_code
first_name	last_name	nick_namegender	dept_code	dept_nameposition_codeposition_namer.   punch_timesr=   N)__name__
__module____qualname__r   modelfieldsr)   r)   r)   r*   MetaF   s   rN   N)rI   rJ   rK   r   Z	CharField_r?   r@   rA   rB   ZSerializerMethodFieldrC   rD   rE   rF   rG   r.   ZIntegerFieldrH   r=   r+   r/   r>   rN   r)   r)   r)   r*   r      s(   r   c               @   sZ   e Zd Zejr,ejdddZejdddZnejdddZejdddZG dd dZ	dS )	TotalTempDetectionReportFilterr,   Zgte)Z
field_namelookup_exprZlte)namerQ   c               @   s   e Zd ZeZdddddgZdS )z#TotalTempDetectionReportFilter.MetaZ	employeesZdepartmentsZareas
start_dateend_dateN)rI   rJ   rK   r   rL   rM   r)   r)   r)   r*   rN   V   s   rN   N)
rI   rJ   rK   sixZPY3django_filtersZ
DateFilterrS   rT   rN   r)   r)   r)   r*   rP   N   s   rP   c                   sR   e Zd ZeZej  dZ	e
ZeedZ fddZdd Zdd Z  ZS )	TotalTempDetectionReportViewSetz-punch_time)listZexportc                sZ  t t|  }| jjj}| jjjs6d|i}|jf |}|jt	dd}|
dddddd	d
dddddd}|jtdd}y| jjjs| jjj}| jjj}| jjj}| r|j| d}| r|j| d }| r|j| d}tt|d}|dkr4|ttdtd dB ttdB }|S  tk
rT   tdY nX d S )NZemp__company_idZ
punch_time)r,   r1   r   r   r   r   r   r   r    r!   r,   r$   )r"   )Zemp__department__in)Zemp__area__in)Zemp__position__in
resign_emp0)Zemp__statuszPlease Check with Admin)superrW   get_querysetZrequestuserZcurrent_companyZis_employeer7   Zannotater   valuesr8   r   Zis_superuserZget_auth_deptZget_auth_areaZget_auth_posexistsallZdistinctr;   r   r&   r   r   r   	Exceptionr   )r'   querysetr9   Zbase_filterZ	auth_deptZ	auth_areaZauth_posrY   )	__class__r)   r*   r\   e   sB    







 z,TotalTempDetectionReportViewSet.get_querysetc             C   s   | j | jtS )N)serializer_dictr&   actionr   )r'   r)   r)   r*   get_serializer_class   s    z4TotalTempDetectionReportViewSet.get_serializer_classc             C   s   t d tdS )NZenzTotal Temp Detection Report)r	   rO   )r'   r)   r)   r*   get_file_title   s    z.TotalTempDetectionReportViewSet.get_file_title)rI   rJ   rK   r   rL   r6   r\   Zselect_relatedr8   rb   rP   Zfilter_classr   rd   rf   rg   __classcell__r)   r)   )rc   r*   rW   [   s   %rW   )*rU   r   rV   Zdjango.db.modelsr   r   r   r   Zdjango.db.models.functionsr   Zdjango.utils.translationr   rO   r	   Zdjango_filters.rest_frameworkr
   Zrest_frameworkr   r   Zrest_framework.exceptionsr   Zmysite.admin.modelsr   Zmysite.att.api.serializersr   Zmysite.att.api.utils_classr   r   r2   r   Zmysite.iclock.modelsr   Zmysite.personnel.db_constr   Zmysite.att.global_cacher   r   ZModelSerializerr   rP   ZListModelMixinrW   r)   r)   r)   r*   <module>   s*   5