From 3589b0daf331c99583e2a29ea516c15fba947757 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Mon, 22 Sep 2025 11:08:02 +0500 Subject: [PATCH] remove branch from warehouse model --- core/apps/wherehouse/admin/wherehouse.py | 5 ++--- .../0016_remove_wherehouse_branch.py | 17 ++++++++++++++++ core/apps/wherehouse/models/wherehouse.py | 1 - .../apps/wherehouse/serializers/wherehouse.py | 20 +++---------------- core/apps/wherehouse/views/wherehouse.py | 4 ++-- 5 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 core/apps/wherehouse/migrations/0016_remove_wherehouse_branch.py diff --git a/core/apps/wherehouse/admin/wherehouse.py b/core/apps/wherehouse/admin/wherehouse.py index 4da3a22..ac12b6c 100644 --- a/core/apps/wherehouse/admin/wherehouse.py +++ b/core/apps/wherehouse/admin/wherehouse.py @@ -5,6 +5,5 @@ from core.apps.wherehouse.models.wherehouse import WhereHouse @admin.register(WhereHouse) class WhereHouseAdmin(admin.ModelAdmin): - list_display = ['id','name', 'address', 'branch'] - search_fields = ['name', 'address'] - list_filter = ['branch'] \ No newline at end of file + list_display = ['id','name', 'address',] + search_fields = ['name', 'address'] \ No newline at end of file diff --git a/core/apps/wherehouse/migrations/0016_remove_wherehouse_branch.py b/core/apps/wherehouse/migrations/0016_remove_wherehouse_branch.py new file mode 100644 index 0000000..e1ee9ed --- /dev/null +++ b/core/apps/wherehouse/migrations/0016_remove_wherehouse_branch.py @@ -0,0 +1,17 @@ +# Generated by Django 5.2.4 on 2025-09-22 11:07 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('wherehouse', '0015_alter_stockmovmendproduct_inventory_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='wherehouse', + name='branch', + ), + ] diff --git a/core/apps/wherehouse/models/wherehouse.py b/core/apps/wherehouse/models/wherehouse.py index 1ec1775..f14a034 100644 --- a/core/apps/wherehouse/models/wherehouse.py +++ b/core/apps/wherehouse/models/wherehouse.py @@ -6,7 +6,6 @@ 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) diff --git a/core/apps/wherehouse/serializers/wherehouse.py b/core/apps/wherehouse/serializers/wherehouse.py index 22da8b2..b68b526 100644 --- a/core/apps/wherehouse/serializers/wherehouse.py +++ b/core/apps/wherehouse/serializers/wherehouse.py @@ -9,43 +9,30 @@ from core.apps.company.models import Branch class WhereHouseListSerializer(serializers.ModelSerializer): - branch = BranchListSerializer() - class Meta: model = WhereHouse fields = [ - 'id', 'name', 'address', 'branch' + 'id', 'name', 'address', ] class WhereHouseDetailSerializer(serializers.ModelSerializer): - branch = BranchListSerializer() - class Meta: model = WhereHouse fields = [ - 'id', 'name', 'address', 'branch', + 'id', 'name', 'address', ] class WhereHouseCreateSerializer(serializers.Serializer): name = serializers.CharField() address = serializers.CharField() - branch_id = serializers.UUIDField() - - def validate(self, data): - branch = Branch.objects.filter(id=data.get('branch_id')).first() - if not branch: - raise serializers.ValidationError("Branch not found") - data['branch'] = branch - return data def create(self, validated_data): with transaction.atomic(): return WhereHouse.objects.create( name=validated_data.get('name'), address=validated_data.get('address'), - branch=validated_data.get('branch'), ) @@ -53,12 +40,11 @@ class WhereHouseUpdateSerializer(serializers.ModelSerializer): class Meta: model = WhereHouse fields = [ - 'name', 'address', 'branch' + 'name', 'address', ] def update(self, instance, validated_data): instance.name = validated_data.get('name', instance.name) instance.address = validated_data.get('address', instance.address) - instance.branch = validated_data.get('branch', instance.branch) instance.save() return instance diff --git a/core/apps/wherehouse/views/wherehouse.py b/core/apps/wherehouse/views/wherehouse.py index 775ce24..1690c52 100644 --- a/core/apps/wherehouse/views/wherehouse.py +++ b/core/apps/wherehouse/views/wherehouse.py @@ -10,13 +10,13 @@ from core.apps.accounts.permissions.permissions import HasRolePermission class WhereHouseListApiView(generics.ListAPIView): serializer_class = serializers.WhereHouseListSerializer - queryset = WhereHouse.objects.select_related('branch') + queryset = WhereHouse.objects.all() permission_classes = [HasRolePermission] class WhereHouseDetailApiView(generics.RetrieveAPIView): serializer_class = serializers.WhereHouseDetailSerializer - queryset = WhereHouse.objects.select_related('branch') + queryset = WhereHouse.objects.all() permission_classes = [HasRolePermission] lookup_field = 'id'