first
This commit is contained in:
commit
89a5d70512
284 files changed
+8364
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,46 @@
|
||||
from django.contrib import admin
|
||||
from apps.customer.models import (
|
||||
Customer as CustomerModel,
|
||||
CustomerNote as CustomerNoteModel,
|
||||
ShiveAshenaei as ShiveAshenaeiModel,
|
||||
ResponsibleGroup as ResponsibleGroupModel,
|
||||
CustomerResponsible as CustomerResponsibleModel,
|
||||
CustomerGroupType as CustomerGroupTypeModel,
|
||||
CustomerGroup as CustomerGroupModel,
|
||||
)
|
||||
# Register your models here.
|
||||
|
||||
|
||||
@admin.register(CustomerModel)
|
||||
class CustomerAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(CustomerNoteModel)
|
||||
class CustomerNoteAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(ShiveAshenaeiModel)
|
||||
class ShiveAshenaeiAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(ResponsibleGroupModel)
|
||||
class ResponsibleGroupAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(CustomerResponsibleModel)
|
||||
class CustomerResponsibleAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(CustomerGroupTypeModel)
|
||||
class CustomerGroupTypeAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(CustomerGroupModel)
|
||||
class CustomerGroupAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CustomerConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.customer'
|
||||
@@ -0,0 +1,104 @@
|
||||
# Generated by Django 4.2.1 on 2023-08-08 08:37
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('workspace', '0002_city'),
|
||||
('cuser', '0002_roletype_cuserrole'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ShiveAshenaei',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(max_length=15)),
|
||||
('sys_ws', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workspace.workspace')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ResponsibleGroup',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(max_length=15)),
|
||||
('sys_ws', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workspace.workspace')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CustomerResponsible',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cuser_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cuser.cuserrole')),
|
||||
('responsible_group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='customer.responsiblegroup')),
|
||||
('sys_ws', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workspace.workspace')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CustomerGroupType',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(max_length=10)),
|
||||
('sys_ws', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workspace.workspace')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CustomerGroup',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(max_length=15)),
|
||||
('group_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='customer.customergrouptype')),
|
||||
('sys_ws', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workspace.workspace')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Customer',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name_family', models.CharField(max_length=25)),
|
||||
('mobile', models.PositiveBigIntegerField(blank=True, null=True)),
|
||||
('phone', models.PositiveBigIntegerField(blank=True, null=True)),
|
||||
('address', models.CharField(max_length=100)),
|
||||
('city', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='workspace.city')),
|
||||
('cuser_role', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cuser.cuserrole')),
|
||||
('responsible_group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='customer.responsiblegroup')),
|
||||
('shive_ashenaei', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='customer.shiveashenaei')),
|
||||
('sys_ws', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workspace.workspace')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.1 on 2023-08-13 05:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('customer', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='responsiblegroup',
|
||||
name='name',
|
||||
field=models.CharField(max_length=20),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.1 on 2023-08-19 12:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('customer', '0002_alter_responsiblegroup_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customer',
|
||||
name='address',
|
||||
field=models.CharField(blank=True, max_length=100, null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.1 on 2024-01-09 10:05
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('customer', '0003_alter_customer_address'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customerresponsible',
|
||||
name='responsible_group',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='customer_responsible', to='customer.responsiblegroup'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,35 @@
|
||||
# Generated by Django 4.2.1 on 2024-01-10 12:08
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0005_smsopt'),
|
||||
('workspace', '0003_alter_workspace_uuid'),
|
||||
('customer', '0004_alter_customerresponsible_responsible_group'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='customer',
|
||||
options={'ordering': ['-created_at']},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CustomerNote',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('desc', models.CharField(max_length=200)),
|
||||
('cuser_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cuser.cuserrole')),
|
||||
('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='customer.customer')),
|
||||
('sys_ws', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workspace.workspace')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.2.1 on 2024-01-13 10:29
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('customer', '0005_alter_customer_options_customernote'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='customernote',
|
||||
options={'ordering': ['-created_at']},
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,83 @@
|
||||
from django.db import models
|
||||
from utils.base_model import BaseModel
|
||||
from apps.workspace.models import City as CityModel, Workspace as WorkspaceModel
|
||||
from apps.cuser.models import CuserRole as CuserRoleModel
|
||||
from django.core.exceptions import ValidationError
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class ShiveAshenaei(BaseModel):
|
||||
name = models.CharField(max_length=15, null=False, blank=False)
|
||||
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
|
||||
class ResponsibleGroup(BaseModel):
|
||||
name = models.CharField(max_length=20, null=False, blank=False)
|
||||
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
|
||||
class CustomerResponsible(BaseModel):
|
||||
responsible_group = models.ForeignKey(ResponsibleGroup, on_delete=models.CASCADE, null=False, blank=False, related_name='customer_responsible')
|
||||
cuser_role = models.ForeignKey(CuserRoleModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.responsible_group)
|
||||
|
||||
|
||||
class CustomerGroupType(BaseModel):
|
||||
name = models.CharField(max_length=10, null=False, blank=False)
|
||||
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
|
||||
class CustomerGroup(BaseModel):
|
||||
name = models.CharField(max_length=15, null=False, blank=False)
|
||||
group_type = models.ForeignKey(CustomerGroupType, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
|
||||
class Customer(BaseModel):
|
||||
name_family = models.CharField(max_length=25, null=False, blank=False)
|
||||
mobile = models.PositiveBigIntegerField(null=True, blank=True)
|
||||
phone = models.PositiveBigIntegerField(null=True, blank=True)
|
||||
address = models.CharField(max_length=100, null=True, blank=True)
|
||||
city = models.ForeignKey(CityModel, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
shive_ashenaei = models.ForeignKey(ShiveAshenaei, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
responsible_group = models.ForeignKey(ResponsibleGroup, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
cuser_role = models.ForeignKey(CuserRoleModel, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name_family)
|
||||
|
||||
def clean(self):
|
||||
if self.cuser_role and not self.cuser_role.role_type.role_name_en == 'workspace_customer':
|
||||
raise ValidationError("cuser_role type must be customer")
|
||||
|
||||
|
||||
class CustomerNote(BaseModel):
|
||||
customer = models.ForeignKey(Customer, on_delete=models.CASCADE, null=False, blank=False)
|
||||
cuser_role = models.ForeignKey(CuserRoleModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
desc = models.CharField(max_length=200, null=False, blank=False)
|
||||
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=False, blank=False)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
|
||||
def __str__(self):
|
||||
return str(self.customer.name_family)
|
||||
@@ -0,0 +1,150 @@
|
||||
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
|
||||
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
from apps.customer.models import (
|
||||
ResponsibleGroup as ResponsibleGroupModel,
|
||||
ShiveAshenaei as ShiveAshenaeiModel,
|
||||
Customer as CustomerModel,
|
||||
CustomerNote as CustomerNoteModel
|
||||
)
|
||||
from apps.reminder.models import Reminder as ReminderModel
|
||||
from apps.workspace.models import Workspace as WorkspaceModel
|
||||
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
|
||||
|
||||
|
||||
def create_responsible_group(name: str, workspace: WorkspaceModel):
|
||||
try:
|
||||
responsible_group_obj = ResponsibleGroupModel(name=name, sys_ws=workspace)
|
||||
responsible_group_obj.full_clean()
|
||||
responsible_group_obj.save()
|
||||
|
||||
return responsible_group_obj
|
||||
|
||||
except Exception as exp:
|
||||
message = f'Error creating ResponsibleGroup: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def delete_responsible_group(responsible_group_id: int, workspace_uuid: str):
|
||||
try:
|
||||
ResponsibleGroupModel.objects.get(id=responsible_group_id, sys_ws__uuid=workspace_uuid).delete()
|
||||
except Exception as exp:
|
||||
message = f'Error Deleting ResponsibleGroup: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def create_shive_ashenaei(name: str, workspace: WorkspaceModel) -> ShiveAshenaeiModel:
|
||||
try:
|
||||
shive_obj = ShiveAshenaeiModel(name=name, sys_ws=workspace)
|
||||
shive_obj.full_clean()
|
||||
shive_obj.save()
|
||||
return shive_obj
|
||||
except Exception as exp:
|
||||
message = f'Error creating ShiveAshenaei: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def delete_shive_ashenaei(shive_id: int, workspace_uuid: str) -> ShiveAshenaeiModel:
|
||||
try:
|
||||
ShiveAshenaeiModel.objects.get(id=shive_id, sys_ws__uuid=workspace_uuid).delete()
|
||||
except Exception as exp:
|
||||
message = f'Error Delete ShiveAshenaei: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def create_customer(name_family: str , mobile: int, phone: int, address: str, city: int, shive_ashenaei: int,
|
||||
responsible_group: int, cuser_role: int = None, workspace: WorkspaceModel = None) -> CustomerModel:
|
||||
try:
|
||||
customer_obj = CustomerModel()
|
||||
customer_obj.name_family = name_family
|
||||
customer_obj.mobile = mobile
|
||||
customer_obj.phone = phone
|
||||
customer_obj.address = address
|
||||
customer_obj.city = city
|
||||
customer_obj.shive_ashenaei = shive_ashenaei
|
||||
customer_obj.responsible_group = responsible_group
|
||||
if cuser_role is not None:
|
||||
customer_obj.cuser_role = cuser_role
|
||||
customer_obj.sys_ws = workspace
|
||||
|
||||
customer_obj.full_clean()
|
||||
customer_obj.save()
|
||||
return customer_obj
|
||||
except Exception as exp:
|
||||
message = f'Error Creating Customer: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def update_customer(customer_id: int, name_family: str = None , mobile: int = None, phone: int = None, address: str = None,
|
||||
city: int = None, shive_ashenaei: int = None, responsible_group: int = None, cuser_role: int = None, workspace_uuid: str = None) -> CustomerModel:
|
||||
try:
|
||||
customer_obj = CustomerModel.objects.get(id=customer_id, sys_ws__uuid=workspace_uuid)
|
||||
|
||||
if name_family is not None:
|
||||
customer_obj.name_family = name_family
|
||||
if mobile is not None:
|
||||
customer_obj.mobile = mobile
|
||||
if phone is not None:
|
||||
customer_obj.phone = phone
|
||||
if address is not None:
|
||||
customer_obj.address = address
|
||||
if city is not None:
|
||||
customer_obj.city = city
|
||||
if shive_ashenaei is not None:
|
||||
customer_obj.shive_ashenaei = shive_ashenaei
|
||||
if responsible_group is not None:
|
||||
customer_obj.responsible_group = responsible_group
|
||||
if cuser_role is not None:
|
||||
customer_obj.cuser_role = cuser_role
|
||||
|
||||
customer_obj.full_clean()
|
||||
customer_obj.save()
|
||||
return customer_obj
|
||||
except Exception as exp:
|
||||
message = f'Error Creating Customer: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def delete_customer(customer_id: int, workspace_uuid: str = None) -> CustomerModel:
|
||||
try:
|
||||
CustomerModel.objects.get(id=customer_id, sys_ws__uuid=workspace_uuid).delete()
|
||||
except Exception as exp:
|
||||
message = f'Error Deleting Customer: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def create_customer_v2(request, name_family: str , mobile: int, phone: int, address: str, city: int, shive_ashenaei: int,
|
||||
responsible_group: int, cuser_role: int = None) -> CustomerModel:
|
||||
try:
|
||||
workspace = get_user_workspace(request=request)
|
||||
|
||||
customer_obj = CustomerModel()
|
||||
customer_obj.name_family = name_family
|
||||
customer_obj.mobile = mobile
|
||||
customer_obj.phone = phone
|
||||
customer_obj.address = address
|
||||
customer_obj.city_id = city
|
||||
customer_obj.shive_ashenaei = ShiveAshenaeiModel.objects.get(id=shive_ashenaei, sys_ws=workspace)
|
||||
|
||||
customer_obj.responsible_group = ResponsibleGroupModel.objects.get(id=responsible_group, sys_ws=workspace)
|
||||
if cuser_role is not None:
|
||||
customer_obj.cuser_role = cuser_role
|
||||
customer_obj.sys_ws = workspace
|
||||
|
||||
customer_obj.full_clean()
|
||||
customer_obj.save()
|
||||
return customer_obj
|
||||
except Exception as exp:
|
||||
message = f'Error Creating Customer: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def create_customer_note(request, customer_id: int, desc: str,
|
||||
reminder_datetime: str = None, reminder_desc: str = None) -> CustomerNoteModel:
|
||||
with transaction.atomic():
|
||||
try:
|
||||
workspace = get_user_workspace(request=request)
|
||||
cuser_role = get_cuser_role(request=request)
|
||||
|
||||
customer_note = CustomerNoteModel()
|
||||
customer_note.customer = CustomerModel.objects.get(id=customer_id, sys_ws=workspace)
|
||||
customer_note.desc = desc
|
||||
customer_note.sys_ws = workspace
|
||||
customer_note.cuser_role = cuser_role
|
||||
customer_note.save()
|
||||
|
||||
if reminder_datetime:
|
||||
try:
|
||||
reminder = ReminderModel()
|
||||
reminder.type = 'NO'
|
||||
reminder.note = customer_note
|
||||
reminder.id_type = customer_note.id
|
||||
reminder.customer = customer_note.customer
|
||||
reminder.datetime = reminder_datetime
|
||||
if reminder_desc:
|
||||
reminder.desc = reminder_desc
|
||||
reminder.cuser_role = cuser_role
|
||||
reminder.sys_ws = workspace
|
||||
reminder.save()
|
||||
|
||||
except Exception as exp:
|
||||
transaction.set_rollback(True)
|
||||
message = f'Error Creating Customer Note and Set Reminder: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
return customer_note
|
||||
|
||||
except Exception as exp:
|
||||
transaction.set_rollback(True)
|
||||
message = f'Error Creating Customer Note: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def customer_note_edit(request, customer_id: int, note_id: int, desc: str,
|
||||
reminder_datetime: str = None, reminder_desc: str = None) -> CustomerNoteModel:
|
||||
try:
|
||||
workspace = get_user_workspace(request)
|
||||
cuser_role = get_cuser_role(request)
|
||||
|
||||
customer_note = CustomerNoteModel.objects.get(id=note_id, customer_id=customer_id, sys_ws=workspace)
|
||||
customer_note.desc = desc
|
||||
customer_note.save()
|
||||
|
||||
if reminder_datetime:
|
||||
try:
|
||||
try:
|
||||
reminder = ReminderModel.objects.get(type='NO', note=customer_note, id_type=note_id, customer_id=customer_id)
|
||||
reminder.datetime = reminder_datetime
|
||||
reminder.desc = reminder_desc
|
||||
reminder.save()
|
||||
except Exception as exp:
|
||||
try:
|
||||
reminder = ReminderModel()
|
||||
reminder.type = 'NO'
|
||||
reminder.note = customer_note
|
||||
reminder.id_type = customer_note.id
|
||||
reminder.customer = customer_note.customer
|
||||
reminder.datetime = reminder_datetime
|
||||
if reminder_desc:
|
||||
reminder.desc = reminder_desc
|
||||
reminder.cuser_role = cuser_role
|
||||
reminder.sys_ws = workspace
|
||||
reminder.save()
|
||||
except Exception as exp:
|
||||
print(exp)
|
||||
except Exception as exp:
|
||||
print(exp)
|
||||
|
||||
return customer_note
|
||||
|
||||
except Exception as exp:
|
||||
message = f'Error Edit Customer Note: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
def customer_note_delete(request, customer_id: int, note_id: int) -> CustomerNoteModel:
|
||||
try:
|
||||
workspace = get_user_workspace_uuid(request=request)
|
||||
|
||||
customer_note = CustomerNoteModel.objects.get(id=note_id, customer_id=customer_id, sys_ws__uuid=workspace).delete()
|
||||
|
||||
return customer_note
|
||||
|
||||
except Exception as exp:
|
||||
message = f'Error Delete Customer Note: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,39 @@
|
||||
from django.urls import path
|
||||
from apps.customer.views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('responsible-group/list/', ResponsibleGroupListApi.as_view(), name='list_responsible_group'),
|
||||
path('responsible-group/<int:responsible_group_id>/', ResponsibleGroupRetrieveApi.as_view(),
|
||||
name='retrieve_responsible_group'),
|
||||
path('responsible-group/create/', ResponsibleGroupCreateApi.as_view(), name='create_responsible_group'),
|
||||
path('responsible-group/delete/<int:responsible_group_id>/', ResponsibleGroupDeleteApi.as_view(), name='delete_responsible_group'),
|
||||
|
||||
path('shive_ashenaei/create/', ShiveAshenaeiCreateApi.as_view(), name='create_shive_ashenaei'),
|
||||
path('shive_ashenaei/delete/<int:shive_id>/', ShiveAshenaeiDeleteApi.as_view(), name='delete_shive_ashenaei'),
|
||||
path('shive_ashenaei/list/', ShiveAshenaeiListApi.as_view(), name='list_shive_ashenaei'),
|
||||
path('shive_ashenaei/<int:shive_id>/', ShiveAshenaeiRetrieveApi.as_view(), name='retrive_shive_ashenaei'),
|
||||
|
||||
path('create/', CustomerCreateApi.as_view(), name='create_customer'),
|
||||
path('update/<int:customer_id>/', CustomerUpdateApi.as_view(), name='update_customer'),
|
||||
path('delete/<int:customer_id>/', CustomerDeleteApi.as_view(), name='delete_customer'),
|
||||
path('list/', CustomerListApi.as_view(), name='list_customer'),
|
||||
path('<int:customer_id>/', CustomerRetrieveApi.as_view(), name='retrive_customer'),
|
||||
|
||||
path('<int:customer_id>/summary/', CustomerSummary.as_view(), name='customer_summary'),
|
||||
|
||||
path('<int:customer_id>/note/create/', CustomerCreateNoteApi.as_view(), name='customer_note_create'),
|
||||
|
||||
path('<int:customer_id>/note/list/', CustomerListNoteApi.as_view(), name='customer_note_list'),
|
||||
|
||||
path('<int:customer_id>/note/<int:note_id>/', CustomerRetrieveNoteApi.as_view(), name='customer_note_retrieve'),
|
||||
|
||||
path('<int:customer_id>/note/<int:note_id>/delete/', CustomerDeleteNoteApi.as_view(), name='customer_note_delete'),
|
||||
|
||||
path('<int:customer_id>/note/<int:note_id>/edit/', CustomerEditNoteApi.as_view(), name='customer_note_edit'),
|
||||
|
||||
path('v2/list/', CustomerListApiV2.as_view(), name='list_customer_v2'),
|
||||
|
||||
path('v2/create/', CustomerCreateApiV2.as_view(), name='customer_create_v2'),
|
||||
|
||||
path('form-item/', CustomerFormItemApi.as_view(), name='customer-form-item'),
|
||||
]
|
||||
@@ -0,0 +1,9 @@
|
||||
from .responsible_group import ResponsibleGroupCreateApi, ResponsibleGroupDeleteApi,\
|
||||
ResponsibleGroupRetrieveApi, ResponsibleGroupListApi
|
||||
|
||||
from .shive_ashenaei import ShiveAshenaeiCreateApi, ShiveAshenaeiDeleteApi, ShiveAshenaeiListApi, ShiveAshenaeiRetrieveApi
|
||||
|
||||
from .customer import *
|
||||
from .form_item import *
|
||||
from .customer_summary import *
|
||||
from .customer_note import *
|
||||
@@ -0,0 +1,226 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import serializers
|
||||
from apps.customer.models import Customer as CustomerModel
|
||||
from apps.customer.selectors import retrieve_customer, list_customer, list_customer_v2
|
||||
from utils.get_user_workspace import get_user_workspace_uuid, get_user_workspace
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from utils import custom_permissions
|
||||
from rest_framework import generics
|
||||
from apps.customer.services import create_customer, update_customer, delete_customer, create_customer_v2
|
||||
from apps.workspace.models import City as CityModel
|
||||
from utils.tools import inline_model_serializer, inline_serializer
|
||||
from utils.pagination import CustomPagination
|
||||
from django_filters import rest_framework as filters
|
||||
|
||||
|
||||
|
||||
|
||||
class CustomerRetrieveApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = '__all__'
|
||||
|
||||
def get(self, request, customer_id: int):
|
||||
user_workspace_uuid = get_user_workspace_uuid(request=request)
|
||||
|
||||
customer_obj = retrieve_customer(customer_id=customer_id, workspace_uuid=user_workspace_uuid)
|
||||
|
||||
output = self.OutputSerializer(customer_obj)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class CustomerListApi(generics.ListAPIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
|
||||
class CitySerializer(serializers.ModelSerializer):
|
||||
|
||||
class OstanSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CityModel
|
||||
fields = '__all__'
|
||||
|
||||
ostan = OstanSerializer()
|
||||
class Meta:
|
||||
model = CityModel
|
||||
fields = '__all__'
|
||||
|
||||
city = CitySerializer()
|
||||
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = '__all__'
|
||||
|
||||
serializer_class = OutputSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
user_workspace_uuid = get_user_workspace_uuid(request=self.request)
|
||||
|
||||
name_family = self.request.query_params.get('name_family')
|
||||
mobile = self.request.query_params.get('mobile')
|
||||
|
||||
customer_objs = list_customer(workspace_uuid=user_workspace_uuid, name_family=name_family, mobile=mobile)
|
||||
|
||||
return customer_objs
|
||||
|
||||
|
||||
class CustomerCreateApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class InputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = '__all__'
|
||||
read_only_fields = ['sys_ws', '']
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
exclude = ('sys_ws', )
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.InputSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
user_workspace = get_user_workspace(request=request)
|
||||
|
||||
customer_obj = create_customer(**serializer.validated_data, workspace=user_workspace)
|
||||
output = self.OutputSerializer(customer_obj)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class CustomerUpdateApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class InputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = '__all__'
|
||||
read_only_fields = ['sys_ws', '']
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
exclude = ('sys_ws', )
|
||||
|
||||
def patch(self, request, customer_id: int):
|
||||
serializer = self.InputSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
user_workspace_uuid = get_user_workspace_uuid(request=request)
|
||||
|
||||
customer_obj = update_customer(**serializer.validated_data, customer_id=customer_id, workspace_uuid=user_workspace_uuid)
|
||||
output = self.OutputSerializer(customer_obj)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class CustomerDeleteApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
exclude = ('sys_ws', )
|
||||
|
||||
def delete(self, request, customer_id: int):
|
||||
|
||||
user_workspace_uuid = get_user_workspace_uuid(request=request)
|
||||
|
||||
delete_customer(customer_id=customer_id, workspace_uuid=user_workspace_uuid)
|
||||
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class CustomerListApiV2(generics.ListAPIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class Pagination(CustomPagination):
|
||||
page_size = 10
|
||||
page_size_query_param = 'page_size'
|
||||
max_page_size = 20
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
|
||||
city = inline_serializer(fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
'ostan': inline_serializer(many=False, fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField()
|
||||
})
|
||||
})
|
||||
|
||||
shive_ashenaei = inline_serializer(fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
})
|
||||
|
||||
responsible_group = inline_serializer(fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
})
|
||||
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = '__all__'
|
||||
|
||||
class CustomerFilter(filters.FilterSet):
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = {
|
||||
'name_family': ['exact', 'contains'],
|
||||
'mobile': ['exact', 'contains'],
|
||||
}
|
||||
|
||||
serializer_class = OutputSerializer
|
||||
|
||||
pagination_class = Pagination
|
||||
|
||||
filter_backends = [filters.DjangoFilterBackend, ]
|
||||
filterset_class = CustomerFilter
|
||||
|
||||
def get_queryset(self):
|
||||
customer_objs = list_customer_v2(request=self.request)
|
||||
|
||||
return customer_objs
|
||||
|
||||
|
||||
class CustomerCreateApiV2(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class InputSerializer(serializers.Serializer):
|
||||
name_family = serializers.CharField(max_length=25, required=True)
|
||||
mobile = serializers.IntegerField(required=True)
|
||||
phone = serializers.IntegerField(required=True)
|
||||
address = serializers.CharField(max_length=300, required=True)
|
||||
city = serializers.IntegerField(required=True)
|
||||
shive_ashenaei = serializers.IntegerField(required=True)
|
||||
responsible_group = serializers.IntegerField(required=True)
|
||||
|
||||
def post(self, request):
|
||||
|
||||
serializer = self.InputSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
customer = create_customer_v2(request=request, **serializer.validated_data)
|
||||
|
||||
return Response(data={'id': customer.id}, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import serializers
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from apps.customer.services import create_customer_note, customer_note_edit, customer_note_delete
|
||||
from apps.customer.selectors import customer_note_retrieve, customer_note_list
|
||||
from apps.customer.models import CustomerNote as CustomerNoteModel
|
||||
from apps.reminder.models import Reminder as ReminderModel
|
||||
from utils.tools import inline_serializer
|
||||
|
||||
|
||||
|
||||
class CustomerCreateNoteApi(APIView):
|
||||
class InputSerializer(serializers.Serializer):
|
||||
desc = serializers.CharField()
|
||||
reminder_datetime = serializers.DateTimeField(required=False, allow_null=True)
|
||||
reminder_desc = serializers.CharField(required=False, allow_null=True, max_length=200)
|
||||
|
||||
def post(self, request, customer_id):
|
||||
serializer = self.InputSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
output = create_customer_note(request=request, customer_id=customer_id, **serializer.validated_data)
|
||||
|
||||
return Response(data={'id': output.id}, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class CustomerListNoteApi(APIView):
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerNoteModel
|
||||
exclude = ['cuser_role', 'sys_ws']
|
||||
|
||||
def get(self, request, customer_id):
|
||||
notes = customer_note_list(request=request, customer_id=customer_id)
|
||||
output = self.OutputSerializer(notes, many=True)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class CustomerRetrieveNoteApi(APIView):
|
||||
|
||||
class OutputSerializer(serializers.Serializer):
|
||||
|
||||
class CustomerNoteSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerNoteModel
|
||||
fields = '__all__'
|
||||
|
||||
class CustomerNoteReminderSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ReminderModel
|
||||
fields = '__all__'
|
||||
|
||||
customer_note = CustomerNoteSerializer(many=False, required=True)
|
||||
customer_note_reminder = CustomerNoteReminderSerializer(many=False, required=False)
|
||||
|
||||
def get(self, request, customer_id, note_id):
|
||||
note = customer_note_retrieve(request=request, customer_id=customer_id, note_id=note_id)
|
||||
output = self.OutputSerializer(note)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class CustomerEditNoteApi(APIView):
|
||||
|
||||
class InputSerializer(serializers.Serializer):
|
||||
desc = serializers.CharField(required=True)
|
||||
reminder_datetime = serializers.DateTimeField(required=False, allow_null=True)
|
||||
reminder_desc = serializers.CharField(required=False, allow_null=True, max_length=200)
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CustomerNoteModel
|
||||
fields = '__all__'
|
||||
|
||||
def patch(self, request, customer_id, note_id):
|
||||
|
||||
serializer = self.InputSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
note = customer_note_edit(request=request, customer_id=customer_id, note_id=note_id, **serializer.validated_data)
|
||||
|
||||
return Response(data={'id': note.id}, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class CustomerDeleteNoteApi(APIView):
|
||||
|
||||
def delete(self, request, customer_id, note_id):
|
||||
note = customer_note_delete(request=request, customer_id=customer_id, note_id=note_id)
|
||||
|
||||
return Response(data={'result': 'deleted'}, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from rest_framework import serializers
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from apps.customer.models import Customer as CustomerModel
|
||||
from rest_framework import status
|
||||
from apps.customer.selectors import customer_summery
|
||||
from utils.tools import inline_serializer
|
||||
|
||||
|
||||
class CustomerSummary(APIView):
|
||||
|
||||
class OutputSerializer(serializers.Serializer):
|
||||
customer_notes = inline_serializer(many=True, fields={
|
||||
'id': serializers.IntegerField(required=True),
|
||||
'created_at': serializers.DateTimeField(required=True),
|
||||
'desc': serializers.CharField(required=True)
|
||||
})
|
||||
customer_leads = inline_serializer(many=True, fields={
|
||||
'id': serializers.IntegerField(required=True),
|
||||
'title': serializers.CharField(required=True),
|
||||
'created_at': serializers.DateTimeField(required=True),
|
||||
})
|
||||
|
||||
def get(self, request, customer_id):
|
||||
|
||||
summery = customer_summery(request=request, customer_id=customer_id)
|
||||
output = self.OutputSerializer(summery)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
from rest_framework.views import APIView
|
||||
from apps.customer.models import ShiveAshenaei as ShiveAshenaeiModel
|
||||
from apps.workspace.models import City as CityModel
|
||||
from rest_framework import serializers
|
||||
from utils.tools import inline_serializer
|
||||
from rest_framework import status
|
||||
from apps.customer.selectors import customer_form_item
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from utils import custom_permissions
|
||||
|
||||
|
||||
class CustomerFormItemApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class OutputSerializer(serializers.Serializer):
|
||||
|
||||
shive_ashenaei = inline_serializer(many=True, fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField()
|
||||
})
|
||||
|
||||
shahr = inline_serializer(many=True, fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
'ostan': inline_serializer(fields={'id': serializers.IntegerField(), }),
|
||||
'is_ostan': serializers.BooleanField(),
|
||||
})
|
||||
|
||||
responsible_groups = inline_serializer(many=True, fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField()
|
||||
})
|
||||
|
||||
def get(self, request):
|
||||
|
||||
fields_value = customer_form_item(request)
|
||||
serializer = self.OutputSerializer(fields_value)
|
||||
|
||||
return Response(data=serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import generics
|
||||
from rest_framework import serializers
|
||||
from rest_framework.response import Response
|
||||
from apps.customer.services import create_responsible_group, delete_responsible_group
|
||||
from apps.customer.selectors import retrieve_responsible_group, list_responsible_group
|
||||
from utils.get_user_workspace import get_user_workspace_uuid, get_user_workspace
|
||||
from rest_framework import status
|
||||
from utils import custom_permissions
|
||||
from apps.customer.models import ResponsibleGroup
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
|
||||
class ResponsibleGroupRetrieveApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission, )
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ResponsibleGroup
|
||||
fields = '__all__'
|
||||
|
||||
def get(self, request, responsible_group_id: int):
|
||||
|
||||
user_workspace_uuid = get_user_workspace_uuid(request)
|
||||
responsible_group_obj = retrieve_responsible_group(responsible_group_id=responsible_group_id, workspace_uuid=user_workspace_uuid)
|
||||
|
||||
output = self.OutputSerializer(responsible_group_obj)
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ResponsibleGroupListApi(generics.ListAPIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission, )
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ResponsibleGroup
|
||||
fields = '__all__'
|
||||
|
||||
serializer_class = OutputSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
user_workspace_uuid = get_user_workspace_uuid(self.request)
|
||||
return list_responsible_group(workspace_uuid=user_workspace_uuid)
|
||||
|
||||
|
||||
class ResponsibleGroupCreateApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceAdminPermission,)
|
||||
|
||||
class InputSerializer(serializers.Serializer):
|
||||
name = serializers.CharField(max_length=20)
|
||||
|
||||
class OutputSerializer(serializers.Serializer):
|
||||
name = serializers.CharField(max_length=20)
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.InputSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
group_name = serializer.validated_data.get
|
||||
user_workspace = get_user_workspace(request=request)
|
||||
|
||||
responsible_group_obj = create_responsible_group(name=group_name, workspace=user_workspace)
|
||||
output = self.OutputSerializer(responsible_group_obj)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class ResponsibleGroupDeleteApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceAdminPermission,)
|
||||
|
||||
def delete(self, request, responsible_group_id: int):
|
||||
|
||||
user_workspace_uuid = get_user_workspace_uuid(request)
|
||||
delete_responsible_group(responsible_group_id=responsible_group_id, workspace_uuid=user_workspace_uuid)
|
||||
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
from apps.customer.models import ShiveAshenaei as ShiveAshenaeiModel
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import generics
|
||||
from utils.get_user_workspace import get_user_workspace_uuid, get_user_workspace
|
||||
from utils import custom_permissions
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import serializers
|
||||
from apps.customer.services import create_shive_ashenaei, delete_shive_ashenaei
|
||||
from apps.customer.selectors import list_shive_ashenaei, retrieve_shive_ashenaei
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
class ShiveAshenaeiCreateApi(APIView):
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceAdminPermission)
|
||||
|
||||
class InputSerializer(serializers.Serializer):
|
||||
name = serializers.CharField(max_length=20)
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.InputSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
user_workspace = get_user_workspace(request=request)
|
||||
name = serializer.validated_data.get
|
||||
|
||||
create_shive_ashenaei(name=name, workspace=user_workspace)
|
||||
|
||||
return Response(status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class ShiveAshenaeiDeleteApi(APIView):
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceAdminPermission)
|
||||
|
||||
def delete(self, request, shive_id: int):
|
||||
|
||||
user_workspace_uuid = get_user_workspace_uuid(request=request)
|
||||
delete_shive_ashenaei(shive_id=shive_id, workspace_uuid=user_workspace_uuid)
|
||||
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ShiveAshenaeiRetrieveApi(APIView):
|
||||
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission, )
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ShiveAshenaeiModel
|
||||
fields = '__all__'
|
||||
|
||||
def get(self, request, shive_id: int):
|
||||
|
||||
user_workspace_uuid = get_user_workspace_uuid(request)
|
||||
responsible_group_obj = retrieve_shive_ashenaei(shive_id=shive_id, workspace_uuid=user_workspace_uuid)
|
||||
|
||||
output = self.OutputSerializer(responsible_group_obj)
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ShiveAshenaeiListApi(generics.ListAPIView):
|
||||
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ShiveAshenaeiModel
|
||||
fields = '__all__'
|
||||
|
||||
serializer_class = OutputSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
user_workspace_uuid = get_user_workspace_uuid(self.request)
|
||||
return list_shive_ashenaei(workspace_uuid=user_workspace_uuid)
|
||||
Reference in new issue
Block a user