3

‘ã\ä  ã               @   sP   d dl mZ G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZd
S )é    )Úgettext_lazyc               @   s<   e Zd ZdZdZdZdZedd„ ƒZedd„ ƒZ	dd	„ Z
dS )
ÚBasez#
    Base availability policy.
    Ú Nc             C   s   | j S )zp
        A shorter version of the availability message, suitable for showing on
        browsing pages.
        )Úmessage)Úself© r   ú:/var/www/html/oscar2019/oscar/apps/partner/availability.pyÚshort_message   s    zBase.short_messagec             C   s   | j dƒd S )z’
        Test if this product is available to be bought.  This is used for
        validation when a product is added to a user's basket.
        é   r   )Úis_purchase_permitted)r   r   r   r   Úis_available_to_buy   s    zBase.is_available_to_buyc             C   s   dt dƒfS )zk
        Test whether a proposed purchase is allowed

        Should return a boolean and a reason
        FÚunavailable)Ú_)r   Úquantityr   r   r   r   $   s    zBase.is_purchase_permitted)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úcoder   Zdispatch_dateÚpropertyr	   r   r   r   r   r   r   r      s   	r   c               @   s   e Zd ZdZdZed ƒZdS )ÚUnavailablez2
    Policy for when a product is unavailable
    r   N)r   r   r   r   r   r   r   r   r   r   r   r   0   s   r   c               @   s$   e Zd ZdZdZed ƒZdd„ ZdS )Ú	AvailablezÙ
    For when a product is always available, irrespective of stock level.

    This might be appropriate for digital products where stock doesn't need to
    be tracked and the product is always available to buy.
    Ú	availablec             C   s   dS )NTr   )Tr   r   )r   r   r   r   r   r   B   s    zAvailable.is_purchase_permittedN)r   r   r   r   r   r   r   r   r   r   r   r   r   8   s   r   c               @   sL   e Zd ZdZdZdZdd„ Zdd„ Zedd	„ ƒZ	ed
d„ ƒZ
edd„ ƒZdS )ÚStockRequiredan  
    Allow a product to be bought while there is stock.  This policy is
    instantiated with a stock number (``num_available``).  It ensures that the
    product is only available to buy while there is stock available.

    This is suitable for physical products where back orders (eg allowing
    purchases when there isn't stock available) are not permitted.
    ZinstockZ
outofstockc             C   s
   || _ d S )N)Únum_available)r   r   r   r   r   Ú__init__R   s    zStockRequired.__init__c             C   s>   | j dkrdtdƒfS || j kr:tdƒd| j i }d|fS dS )	Nr   Fzno stock availablez"a maximum of %(max)d can be boughtÚmaxTr   )Tr   )r   r   )r   r   Úmsgr   r   r   r   U   s    

z#StockRequired.is_purchase_permittedc             C   s   | j dkr| jS | jS )Nr   )r   ÚCODE_IN_STOCKÚCODE_OUT_OF_STOCK)r   r   r   r   r   ^   s    
zStockRequired.codec             C   s   | j dkrtdƒS tdƒS )Nr   zIn stockr   )r   r   )r   r   r   r   r	   d   s    
zStockRequired.short_messagec             C   s    | j dkrtdƒ| j  S tdƒS )Nr   zIn stock (%d available)r   )r   r   )r   r   r   r   r   j   s    
zStockRequired.messageN)r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   F   s   	r   N)Údjango.utils.translationr   r   Úobjectr   r   r   r   r   r   r   r   Ú<module>   s   ,