from rest_framework import status from rest_framework.exceptions import APIException class QuotaException(APIException): """ if quota is not available """ status_code = status.HTTP_400_BAD_REQUEST default_detail = "خطا در اطلاعات سهمیه" # noqa default_code = 'error' def __init__(self, message=None, status_code=None, code=None): if status_code is not None: self.status_code = status_code detail = { "message": message, "status_code": status_code } super().__init__(detail) class DistributionException(APIException): """ if distribution is not available """ status_code = status.HTTP_400_BAD_REQUEST default_detail = "خطا در اطلاعات توزیع." # noqa default_code = 'error' def __init__(self, message=None, status_code=None, code=None): if status_code is not None: self.status_code = status_code detail = { "message": message, "status_code": status_code } super().__init__(detail) class QuotaWeightException(APIException): """ if quota distributions weight is more """ status_code = status.HTTP_400_BAD_REQUEST default_detail = "مقدار وارد شده باعث می‌شود مجموع سهمیه‌ها از مقدار کل سهمیه بیشتر شود." # noqa default_code = 'error' class DistributionWeightException(APIException): """ if sale transaction weight is more than distribution weight """ status_code = status.HTTP_400_BAD_REQUEST default_detail = 'مقدار وزن وارد شده بیشتر از وزن سهمیه توزیع شده میباشد.' # noqa default_code = 'error' class DistributionDeletedException(APIException): """ if distribution is deleted """ status_code = status.HTTP_400_BAD_REQUEST default_detail = "امکان حذف این توزیع وجود ندارد. ورود به انبار یا توزیعی برای آن ثبت شده است" # noqa default_code = 'error' class QuotaClosedException(APIException): """ if quota is closed, operations can not be done """ status_code = status.HTTP_400_BAD_REQUEST default_detail = "این سهمیه بسته شده است و قابل توزیع نیست" # noqa default_code = 'error' class QuotaExpiredTimeException(APIException): """if quota allowed time for distribute, sale, etc. is expired""" status_code = status.HTTP_400_BAD_REQUEST default_detail = "این سهمیه دارای محدودیت توزیع میباشد" # noqa default_code = 'error' class QuotaSaleTimeException(APIException): """if quota allowed time for distribute, sale, etc. is expired""" status_code = status.HTTP_400_BAD_REQUEST default_detail = "اين سهمیه دارای محدودیت مجوز فروش میباشد" # noqa default_code = 'error' class QuotaLimitByOrganizationException(APIException): """ if limitation of quota by organization is true, distribution should be done in organizations limits """ status_code = status.HTTP_400_BAD_REQUEST default_detail = "سازمان انتخاب شده در بین سامان های انتخاب شده برای توزیع سهمیه وجود ندارد" # noqa default_code = 'error' class FreePOSProductUniqueCheck(APIException): """ raise exception for free pos products to be unique """ status_code = status.HTTP_403_FORBIDDEN default_detail = "محصول مورد نظر برای این دستگاه از قبل ثبت شده است" # noqa default_code = 'error' class RancherIncentivePlanExists(APIException): """ raise exception if rancher with same info """ status_code = status.HTTP_403_FORBIDDEN default_detail = "این دامدار برای این طرح با این نوع گونه دام قبلا اضافه شده است" # noqa default_code = 'error'