new feature: customer panel accsess
This commit is contained in:
1 parent
5052bde49a
commit
e983e0cc43
12 files changed
+175
-4
No files matched your search
@@ -6,10 +6,62 @@ from apps.customer.models import (
|
||||
)
|
||||
from apps.reminder.models import Reminder as ReminderModel
|
||||
from apps.workspace.models import Workspace as WorkspaceModel
|
||||
from apps.cuser.models import CuserRole as CuserRoleModel
|
||||
from rest_framework import exceptions
|
||||
from utils.get_user_workspace import get_user_workspace, get_user_workspace_uuid
|
||||
from utils.get_cuser_role import get_cuser_role
|
||||
from django.db import transaction
|
||||
from django.contrib.auth import get_user_model
|
||||
import uuid
|
||||
import random
|
||||
|
||||
CUser = get_user_model()
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def customer_panel_access(request, mobile: int, customer_id: int, status: bool) -> CuserRoleModel:
|
||||
|
||||
try:
|
||||
workspace = get_user_workspace(request)
|
||||
customer = CustomerModel.objects.get(id=customer_id, sys_ws=workspace)
|
||||
|
||||
try:
|
||||
cuser_obj = CUser.objects.get(mobile=mobile)
|
||||
except CUser.DoesNotExist:
|
||||
cuser_obj = CUser.objects.create_user(
|
||||
username=uuid.uuid4(),
|
||||
mobile=mobile,
|
||||
name_family=customer.name_family,
|
||||
password=f"{random.randint(10000, 900000)}!@#{random.randint(10000, 9000000)}",
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
try:
|
||||
cuser_role_obj = CuserRoleModel.objects.get(cuser=cuser_obj, role_type_id=3)
|
||||
cuser_role_obj.customer_panel = status
|
||||
cuser_role_obj.save()
|
||||
except CuserRoleModel.DoesNotExist:
|
||||
cuser_role_obj = CuserRoleModel.objects.create(
|
||||
cuser=cuser_obj,
|
||||
role_type_id=3,
|
||||
name_family=customer.name_family,
|
||||
mobile=mobile,
|
||||
mobile_verify=True,
|
||||
is_active=True,
|
||||
customer_panel=status,
|
||||
sys_ws=workspace
|
||||
)
|
||||
|
||||
if cuser_role_obj:
|
||||
customer.cuser_role = cuser_role_obj
|
||||
customer.save()
|
||||
return cuser_role_obj
|
||||
else:
|
||||
raise Exception
|
||||
|
||||
except Exception as exp:
|
||||
message = f'Error Create or Update Customer panel accsess: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def create_responsible_group(name: str, workspace: WorkspaceModel):
|
||||
@@ -232,4 +284,5 @@ def customer_note_delete(request, customer_id: int, note_id: int) -> CustomerNot
|
||||
|
||||
except Exception as exp:
|
||||
message = f'Error Delete Customer Note: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
Reference in new issue
Block a user