o
    'jN                     @   s  d dl mZ ddlmZmZmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZ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$G d&d' d'ejZ%d(S ))    )serializers   )
AdditionalDetailsCustomOrderTrackingOrderProductCustomizationOrdersOrderProductsAdsDiscountCouponsOrderDeliverySomeOneElse)reverse)ProductImageProductsCustomProductImage)CustomProductSerializerc                   @      e Zd ZG dd dZdS )SomeOneElseDataSerializerc                   @   s   e Zd ZeZddgZdS )zSomeOneElseDataSerializer.Metanamephone_numberN)__name__
__module____qualname__r   modelfields r   r   F/var/www/html/collabkart/collabkart.saasvaap.com/orders/serializers.pyMeta
       r   Nr   r   r   r   r   r   r   r   r   	       r   c                   @   r   )#OrderProductCustomizationSerializerc                   @      e Zd ZeZg dZdS z(OrderProductCustomizationSerializer.Meta)idcustom_notecustom_imageNr   r   r   r   r   r   r   r   r   r   r      r   r   Nr    r   r   r   r   r"      r!   r"   c                   @   sV   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	dddZ
G dd	 d	Zd
S )OrderProductSerializerzsku.sku_namesourcezsku.sku_quantityzsku.sku_unitz!sku.product.veg_or_non_veg_statusTmany	read_onlyc                   @   r#   )zOrderProductSerializer.Meta)skuquantitypricesku_nameveg_or_non_vegsku_quantitysku_unitcustomizationsN)r   r   r   r   r   r   r   r   r   r   r      r   r   N)r   r   r   r   	CharFieldr2   r4   r5   r3   r"   r6   r   r   r   r   r   r)      s    r)   c                       sd   e Zd ZedddZejddZejddZejddZ	e
ddZG dd	 d	Z fd
dZ  ZS )PickUpOrderSerializerTr,   store_uuid.unit_namer*   store_uuid.unit_locationstore_uuid.contact_nor.   c                   @   r#   )zPickUpOrderSerializer.Meta)uuidorder_ID
order_typeorder_status	sub_totaltaxes_and_chargesdelivery_chargesgrand_total
order_datacreated_date	shop_nameshop_locationshop_contactdelivery_slot_datedelivery_slot_timesome_one_else_orderNr   r   r   r   r   r   r   r   r   r   r   5   r   r   c                    &   t  |}|dd u ri |d< |S NrL   superto_representationgetselfinstancerepresentation	__class__r   r   rR   I      z'PickUpOrderSerializer.to_representation)r   r   r   r)   rE   r   r7   rG   rH   rI   r   rL   r   rR   __classcell__r   r   rX   r   r8   /   s    
r8   c                       s   e Zd ZedddZejddZejddZejddZ	ejdddd	Z
ejd
ddd	Zejdddd	Zejdddd	ZeddZe Ze ZG dd dZdd Zdd Z fddZ  ZS )OrderSerializerTr,   r9   r*   r:   r;   drop_address.address_typeFr+   
allow_nullrequired!drop_address.house_number_or_namedrop_address.land_markpayment_mode.mode_namer<   c                   @   r#   )zOrderSerializer.Meta)r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   address_typepayment_mode	address_1	address_2rL   discountadditional_infomobile_numberNrM   r   r   r   r   r   d   r   r   c                 C   :   zt jj|d }|r|jW S dW S  ty   Y dS w N)order r   objectsfilterfirstri   	ExceptionrU   objdetailsr   r   r   get_additional_info      z#OrderSerializer.get_additional_infoc                 C   rk   rl   r   rp   rq   rr   rj   rs   rt   r   r   r   get_mobile_number   rx   z!OrderSerializer.get_mobile_numberc                    rN   rO   rP   rT   rX   r   r   rR      s   z!OrderSerializer.to_representation)r   r   r   r)   rE   r   r7   rG   rH   rI   rd   rf   rg   re   r   rL   SerializerMethodFieldri   rj   r   rw   rz   rR   r[   r   r   rX   r   r\   R   s     
r\   c                   @   r   )CourierDetailsSerializerc                   @   r#   )zCourierDetailsSerializer.Meta)courier_service_namepackage_numberexpected_date_of_deliverytracking_linkN)r   r   r   r   r   r   r   r   r   r   r      r   r   Nr    r   r   r   r   r|      r!   r|   c                       s   e Zd ZedddZejddZejddZejddZ	ejdddd	Z
ejd
ddd	Zejdddd	Zejdddd	Ze Ze ZeddZG dd dZdd Zdd Z fddZ  ZS )OrderSerializer2Tr,   zpu_uuid.pu_namer*   zpu_uuid.pu_locationzpu_uuid.contact_nor]   Fr^   ra   rb   rc   r<   c                   @   r#   )zOrderSerializer2.Meta)r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   pu_namepu_location
pu_contactrJ   rK   rd   re   rf   rg   rL   rh   ri   rj   NrM   r   r   r   r   r      r   r   c                 C   rk   rl   ro   rt   r   r   r   rw      rx   z$OrderSerializer2.get_additional_infoc                 C   rk   rl   ry   rt   r   r   r   rz      rx   z"OrderSerializer2.get_mobile_numberc                    rN   rO   rP   rT   rX   r   r   rR      rZ   z"OrderSerializer2.to_representation)r   r   r   r)   rE   r   r7   r   r   r   rd   rf   rg   re   r{   ri   rj   r   rL   r   rw   rz   rR   r[   r   r   rX   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ddZejd	dddZ	ejd
dddZ
ejddddZeddZeddZG dd dZ fddZ  ZS )CustomOrderCreateSerializerr9   r*   r:   r;   r]   TFr^   ra   rb   rc   r<   c                   @   r#   )z CustomOrderCreateSerializer.Meta)r=   r>   r?   r@   rA   rB   rC   rD   rF   rG   rH   rI   rJ   rK   rd   rf   rg   custom_productdescriptionmessagerL   re   NrM   r   r   r   r   r      r   r   c                    rN   rO   rP   rT   rX   r   r   rR     rZ   z-CustomOrderCreateSerializer.to_representation)r   r   r   r   r7   rG   rH   rI   rd   rf   rg   re   r   r   r   rL   r   rR   r[   r   r   rX   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ddZejd	dddZ	ejd
dddZ
eddZeddZejddddZe Ze Ze 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d Zdd Zdd Zdd Z  fdd Z!  Z"S )!CustomOrderSerializerr9   r*   r:   r;   r]   TFr^   ra   rb   r<   rc   c                   @   r#   )zCustomOrderSerializer.Meta)r=   r>   r?   r@   rA   rB   rC   rD   rh   rF   rG   rH   rI   rJ   rK   rd   rf   rg   r   r   r   rL   r'   r0   quantity_unitdelivery_typelatitude	longitudere   	is_editedNrM   r   r   r   r   r   9  r   r   c                 C   sH   t | ds!ztjj|d| _W | jS  tjy    d | _Y | jS w | jS )N_tracking_cache)order_id)hasattrr   rp   rS   r   DoesNotExistrU   ru   r   r   r   get_tracking]  s   
z"CustomOrderSerializer.get_trackingc                 C   s,   |  |}|r|jr| jd |jjS d S )Nrequest)r   r'   contextbuild_absolute_uriurlrU   ru   trackingr   r   r   get_custom_imagee  s   

z&CustomOrderSerializer.get_custom_imagec                 C      |  |}|r
|jS d S N)r   r0   r   r   r   r   get_quantityk     
z"CustomOrderSerializer.get_quantityc                 C   r   r   )r   r   r   r   r   r   get_quantity_unito  r   z'CustomOrderSerializer.get_quantity_unitc                 C   r   r   )r   r   r   r   r   r   get_delivery_types  r   z'CustomOrderSerializer.get_delivery_typec                 C   *   |  |}|r|jdkr|jr|jjS d S NzPick Up)r   r   drop_addressr   r   r   r   r   get_latitudew     
z"CustomOrderSerializer.get_latitudec                 C   r   r   )r   r   r   r   r   r   r   r   get_longitude}  r   z#CustomOrderSerializer.get_longitudec                 C   s   | j ddS )Nr   F)r   rS   r   r   r   r   get_is_edited  s   z#CustomOrderSerializer.get_is_editedc                    rN   rO   rP   rT   rX   r   r   rR     rZ   z'CustomOrderSerializer.to_representation)#r   r   r   r   r7   rG   rH   rI   rd   rf   rg   r   r   r   rL   re   r{   r'   r0   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   r[   r   r   rX   r   r     s6    

$r   c                   @   r   )r"   c                   @   r#   r$   r(   r   r   r   r   r     r   r   Nr    r   r   r   r   r"     r!   c                       s   e Zd Ze Ze ZejdddZ	e
 Ze Ze Ze Ze ZejddddZG dd dZdd	 Zd
d Z fddZ  ZS )PastOrderListSerializerFT)r`   r_   r]   r^   c                   @   r#   )zPastOrderListSerializer.Meta)r=   r>   rJ   rK   rD   r@   r?   product_namesproduct_imagerd   r   NrM   r   r   r   r   r     r   r   c                 C   s(   |j dkr
|jjgS dd |j D S )NCustom Ordersc                 S   s   g | ]}|j qS r   )product_name).0order_productr   r   r   
<listcomp>  s    z=PastOrderListSerializer.get_product_names.<locals>.<listcomp>)r?   r   	item_namerE   allr   r   r   r   get_product_names  s   

z)PastOrderListSerializer.get_product_namesc                 C   sv   |j dkrtjj|jd }|r|jjS |j	 D ]}|j
s q|j
j}|s'qtjj|d }|r8|jj  S qd S )Nr   )r   )product)r?   r   rp   rq   r   rr   imager   rE   r   r/   r   r   )rU   ru   product_image_customr   r   r   r   r   r   get_product_image  s.   
z)PastOrderListSerializer.get_product_imagec                    s"   t  |}|dsd|d< |S )NrK   zNot ProvidedrP   )rU   rV   datarX   r   r   rR     s   
z)PastOrderListSerializer.to_representation)r   r   r   r   r7   r>   	DateFieldrJ   	TimeFieldrK   
FloatFieldrD   r@   r?   r{   r   r   rd   r   r   r   rR   r[   r   r   rX   r   r     s    r   c                   @   r   )ProductSerializerc                   @   r#   )zProductSerializer.Meta)r%   r   	item_codeN)r   r   r   r   r   r   r   r   r   r   r     r   r   Nr    r   r   r   r   r     r!   r   c                   @   r   )CouponSerializerc                   @   r#   )zCouponSerializer.Meta)r%   
CouponName
CouponCodeN)r   r   r   r   r   r   r   r   r   r   r   "  r   r   Nr    r   r   r   r   r   !  r!   r   c                   @   r   )DiscountSerializerc                   @   r#   )zDiscountSerializer.Meta)r%   DiscountNameDiscountCodeNr   r   r   r
   r   r   r   r   r   r   r   '  r   r   Nr    r   r   r   r   r   &  r!   r   c                   @   sT   e Zd ZejdddZejdddZeddZe	ddZ
eddZG dd dZdS )	AdSerializerStandardImageF)r+   r`   BannerImage)r`   c                   @   r#   )zAdSerializer.Meta)	AdTitleAdDescriptionAdPlacementAdType	web_imagemobile_imager
   CouponProductN)r   r   r   r	   r   r   r   r   r   r   r   5  r   r   N)r   r   r   r   
ImageFieldr   r   r   r
   r   r   r   r   r   r   r   r   r   r   -  s    


r   c                   @   r   )DiscountDetailSerializerc                   @   r#   )zDiscountDetailSerializer.Meta)r%   r   r   DiscountDescription
DiscountOnApplicableCategoryApplicableSubCategoryApplicableProductApplicableSkuDiscountPercentager   r   Nr   r   r   r   r   r   D  r   r   Nr    r   r   r   r   r   C  r!   r   c                   @   r   )OrderBillDetailsSerializerc                   @   r#   )zOrderBillDetailsSerializer.Meta)rA   rB   rC   rD   total_savingscoupon_savingsrh   NrM   r   r   r   r   r   J  r   r   Nr    r   r   r   r   r   I  r!   r   N)&rest_frameworkr   modelsr   r   r   r   r   r	   r
   r   r   r   django.urlsr   products.modelsr   r   r   products.serializersr   ModelSerializerr   r"   r)   r8   r\   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s,    0#FP1wAE