o
    qvh                     @   sD   d dl 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 )	    )forms   )SaleSaleItemc                       *   e Zd ZG dd dZ fddZ  ZS )SaleFormc                   @   s   e Zd ZeZg dZdS )zSaleForm.Meta)customerpayment_method
cash_givencredit_amountmpesa_referencecheque_numbercheque_dateN)__name__
__module____qualname__r   modelfields r   r   '/var/www/html/hyperkenya/sales/forms.pyMeta       r   c                    s   t   }|d}|d}|d}|d}|d}|d}|dkr.|s.td|d	kr9|s9td
|dkrF|rA|sFtd|S )Nr	   r
   r   r   r   r   creditz.Credit amount is required for credit payments.mpesaz1M-Pesa reference is required for M-Pesa payments.chequez8Cheque number and date are required for cheque payments.)supercleangetr   ValidationError)selfcleaned_datar	   r
   r   r   r   r   	__class__r   r   r      s   









zSaleForm.cleanr   r   r   r   r   __classcell__r   r   r!   r   r      s    r   c                       r   )SaleItemFormc                   @   s   e Zd ZeZddgZdS )zSaleItemForm.MetabatchquantityN)r   r   r   r   r   r   r   r   r   r   r   #   r   r   c                    s>   t   }|d}|d}|r|r|j|k rtd|S )Nr&   r'   z'Not enough stock in the selected batch.)r   r   r   r'   r   r   )r   r    r&   r'   r!   r   r   r   '   s   




zSaleItemForm.cleanr#   r   r   r!   r   r%   "   s    r%   N)djangor   modelsr   r   	ModelFormr   r%   r   r   r   r   <module>   s    