Commit 386b17ec authored by John Red Medrano's avatar John Red Medrano

Merge pull request #748 in RMS/api-main-service from core-dev-red-develop to RMSv2

* commit '1e780140':
  {dev bugfix} added validation on Application section set excel_code not blank, unique and required
parents ce8a8e0f 1e780140
......@@ -26,6 +26,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
search_fields = ('name', 'code')
@decorators.rms.ApplicationValidation
@decorators.rms.application_crate
@transaction.atomic
def create(self, request, *args, **kwargs):
......
......@@ -47,7 +47,7 @@ class rms:
enums_company = enums.UserTypeEnum.COMPANY_USER_ADMIN.value
enums_department = enums.UserTypeEnum.DEPARTMENT_USER_ADMIN.value
enums_user = enums.UserTypeEnum.USER.value
access_error = "Logged user is unauthorize to make another user"
access_error = "Logged user is unauthorize to access this section"
department_error = 'Department should be same with the logged user'
company_error = 'Company should be same with the logged user'
......@@ -97,6 +97,30 @@ class rms:
return wrapper
@staticmethod
def ApplicationValidation(function):
@wraps(function)
def wrapper(self, request, *args, **kwargs):
payload = request.data
if not 'excel_code' in payload:
return Response(
{"message": "Excel code is required"}
)
elif len(payload['excel_code'].strip()) == 0:
return Response(
{"message": "Excel code is may not be blank"}
)
is_excel_code_exist = self.queryset.filter(
excel_code=payload['excel_code']
)
if is_excel_code_exist:
return Response(
{"message": "This excel code is already exists"}
)
return function(self, request, *args, **kwargs)
return wrapper
@staticmethod
def AccountValidation(function):
@wraps(function)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment