B
    b                 @   s   d dl Z 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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mZ d dlmZmZ d dlmZ d dl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)Q)	TruncDate)gettext_lazyactivate)	FilterSet)mixinsserializers)STATUS_VALIDSTATUS_RESIGN_PENDING)NoneSerializer)ReportUtilGenericViewSetReportGenericFilter)short_date_formatshort_time_format)TransactionTerminalWorkCode)
C_ATT_RULEc               @   sl  e Z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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ZejeddZejeddZejedddZejedddZejeddd Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* ZG d+d, d,Zd-S ).!MobileTransactionReportSerializerZreport_column_empCodezemp.emp_codeT)labelsource
allow_nullZreport_column_firstNamezemp.first_nameZreport_column_lastNamezemp.last_nameZreport_column_nickNamezemp.nicknameZreport_column_genderzemp.get_gender_displayZreport_column_departmentCodezemp.department.dept_codeZreport_column_departmentNamezemp.department.dept_nameZreport_column_positionCodezemp.position.position_codeZreport_column_positionNamezemp.position.position_nameZreport_column_punchDate)r   Zreport_column_punchTimeZreport_column_punchStateZreport_column_workCodeAliasZreport_column_verifyTypeZget_verify_type_display)r   r   Zreport_column_dataSourcesZget_source_displayZreport_column_gps_location)r   r   c             C   s   ddl m} y|| jd jjd}W n*   || jd jjjjd}Y nX x$|	 D ]}|d |kr`|d S q`W d S )Nr   )r   request	func_keysvaluename)
mysite.att.global_cacher   getcontextusercurrent_companyZ
departmentZcompanyidvalues)selfr   r   r   v r$   KG:\easytimepro\master/mysite/att\api\views\view_report_mobiletransaction.pyget_func_key8   s    $z.MobileTransactionReportSerializer.get_func_keyc             C   s   |  |jS )N)r&   punch_state)r"   objr$   r$   r%   get_punch_stateB   s    z1MobileTransactionReportSerializer.get_punch_statec             C   s
   t |jS )N)r   date)r"   r(   r$   r$   r%   get_att_dateE   s    z.MobileTransactionReportSerializer.get_att_datec             C   s
   t |jS )N)r   
punch_time)r"   r(   r$   r$   r%   get_punch_timeH   s    z0MobileTransactionReportSerializer.get_punch_timec             C   s,   d}|j r(tjj|j d}|r(|d j}|S )N )coder   )	work_coder   objectsfilteralias)r"   r(   r3   Z
work_codesr$   r$   r%   get_work_code_aliasK   s    
z5MobileTransactionReportSerializer.get_work_code_aliasc               @   s   e Zd ZeZdZdS )z&MobileTransactionReportSerializer.Meta)r    emp_code
first_name	last_name	nick_namegender	dept_code	dept_nameposition_codeposition_namer0   att_datework_code_aliasr,   r'   verify_typer   gps_locationN)__name__
__module____qualname__r   modelfieldsr$   r$   r$   r%   MetaS   s   rG   N)rB   rC   rD   r   Z	CharField_r5   r6   r7   r8   r9   r:   r;   r<   r=   ZSerializerMethodFieldr>   r,   r'   r?   r@   r   rA   r&   r)   r+   r-   r4   rG   r$   r$   r$   r%   r      sL   
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 )	TransactionReportFilterr*   Zgte)Z
field_namelookup_exprZlte)r   rJ   c               @   s   e Zd ZeZdddddgZdS )zTransactionReportFilter.MetaZ	employeesZdepartmentsZareas
start_dateend_dateN)rB   rC   rD   r   rE   rF   r$   r$   r$   r%   rG   b   s   rG   N)
rB   rC   rD   sixZPY3django_filtersZ
DateFilterrK   rL   rG   r$   r$   r$   r%   rI   Z   s   rI   c                   sV   e Zd ZeZej jdddZ	e
ZeedZ fddZdd Zd	d
 Z  ZS )MobileTransactionReportViewSetZApp)Zterminal_snz-punch_time)listZexportc                s   t t|  }| jjj}| jjjs6d|i}|jf |}| jjjs| jjj	}| jjj
}| jjj}| rv|j| d}| r|j| d }| r|j| d}tt|d}|dkr|ttdtd dB ttdB }|jtdd	}|S )
NZemp__department__company_id)Zemp__department__in)Zemp__area__in)Zemp__position__in
resign_emp0)Zemp__statusr,   )r*   )superrO   get_querysetr   r   r   Zis_employeer2   Zis_superuserZget_auth_deptZget_auth_areaZget_auth_posexistsallZdistinctstrr   r   r   r	   r
   Zannotater   )r"   querysetZ
company_idZbase_filterZ	auth_deptZ	auth_areaZauth_posrQ   )	__class__r$   r%   rT   r   s*    





 z+MobileTransactionReportViewSet.get_querysetc             C   s   | j | jtS )N)serializer_dictr   actionr   )r"   r$   r$   r%   get_serializer_class   s    z3MobileTransactionReportViewSet.get_serializer_classc             C   s   t d tdS )NZenzMobile Transaction Report)r   rH   )r"   r$   r$   r%   get_file_title   s    z-MobileTransactionReportViewSet.get_file_title)rB   rC   rD   r   rE   r1   rT   r2   Zorder_byrX   rI   Zfilter_classr   rZ   r\   r]   __classcell__r$   r$   )rY   r%   rO   g   s   rO   )$rM   rN   Zdjango.db.modelsr   Zdjango.db.models.functionsr   Zdjango.utils.translationr   rH   r   Zdjango_filters.rest_frameworkr   Zrest_frameworkr   r   Zmysite.admin.modelsr	   r
   Zmysite.att.api.serializersr   Zmysite.att.api.utils_classr   r   Zmysite.att.utilsr   r   Zmysite.iclock.modelsr   r   r   r   ZModelSerializerr   rI   ZListModelMixinrO   r$   r$   r$   r%   <module>   s    D