3

\                 @   s   d dl mZ d dlmZ d dlmZ d dlmZm	Z	m
Z
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 d dlmZ eddZeddZeddZG dd dejZdS )    )render_to_string)mixins)Subscription) get_subscription_interval_optionget_next_order_dateget_surprise_optionget_brewing_method_optioncreate_next_order)subscription_created)	get_model)timezone)get_next_shipping_date)enqueue)
send_email)MANDRILL_TEMPLATESorderLineAttributeaddressUserAddress	catalogueOptionc                   s,   e Zd Z fddZdd Zdd Z  ZS )OrderPlacementMixinc       	         s6  | j j }|rtjj|d}ntjj| jjdj }x|j	j
 D ]}ttj d|_|j  |jjr@tjj|t dj }y|rdnd}W n tk
r   d}Y nX tjjt dj }tjj|j|jtj tjj|t dj j|jj|||r|jnd tj d	}|j  t| tj| |d	 q@W tt | j!|S )
N)pk)user   )lineoptionTF)r   )	r   product
last_orderintervalcurrencyshipping_addresssurprisebrewing_method
next_order)subscription)"checkout_sessionshipping_user_address_idr   objectsgetfilterrequestr   firstlinesallr   r   	localdateest_dispatch_datesaver   r%   r   r   AttributeErrorr   r   creater   valuestockrecordprice_currencyr	   r
   sendsuperr   handle_successful_order)	selfr   
address_idr   r   Zsurprise_intr"   r#   r%   )	__class__ //var/www/html/oscar2019/apps/checkout/mixins.pyr9      s>    

z+OrderPlacementMixin.handle_successful_orderc             C   s   t dd|idS )Nz0communication/partials/order_email_products.htmlr   )context)r   )r:   r   r=   r=   r>   _get_products_data?   s    z&OrderPlacementMixin._get_products_datac             K   s^   t tdtd |jjd|jjr$|jjndt|jj j	|j
d t|j | j|ddd d S )	NzYour order has been confirmed!ORDER_CONFIRMATIONz#Hook Coffee<hola@hookcoffee.com.sg>  r   )USERNAMESHIPPING_DATEPRICECOFFEESDISPLAY_REFERRAL_CODE)subjecttemplateto_email
from_email
merge_vars)r   r   r   r   email
first_namestrr-   r,   r0   r    total_incl_taxr@   )r:   r   codekwargsr=   r=   r>   send_confirmation_messageB   s    z-OrderPlacementMixin.send_confirmation_message)__name__
__module____qualname__r9   r@   rT   __classcell__r=   r=   )r<   r>   r      s   )r   N)django.template.loaderr   oscar.apps.checkoutr   baseZsubscription.modelsr   subscription.utilsr   r   r   r   r	   subscription.signalsr
   oscar.core.loadingr   django.utilsr   apps.shipping.utilsr   	django_rqr   communication.tasksr   communication.settingsr   r   r   r   r   r=   r=   r=   r>   <module>   s   


