B
    CDb                 @   sx   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 G dd dejZG d	d
 d
ejZdS )    )serializers)Company)FeatureSerializer)Employee)TransactionTerminal)STATUS_VALIDSTATUS_RESIGN_PENDINGc               @   s   e Zd Ze Ze Ze Ze Ze Z	ej
ddZej
ddZe Z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 )CompanySerializerz%Y-%m-%d)formatc             C   s   t jj|ttfd }|S )N)companyZ
status__in)r   objectsfilterr   r	   count)selfinstancecurrent_employees_count r   IG:\easytimepro\master/mysite/cloud\api\serializers\company_serializers.pyget_current_employees_count   s    z-CompanySerializer.get_current_employees_countc             C   s   t jj|d }|S )N)r   )r   r   r   r   )r   r   current_devices_countr   r   r   get_current_devices_count   s    z+CompanySerializer.get_current_devices_countc             C   s   t jj|d }|S )N)r   )r   r   r   r   )r   r   current_transactions_countr   r   r   get_current_transactions_count   s    z0CompanySerializer.get_current_transactions_countc             C   s   t jjd|d }|S )N   )Z
app_statusr   )r   r   r   r   )r   r   !current_mobile_applications_countr   r   r   %get_current_mobile_applications_count$   s    z7CompanySerializer.get_current_mobile_applications_countc             C   s   t jjd|d }|S )Nr   )Zenable_whatsappr   )r   r   r   r   )r   r   current_whatsapp_push_countr   r   r   get_current_whatsapp_push_count)   s    z1CompanySerializer.get_current_whatsapp_push_countc             C   s   |j  }dd |D }|S )Nc             S   s   g | ]
}|j qS r   )name).0fr   r   r   
<listcomp>0   s    z6CompanySerializer.get_feature_name.<locals>.<listcomp>)featureall)r   r   r#   Zfeature_name_listr   r   r   get_feature_name.   s    
z"CompanySerializer.get_feature_namec               @   s2   e Zd ZeZddddddddd	d
dddddgZdS )zCompanySerializer.Metaidr   feature_namesubscription_start_datesubscription_end_dater   max_employees_limitr   max_devices_limitr   max_transactions_limitr   max_mobile_applications_limitr   max_whatsapp_push_limitN)__name__
__module____qualname__r   modelfieldsr   r   r   r   Meta4   s   
r4   N)r/   r0   r1   r   ZSerializerMethodFieldr   r   r   r   r   ZDateTimeFieldr(   r)   r'   r   r   r   r   r   r%   r4   r   r   r   r   r
   
   s   r
   c               @   s^   e Z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
G dd dZdS )CompanyEditSerializerr   )Z	min_valuec             C   s8   || j jkr4|d| j jdk r4tddgi|S )Nz%Y-%m-%dr)   zJThe subscription end date cannot be less than the subscription start date.)r   r)   strftimer(   r   ZValidationError)r   r)   r   r   r   validate_subscription_end_dateG   s
    
z4CompanyEditSerializer.validate_subscription_end_datec            
   @   s0   e Zd ZeZddddddddd	d
g
ZddgZdS )zCompanyEditSerializer.Metar&   r   r#   r(   r)   r*   r+   r,   r-   r.   N)r/   r0   r1   r   r2   r3   Zread_only_fieldsr   r   r   r   r4   O   s
   
r4   N)r/   r0   r1   r   ZIntegerFieldr*   r+   r,   r-   r.   r7   r4   r   r   r   r   r5   @   s   r5   N)Zrest_frameworkr   Zmysite.cloud.modelsr   Zmysite.cloud.api.serializersr   Zmysite.personnel.modelsr   Zmysite.iclock.modelsr   r   Zmysite.admin.modelsr   r	   ZModelSerializerr
   r5   r   r   r   r   <module>   s   6