This commit is contained in:
javad committed 2024-01-22 13:01:42 +03:30
commit 89a5d70512
284 files changed
+8364

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
from .product_category import *
from .product import *
from .order import *
from .cart import *
from .order_item import *
+9
View File
@@ -0,0 +1,9 @@
from apps.shop.models import Cart as CartModel
def list_cart(cuser_role_uuid: str, workspace_uuid: str) -> CartModel:
return CartModel.objects.filter(sys_ws__uuid=workspace_uuid, cuser_role__uuid=cuser_role_uuid)
def clean_cart(cuser_role_uuid: str, workspace_uuid: str) -> CartModel:
return CartModel.objects.filter(sys_ws__uuid=workspace_uuid, cuser_role__uuid=cuser_role_uuid).delete()
+46
View File
@@ -0,0 +1,46 @@
from apps.shop.models import Order as OrderModel
from apps.customer.models import CustomerResponsible as CustomerResponsibleModel
from apps.cuser.models import CuserRole as CuserRoleModel
from rest_framework import exceptions
from utils.custom_permissions import workspace_admin_up
from apps.customer.models import Customer as CustomerModel
def retrieve_order(cuser_role_uuid: str, order_id: int, workspace_uuid: str) -> OrderModel:
try:
cuser_role = CuserRoleModel.objects.select_related('role_type').get
role_type = cuser_role.role_type
if role_type.role_name_en == 'workspace_customer':
customer = CustomerModel.objects.get(cuser_role=cuser_role)
order_obj = OrderModel.objects.get(id=order_id, sys_ws__uuid=workspace_uuid, customer=customer)
return order_obj
if role_type.role_name_en in ('workspace_owner', 'workspace_operator', 'workspace_admin'):
order_obj = OrderModel.objects.get(id=order_id, sys_ws__uuid=workspace_uuid)
return order_obj
except Exception as exp:
message = f'Error Retrieve Order: {exp}'
raise exceptions.ValidationError({'error': message})
def list_order(cuser_role_uuid: str, workspace_uuid: str) -> OrderModel:
try:
cuser_role = CuserRoleModel.objects.select_related('role_type').get(uuid=cuser_role_uuid)
role_type = cuser_role.role_type
if role_type.role_name_en == 'workspace_customer':
customer = CustomerModel.objects.get(cuser_role=cuser_role)
orders_obj = OrderModel.objects.filter(sys_ws__uuid=workspace_uuid, customer=customer).order_by('-created_at')
return orders_obj
if role_type.role_name_en in ('workspace_owner', 'workspace_operator', 'workspace_admin'):
orders_obj = OrderModel.objects.filter(sys_ws__uuid=workspace_uuid).order_by('-created_at')
return orders_obj
except Exception as exp:
message = f'Error Fetching List Order: {exp}'
raise exceptions.ValidationError({'error': message})
+19
View File
@@ -0,0 +1,19 @@
from apps.shop.models import OrderItem as OrderItemModel
from apps.cuser.models import CuserRole as CuserRoleModel
from rest_framework import exceptions
def list_order_item(order_id: int, cuser_role_uuid: str) -> OrderItemModel:
try:
cuser_role_uuid_obj = CuserRoleModel.objects.get(uuid=cuser_role_uuid)
order_items_obj = OrderItemModel.objects.filter(
order_id=order_id,
order__customer__cuser_role_id=cuser_role_uuid_obj.id).order_by('-created_at')
return order_items_obj
except Exception as exp:
message = f'Error Fetching List Order items: {exp}'
raise exceptions.ValidationError({'error': message})
+38
View File
@@ -0,0 +1,38 @@
from apps.shop.models import Product as ProductModel
from rest_framework import exceptions
def retrieve_product(product_id: int, workspace_uuid: str) -> ProductModel:
try:
product_obj = ProductModel.objects.get(id=product_id, sys_ws__uuid=workspace_uuid)
return product_obj
except Exception as exp:
message = f'Error Retrieve Product: {exp}'
raise exceptions.ValidationError({'error': message})
def list_product(workspace_uuid: str) -> ProductModel:
try:
product_category_obj = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid)
return product_category_obj
except Exception as exp:
message = f'Error Fetching List Product: {exp}'
raise exceptions.ValidationError({'error': message})
def list_product_by_category(workspace_uuid: str, category_id: int) -> ProductModel:
try:
product_category_obj = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid, category_id=category_id)
return product_category_obj
except Exception as exp:
message = f'Error Fetching List Product by category: {exp}'
raise exceptions.ValidationError({'error': message})
def count_product_in_category(workspace_uuid: str, category_id: int) -> int:
try:
count_product = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid, category_id=category_id).count()
return count_product
except Exception as exp:
message = f'Error Couting Product in category: {exp}'
raise exceptions.ValidationError({'error': message})
+20
View File
@@ -0,0 +1,20 @@
from apps.shop.models import ProductCategory as ProductCategoryModel
from rest_framework import exceptions
def retrieve_product_category(category_id: int, workspace_uuid: str) -> ProductCategoryModel:
try:
product_category_obj = ProductCategoryModel.objects.get(id=category_id, sys_ws__uuid=workspace_uuid)
return product_category_obj
except Exception as exp:
message = f'Error Retrieve ProductCategory: {exp}'
raise exceptions.ValidationError({'error': message})
def list_product_category(workspace_uuid: str) -> ProductCategoryModel:
try:
product_category_obj = ProductCategoryModel.objects.filter(sys_ws__uuid=workspace_uuid)
return product_category_obj
except Exception as exp:
message = f'Error Fetching List ProductCategory: {exp}'
raise exceptions.ValidationError({'error': message})