add new app

This commit is contained in:
behruz-dev
2025-08-01 15:24:00 +05:00
parent 9b403c46da
commit a714dbacb3
49 changed files with 579 additions and 0 deletions

View File

View File

@@ -0,0 +1,3 @@
from .wherehouse import *
from .inventory import *
from .stock_movement import *

View File

@@ -0,0 +1,9 @@
from django.contrib import admin
from core.apps.wherehouse.models.inventory import Inventory
@admin.register(Inventory)
class InventoryAdmin(admin.ModelAdmin):
list_display = ['quantity', 'wherehouse', 'product']

View File

@@ -0,0 +1,8 @@
from django.contrib import admin
from core.apps.wherehouse.models.stock_movemend import StockMovemend
@admin.register(StockMovemend)
class StockMovemendAdmin(admin.ModelAdmin):
list_display = ['wherehouse_to', 'wherehouse_from', 'product', 'quantity', 'movemend_type']

View File

@@ -0,0 +1,10 @@
from django.contrib import admin
from core.apps.wherehouse.models.wherehouse import WhereHouse
@admin.register(WhereHouse)
class WhereHouseAdmin(admin.ModelAdmin):
list_display = ['name', 'address', 'branch']
search_fields = ['name', 'address']
list_filter = ['branch']

View File

@@ -0,0 +1,9 @@
from django.apps import AppConfig
class WherehouseConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'core.apps.wherehouse'
def ready(self):
from . import admin

View File

@@ -0,0 +1,48 @@
# Generated by Django 5.2.4 on 2025-08-01 11:42
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('company', '0002_rename_barnch_branch'),
('products', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='WhereHouse',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=200)),
('address', models.CharField(max_length=200)),
('branch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='wherehouses', to='company.branch')),
],
options={
'verbose_name': 'omborxona',
'verbose_name_plural': 'omborxonalar',
},
),
migrations.CreateModel(
name='Inventory',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('quantity', models.PositiveIntegerField(default=0)),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='inventories', to='products.product')),
('wherehouse', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='inventories', to='wherehouse.wherehouse')),
],
options={
'verbose_name': 'inventar',
'verbose_name_plural': 'inventarlar',
},
),
]

View File

@@ -0,0 +1,33 @@
# Generated by Django 5.2.4 on 2025-08-01 14:37
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('products', '0002_alter_product_options'),
('wherehouse', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='StockMovemend',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('quantity', models.PositiveIntegerField(default=0)),
('movemend_type', models.CharField(choices=[('IN', 'in'), ('OUT', 'out'), ('TRANSFER', 'transfer')], max_length=20)),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stocks', to='products.product')),
('wherehouse_from', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stocks_from', to='wherehouse.wherehouse')),
('wherehouse_to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stocks_to', to='wherehouse.wherehouse')),
],
options={
'verbose_name': 'Mahsulotlarni kochirish',
'verbose_name_plural': 'Mahsulotlarni kochirish',
},
),
]

View File

@@ -0,0 +1,3 @@
from .inventory import *
from .wherehouse import *
from .stock_movemend import *

View File

@@ -0,0 +1,20 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from core.apps.shared.models import BaseModel
from core.apps.wherehouse.models.wherehouse import WhereHouse
from core.apps.products.models.product import Product
class Inventory(BaseModel):
wherehouse = models.ForeignKey(WhereHouse, on_delete=models.CASCADE, related_name='inventories')
quantity = models.PositiveIntegerField(default=0)
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='inventories')
def __str__(self):
return f'{self.product} in {self.wherehouse}'
class Meta:
verbose_name = _('inventar')
verbose_name_plural = _("inventarlar")

View File

@@ -0,0 +1,33 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from core.apps.shared.models import BaseModel
from core.apps.wherehouse.models.wherehouse import WhereHouse
from core.apps.products.models.product import Product
class StockMovemend(BaseModel):
TYPE = (
('IN', 'in'),
('OUT', 'out'),
('TRANSFER', 'transfer'),
)
wherehouse_to = models.ForeignKey(
WhereHouse, on_delete=models.CASCADE, related_name='stocks_to'
)
wherehouse_from = models.ForeignKey(
WhereHouse, on_delete=models.CASCADE, related_name='stocks_from'
)
product = models.ForeignKey(
Product, on_delete=models.CASCADE, related_name='stocks'
)
quantity = models.PositiveIntegerField(default=0)
movemend_type = models.CharField(max_length=20, choices=TYPE)
def __str__(self):
return f'{self.product} send from {self.wherehouse_from} to {self.wherehouse_to}'
class Meta:
verbose_name = _('Mahsulotlarni kochirish')
verbose_name_plural = _('Mahsulotlarni kochirish')

View File

@@ -0,0 +1,18 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from core.apps.shared.models import BaseModel
from core.apps.company.models.branch import Branch
class WhereHouse(BaseModel):
branch = models.ForeignKey(Branch, on_delete=models.CASCADE, related_name='wherehouses')
name = models.CharField(max_length=200)
address = models.CharField(max_length=200)
def __str__(self):
return self.name
class Meta:
verbose_name = _('omborxona')
verbose_name_plural = _('omborxonalar')

View File

@@ -0,0 +1,11 @@
from rest_framework import serializers
from core.apps.wherehouse.models.inventory import Inventory
class WhereHouseInventoryListSerializer(serializers.ModelSerializer):
class Meta:
model = Inventory
fields = [
'id', 'quantity', 'product'
]

View File

@@ -0,0 +1,27 @@
from rest_framework import serializers
from core.apps.wherehouse.models.wherehouse import WhereHouse
from core.apps.wherehouse.serializers.inventory import WhereHouseInventoryListSerializer
from core.apps.company.serializers.branch import BranchListSerializer
class WhereHouseListSerializer(serializers.ModelSerializer):
branch = BranchListSerializer()
class Meta:
model = WhereHouse
fields = [
'id', 'name', 'address', 'branch'
]
class WhereHouseDetailSerializer(serializers.ModelSerializer):
branch = BranchListSerializer()
inventories = WhereHouseInventoryListSerializer(many=True)
class Meta:
model = WhereHouse
fields = [
'id', 'name', 'address', 'branch', 'inventories'
]

View File

@@ -0,0 +1,13 @@
from django.urls import path, include
from core.apps.wherehouse.views import wherehouse as wherehouse_views
urlpatterns = [
path('wherehouse/', include(
[
path('list/', wherehouse_views.WhereHouseListApiView.as_view()),
path('<uuid:id>/', wherehouse_views.WhereHouseDetailApiView.as_view()),
]
))
]

View File

View File

@@ -0,0 +1,21 @@
from rest_framework import generics, status
from rest_framework.response import Response
from core.apps.wherehouse.models import WhereHouse, Inventory
from core.apps.wherehouse.serializers import wherehouse as serializers
from core.apps.accounts.permissions.permissions import HasRolePermission
class WhereHouseListApiView(generics.ListAPIView):
serializer_class = serializers.WhereHouseListSerializer
queryset = WhereHouse.objects.select_related('branch')
permission_classes = [HasRolePermission]
required_permissions = []
class WhereHouseDetailApiView(generics.RetrieveAPIView):
serializer_class = serializers.WhereHouseDetailSerializer
queryset = WhereHouse.objects.select_related('branch').prefetch_related('inventories')
permission_classes = [HasRolePermission]
required_permissions = []
lookup_field = 'id'