diff --git a/core/apps/products/migrations/0006_alter_product_type.py b/core/apps/products/migrations/0006_alter_product_type.py new file mode 100644 index 0000000..58dc007 --- /dev/null +++ b/core/apps/products/migrations/0006_alter_product_type.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.4 on 2025-08-18 09:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('products', '0005_folder_product_product_code_product_unity_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='product', + name='type', + field=models.CharField(choices=[('MECHANISM', 'maxanizm'), ('PRODUCT', 'mahsulot'), ('HUMAN_RESOURCE', 'inson resursi'), ('SERVICE', 'xizmat')], default='TANGIBLE', max_length=20), + ), + ] diff --git a/core/apps/products/models/product.py b/core/apps/products/models/product.py index 83cdf7d..92166f3 100644 --- a/core/apps/products/models/product.py +++ b/core/apps/products/models/product.py @@ -7,7 +7,7 @@ from core.apps.shared.models import BaseModel class Product(BaseModel): TYPE = ( ("MECHANISM", "maxanizm"), - ("PRODUCT", "product"), + ("PRODUCT", "mahsulot"), ("HUMAN_RESOURCE", "inson resursi"), ("SERVICE", 'xizmat') ) diff --git a/core/apps/products/serializers/unity.py b/core/apps/products/serializers/unity.py index f716d4a..a912ce4 100644 --- a/core/apps/products/serializers/unity.py +++ b/core/apps/products/serializers/unity.py @@ -6,4 +6,7 @@ from core.apps.products.models import Unity class UnityListSerializer(serializers.ModelSerializer): class Meta: model = Unity - fields = ['id', 'value'] \ No newline at end of file + fields = ['id', 'value'] + + def create(self, validated_data): + return Unity.objects.create(**validated_data) \ No newline at end of file diff --git a/core/apps/products/urls.py b/core/apps/products/urls.py index 826e374..f644acb 100644 --- a/core/apps/products/urls.py +++ b/core/apps/products/urls.py @@ -17,6 +17,9 @@ urlpatterns = [ path('unity/', include( [ path('list/', unity_views.UnityListApiView.as_view()), + path('create/', unity_views.UnityCreateApiView.as_view()), + path('/delete/', unity_views.UnityDeleteApiView.as_view()), + path('/update/', unity_views.UnityUpdateApiView.as_view()), ] )), path('folder/', include( diff --git a/core/apps/products/views/unity.py b/core/apps/products/views/unity.py index 34f9dd7..2d4221a 100644 --- a/core/apps/products/views/unity.py +++ b/core/apps/products/views/unity.py @@ -12,4 +12,27 @@ class UnityListApiView(generics.ListAPIView): queryset = Unity.objects.all() permission_classes = [HasRolePermission] required_permissions = [] - pagination_class = CustomPageNumberPagination \ No newline at end of file + pagination_class = CustomPageNumberPagination + + +class UnityCreateApiView(generics.CreateAPIView): + serializer_class = serializers.UnityListSerializer + queryset = Unity.objects.all() + permission_classes = [HasRolePermission] + required_permissions = [] + + +class UnityUpdateApiView(generics.UpdateAPIView): + serializer_class = serializers.UnityListSerializer + queryset = Unity.objects.all() + permission_classes = [HasRolePermission] + required_permissions = [] + lookup_field = 'id' + + +class UnityDeleteApiView(generics.DestroyAPIView): + serializer_class = serializers.UnityListSerializer + queryset = Unity.objects.all() + permission_classes = [HasRolePermission] + required_permissions = [] + lookup_field = 'id'