saleor/dashboard/order/forms.py
def clean(self):
        """Check if given quantity is available in stocks."""
        cleaned_data = super().clean()
        variant = cleaned_data.get('variant')
        quantity = cleaned_data.get('quantity')
        if variant and quantity is not None:
            try:
                variant.check_quantity(quantity)
            except InsufficientStock as e:
                error = forms.ValidationError(
                    pgettext_lazy(
                        'Add item form error',
                        'Could not add item. '
                        'Only %(remaining)d remaining in stock.' %
                        {'remaining': e.item.quantity_available}))
                self.add_error('quantity', error)
        return cleaned_data
Check if given quantity is available in stocks.
Check if given quantity is available in stocks.
Check if given quantity is available in stocks .
def clean(self):
        cleaned_data = super().clean()
        variant = cleaned_data.get('variant')
        quantity = cleaned_data.get('quantity')
        if variant and quantity is not None:
            try:
                variant.check_quantity(quantity)
            except InsufficientStock as e:
                error = forms.ValidationError(
                    pgettext_lazy(
                        'Add item form error',
                        'Could not add item. '
                        'Only %(remaining)d remaining in stock.' %
                        {'remaining': e.item.quantity_available}))
                self.add_error('quantity', error)
        return cleaned_data
def clean ( self ) : cleaned_data = super ( ) . clean ( ) variant = cleaned_data . get ( 'variant' ) quantity = cleaned_data . get ( 'quantity' ) if variant and quantity is not None : try : variant . check_quantity ( quantity ) except InsufficientStock as e : error = forms . ValidationError ( pgettext_lazy ( 'Add item form error' , 'Could not add item. ' 'Only %(remaining)d remaining in stock.' % { 'remaining' : e . item . quantity_available } ) ) self . add_error ( 'quantity' , error ) return cleaned_data
Check if given quantity is available in stocks.
Check if given quantity is available in stocks .
"""Check if given quantity is available in stocks."""
self