151 lines
5.4 KiB
Python
151 lines
5.4 KiB
Python
from apps.customer.models import ResponsibleGroup as ResponsibleGroupModel, CustomerResponsible as CustomerResponsibleModel
|
|
from apps.customer.models import ShiveAshenaei as ShiveAshenaeiModel
|
|
from apps.workspace.models import City as CityModel
|
|
from apps.customer.models import Customer as CustomerModel
|
|
from rest_framework import exceptions
|
|
from utils.get_user_workspace import get_user_workspace_uuid
|
|
from utils.get_cuser_role import get_cuser_role_uuid
|
|
from apps.lead.models import Lead as LeadModel
|
|
from apps.customer.models import CustomerNote as CustomerNoteModel
|
|
from apps.reminder.models import Reminder as ReminderModel
|
|
|
|
|
|
|
|
def retrieve_responsible_group(responsible_group_id: int, workspace_uuid: str):
|
|
try:
|
|
responsible_group_obj = ResponsibleGroupModel.objects.get(id=responsible_group_id, sys_ws__uuid=workspace_uuid)
|
|
return responsible_group_obj
|
|
except Exception as exp:
|
|
message = f'Error Retrieve ResponsibleGroup: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def list_responsible_group(workspace_uuid: str) -> ResponsibleGroupModel:
|
|
try:
|
|
responsible_group_objs = ResponsibleGroupModel.objects.filter(sys_ws__uuid=workspace_uuid)
|
|
return responsible_group_objs
|
|
except Exception as exp:
|
|
message = f'Error Fetch ResponsibleGroup List: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def retrieve_shive_ashenaei(shive_id: int, workspace_uuid: str):
|
|
try:
|
|
responsible_group_obj = ShiveAshenaeiModel.objects.get(id=shive_id, sys_ws__uuid=workspace_uuid)
|
|
return responsible_group_obj
|
|
except Exception as exp:
|
|
message = f'Error Retrieve ShiveAshenaei: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def list_shive_ashenaei(workspace_uuid: str) -> ResponsibleGroupModel:
|
|
try:
|
|
shive_ashenaei_objs = ShiveAshenaeiModel.objects.filter(sys_ws__uuid=workspace_uuid)
|
|
return shive_ashenaei_objs
|
|
except Exception as exp:
|
|
message = f'Error Fetch ShiveAshenaei List: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def retrieve_customer(customer_id: int, workspace_uuid: str):
|
|
try:
|
|
customer_obj = CustomerModel.objects.get(id=customer_id, sys_ws__uuid=workspace_uuid)
|
|
return customer_obj
|
|
except Exception as exp:
|
|
message = f'Error Retrieve Customer: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def list_customer(workspace_uuid: str, name_family: str = None, mobile: int = None):
|
|
try:
|
|
customer_objs = CustomerModel.objects.filter(sys_ws__uuid=workspace_uuid)
|
|
|
|
if name_family is not None:
|
|
customer_objs = customer_objs.filter(name_family__contains=name_family)
|
|
if mobile is not None:
|
|
customer_objs = customer_objs.filter(mobile__=mobile)
|
|
|
|
return customer_objs[:3]
|
|
except Exception as exp:
|
|
message = f'Error Fetch Customer List: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def list_customer_v2(request):
|
|
try:
|
|
|
|
user_workspace_uuid = get_user_workspace_uuid(request=request)
|
|
user_cuser_role_uuid = get_cuser_role_uuid(request=request)
|
|
|
|
customer_responsible = CustomerResponsibleModel.objects.filter(cuser_role__uuid=user_cuser_role_uuid)
|
|
|
|
customer_objs = CustomerModel.objects.filter(sys_ws__uuid=user_workspace_uuid,
|
|
responsible_group__customer_responsible__in=customer_responsible)
|
|
|
|
return customer_objs
|
|
except Exception as exp:
|
|
message = f'Error Fetch Customer List: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def customer_form_item(request):
|
|
|
|
workspace_uuid = get_user_workspace_uuid(request)
|
|
|
|
shive_ashenaei = ShiveAshenaeiModel.objects.filter(sys_ws__uuid=workspace_uuid)
|
|
shahr = CityModel.objects.filter()
|
|
responsible_groups = ResponsibleGroupModel.objects.filter(sys_ws__uuid=workspace_uuid)
|
|
|
|
data = {
|
|
'shive_ashenaei': shive_ashenaei,
|
|
'shahr': shahr,
|
|
'responsible_groups': responsible_groups
|
|
}
|
|
|
|
return data
|
|
|
|
|
|
def customer_summery(request, customer_id:int):
|
|
|
|
workspace_uuid = get_user_workspace_uuid(request)
|
|
cuser_role_uuid = get_cuser_role_uuid(request)
|
|
|
|
customer_notes = CustomerNoteModel.objects.filter(customer_id=customer_id, sys_ws__uuid=workspace_uuid)[:4]
|
|
customer_leads = LeadModel.objects.filter(customer_id=customer_id, sys_ws__uuid=workspace_uuid)[:4]
|
|
|
|
data = {
|
|
'customer_notes': customer_notes,
|
|
'customer_leads': customer_leads,
|
|
}
|
|
|
|
return data
|
|
|
|
|
|
def customer_note_list(request, customer_id: int) -> CustomerNoteModel:
|
|
|
|
workspace_uuid = get_user_workspace_uuid(request)
|
|
|
|
customer_notes = CustomerNoteModel.objects.filter(customer_id=customer_id, sys_ws__uuid=workspace_uuid)[:20]
|
|
|
|
return customer_notes
|
|
|
|
|
|
def customer_note_retrieve(request, customer_id: int, note_id: int) -> CustomerNoteModel:
|
|
|
|
workspace_uuid = get_user_workspace_uuid(request)
|
|
|
|
customer_note = CustomerNoteModel.objects.get(id=note_id, customer_id=customer_id, sys_ws__uuid=workspace_uuid)
|
|
customer_note_reminder = None
|
|
try:
|
|
customer_note_reminder = ReminderModel.objects.get(type='NO', id_type=note_id, customer_id=customer_id, sys_ws__uuid=workspace_uuid)
|
|
except Exception as exp:
|
|
pass
|
|
|
|
output = {
|
|
'customer_note': customer_note,
|
|
'customer_note_reminder': customer_note_reminder
|
|
}
|
|
return output
|
|
|
|
|