add new api

This commit is contained in:
behruz-dev
2025-08-25 15:56:09 +05:00
parent 74ecc581ae
commit 30e0e3462f
15 changed files with 108 additions and 61 deletions

View File

@@ -0,0 +1,3 @@
from .celery import app as celery_app
__all__ = ['celery_app']

View File

@@ -1,11 +1,10 @@
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
app = Celery('config')
app = Celery('config', broker="redis://redis:6379", backend="redis://redis:6379")
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

View File

@@ -1,6 +1,9 @@
from django.conf import settings
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_BROKER_URL = 'redis://redis:6379'
CELERY_RESULT_BACKEND = "redis://redis:6379"
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_TIMEZONE = settings.TIME_ZONE
CELERY_ENABLED = True

View File

@@ -45,7 +45,6 @@ JAZZMIN_SETTINGS = {
"default_icon_parents": "fas fa-chevron-circle-right",
"default_icon_children": "fas fa-circle",
"related_modal_active": True,
"use_google_fonts_cdn": True,
"show_ui_builder": False,

View File

@@ -1,7 +1,7 @@
CACHES = {
"default": {
"BACKEND": 'django_redis.cache.RedisCache',
"LOCATION": 'redis://redis:6379',
"LOCATION": 'redis://redis:6379z',
"TIMEOUT": 300,
},
}

View File

@@ -38,7 +38,6 @@ PACKAGES = [
'rest_framework_simplejwt',
'corsheaders',
'cacheops',
# 'silk',
]
DJANGO_APPS = [
@@ -100,7 +99,6 @@ DATABASES = {
'PASSWORD': env.str('POSTGRES_PASSWORD'),
'HOST': env.str('POSTGRES_HOST'),
'PORT': env.str('POSTGRES_PORT'),
'CONN_MAX_AGE': 0
}
}
@@ -159,5 +157,5 @@ from config.conf.logs import *
from config.conf.cors_headers import *
from config.conf.drf_yasg import *
from config.conf.jazzmin import *
from config.conf.redis import *
from config.conf.celery import *
from config.conf.redis import *

View File

@@ -81,8 +81,6 @@ class MultipleOrderCreateSerializer(serializers.Serializer):
date=common_date,
employee=self.context.get('user'),
))
create_inventory.delay(resource['wherehouse'],resource['quantity'],resource)
created_orders = Order.objects.bulk_create(orders)
return created_orders

View File

@@ -6,6 +6,7 @@ from core.apps.orders.models import Party, PartyAmount, Order, DeletedParty
from core.apps.orders.serializers.order import MultipleOrderAddSerializer, OrderListSerializer
from core.apps.accounts.models import User
from core.apps.counterparty.serializers.counterparty import CounterpartyListPartySerializer
from core.apps.orders.tasks.order import create_inventory
from core.apps.shared.models import UsdCourse
from core.apps.products.models import Product, Unity
from core.apps.projects.models import Project, ProjectFolder
@@ -56,6 +57,7 @@ class PartyCreateSerializer(serializers.Serializer):
total_price=resource.get('total_price'),
qqs=resource.get('qqs'),
))
create_inventory.delay(resource['wherehouse_id'], resource['quantity'], resource['product_id'], resource['unity_id'], resource['total_price'])
if validated_data.get('currency') == 'uzs':
if resource.get('currency') == 'usd':
usd_value = UsdCourse.objects.first().value

View File

@@ -6,9 +6,9 @@ from core.apps.wherehouse.models.inventory import Inventory
@shared_task
def create_inventory(wherehouse, quantity, product, unity, price):
Inventory.objects.create(
wherehouse__id=wherehouse,
quantity=quantity,
product__id=product,
unity__id=unity,
price=price
wherehouse_id=wherehouse,
quantity=quantity,
product_id=product,
unity_id=unity,
price=price
)

View File

@@ -3,9 +3,9 @@ from rest_framework import serializers
from core.apps.wherehouse.models.inventory import Inventory
class WhereHouseInventoryListSerializer(serializers.ModelSerializer):
class InventoryListSerializer(serializers.ModelSerializer):
class Meta:
model = Inventory
fields = [
'id', 'quantity', 'product'
'id', 'quantity', 'product', 'price', 'unity'
]

View File

@@ -3,7 +3,7 @@ from django.db import transaction
from rest_framework import serializers
from core.apps.wherehouse.models.wherehouse import WhereHouse
from core.apps.wherehouse.serializers.inventory import WhereHouseInventoryListSerializer
from core.apps.wherehouse.serializers.inventory import InventoryListSerializer
from core.apps.company.serializers.branch import BranchListSerializer
from core.apps.company.models import Branch

View File

@@ -1,6 +1,7 @@
from django.urls import path, include
from core.apps.wherehouse.views import wherehouse as wherehouse_views
from core.apps.wherehouse.views import inventory as inventory_views
urlpatterns = [
@@ -13,4 +14,9 @@ urlpatterns = [
path('<uuid:id>/update/', wherehouse_views.WhereHouseUpdateApiView.as_view()),
]
)),
path('inventory/', include(
[
path('<uuid:wherehouse_id>/list/', inventory_views.InventoryListApiView.as_view()),
]
)),
]

View File

@@ -0,0 +1,25 @@
from django.shortcuts import get_object_or_404
from rest_framework import generics, views
from rest_framework.response import Response
from core.apps.wherehouse.serializers import inventory as serializers
from core.apps.wherehouse.models import WhereHouse, Inventory
from core.apps.accounts.permissions.permissions import HasRolePermission
class InventoryListApiView(generics.GenericAPIView):
serializer_class = serializers.InventoryListSerializer
queryset = Inventory.objects.all()
permissions_class = [HasRolePermission]
required_permissions = ['wherehouse']
def get(self, request, wherehouse_id):
wherehouse = get_object_or_404(WhereHouse, id=wherehouse_id)
inventories = Inventory.objects.filter(wherehouse=wherehouse)
page = self.paginate_queryset(inventories)
if page is not None:
serializer = self.serializer_class(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.serializer_class(inventories, many=True)
return Response(serializer.data, status=200)

View File

@@ -50,8 +50,6 @@ services:
networks:
- uyqur
image: redis
ports:
- "6380:6379"
celery:
build:
@@ -65,3 +63,6 @@ services:
- web
networks:
- uyqur
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0

View File

@@ -1,13 +1,26 @@
FROM python:3.13-alpine
ENV PYTHONPYCACHEPREFIX=/dev/null
RUN apk update && apk add git gettext
FROM python:3.12
WORKDIR /code
COPY requirements.txt /code/requirements.txt
RUN apt-get update && \
apt-get install -y \
gdal-bin \
libgdal-dev \
python3-gdal \
libgeos-dev \
libproj-dev \
g++ \
make \
wget \
libfontconfig \
libxrender1 \
libjpeg-dev \
xfonts-base && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
CMD ["sh", "./entrypoint.sh"]
COPY ./ /code
RUN --mount=type=cache,target=/root/.cache/pip python3 -m pip install -r requirements.txt
CMD ["sh", "./resources/scripts/entrypoint.sh"]