3

\                 @   s   d dl T d dl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Zd d
lmZ G dd deZdd Zdd Zdd ZdS )    )*N)timezone)	timedeltadatetime)	get_model)	urlencode
quote_plus)Image)	ImageFont)	ImageDraw)global_preferences_registryc               @   s   e Zd ZdZdd ZdS )OrderNumberGeneratorz
    Simple object for generating order numbers.

    We need this as the order number is often required for payment
    which takes place before the order model has been created.
    c             C   s   dt |jj d t |j S )z;
        Return an order number for a given basket
        Z10000)strownerpkid)selfbasket r   +/var/www/html/oscar2019/apps/order/utils.pyorder_number   s    z!OrderNumberGenerator.order_numberN)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   c             C   s   d}dj | j}y| jjj j }W n   d}Y nX dj |||d}d| }t|}dj |d}tjd	tj	j
d
d	d}|j| |jdd |jdddS )z+Create and return a drawing with a QR code.zhttps://hookcoffee.com.sgz/qr_social/@{}/ z{host}{referral}{social})hostreferralsocialzHello! I recently tried this coffee subscription service, and have fallen in love with with it. You can try your first bag of coffee at 50% off if you sign up using my unique link - zwhatsapp://send?text={message})message      )versionZerror_correctionZbox_sizeborderT)fitblackwhite)Z
fill_colorZ
back_color)formatnumberuser	referrersfirstget_absolute_urlr   qrcodeZQRCode	constantsZERROR_CORRECT_Ladd_datamakeZ
make_image)orderr   r   r   linkr    valueZqrr   r   r   
_create_qr    s*    

r5   c       
      C   s   d\}}t jtd d}tjd||fd}tj|}dj| jj	j
| jj | jj j
}|j||d\}}|j|| d	 || d	 f|d
d|d tj }	|j|	d |	j S )N  X  AMATIC_BOLDZ   RGB   z{}
{}
{})font   centerr&   )alignfillr<   jpeg)r6   r7   )r;   r;   r;   )r
   truetypeIMAGE_FONTSr	   newr   Drawr(   r2   shipping_addressnameproduct	get_titleget_product_classmultiline_textsizemultiline_textioBytesIOsavegetvalue)
lineWHr<   imagedrawtextwh	img_bytesr   r   r   #generate_common_product_label_image;   s    
(rZ   c             C   s  t j }| j}| jjjj}| jjddj }d }| jj	 j
dkrT| jjdkrT| jj}d}| jjj}dj|}|d }	|	stj tdd	 }	tj|	d
jd}	|dkrtjjtjt|jj}
n6tjjtjt|jj}
|dkr|dkrt|jnd}t j!|
}t"j#|}t$j%t&d d}|j't(d |d|d |j't(d |d|d |j't(d |	d|d |r~|j't(d t|d d|d t)| j}|j*|t(d  t+j, }|j-|d |j. S ) Nzbrewing-method)Zoption__codez
coffee-bag   r   z{:^35}Zcoffee__roasted_dater"   )daysz%d %b %Y0z	Drip BagsZGroundNoneZDripDROIDSANSFALLBACK   rG   r   )r<   
ground_for
roasted_onweightgbarcoderA   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )/r   managerrH   attr	packagingoption
attributesfilterr,   rJ   slugshipping_weightr2   r*   
first_namer(   r   	localdater   r   strftimelstripospathjoinsettings
MEDIA_ROOTr   parent
label_driplabelr4   r	   openr   rE   r
   rB   rC   rV   ELEMENT_POSITION_IMAGEr5   pasterM   rN   rO   rP   )rQ   Zglobal_preferencesZcoffeepackageZbrewrc   ra   	recipientrG   rb   Ztemplate_srcrT   rU   r<   Zqr_coderY   r   r   r   generate_product_label_imageU   s@    




r   )hookcoffee.pdf_settingsrM   django.utilsr   r   r   oscar.core.loadingr   urllib.parser   r   PILr	   r
   r   r.   Zdynamic_preferences.registriesr   objectr   r5   rZ   r   r   r   r   r   <module>   s   