From 246363826a06e195a572fd90f6048685c9fa9027 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 30 Sep 2025 15:09:05 +0330 Subject: [PATCH] add item share to transaction item --- .../0075_posfreeproducts_company_fee.py | 18 ++++++++++++++++++ apps/pos_device/models.py | 1 + .../api/v1/serializers/product_serializers.py | 2 ++ .../product/pos/api/v1/viewsets/product_api.py | 16 +++++++++++++++- .../0037_inventoryquotasaleitem_item_share.py | 18 ++++++++++++++++++ apps/warehouse/models.py | 1 + 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 apps/pos_device/migrations/0075_posfreeproducts_company_fee.py create mode 100644 apps/warehouse/migrations/0037_inventoryquotasaleitem_item_share.py diff --git a/apps/pos_device/migrations/0075_posfreeproducts_company_fee.py b/apps/pos_device/migrations/0075_posfreeproducts_company_fee.py new file mode 100644 index 0000000..efa230c --- /dev/null +++ b/apps/pos_device/migrations/0075_posfreeproducts_company_fee.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0 on 2025-09-30 08:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pos_device', '0074_stakeholders_default'), + ] + + operations = [ + migrations.AddField( + model_name='posfreeproducts', + name='company_fee', + field=models.IntegerField(default=0), + ), + ] diff --git a/apps/pos_device/models.py b/apps/pos_device/models.py index 0703417..8bcf708 100644 --- a/apps/pos_device/models.py +++ b/apps/pos_device/models.py @@ -327,6 +327,7 @@ class POSFreeProducts(BaseModel): ) balance = models.PositiveIntegerField(default=0) price = models.PositiveIntegerField(default=0) + company_fee = models.IntegerField(default=0) def __str__(self): return f'{self.product.name}-{self.organization.name}' diff --git a/apps/product/pos/api/v1/serializers/product_serializers.py b/apps/product/pos/api/v1/serializers/product_serializers.py index 63c0a5d..c958006 100644 --- a/apps/product/pos/api/v1/serializers/product_serializers.py +++ b/apps/product/pos/api/v1/serializers/product_serializers.py @@ -33,6 +33,8 @@ class POSFreeProductSerializer(serializers.ModelSerializer): 'id': instance.product.id } + representation['total_price'] = instance.price + instance.company_fee + return representation diff --git a/apps/product/pos/api/v1/viewsets/product_api.py b/apps/product/pos/api/v1/viewsets/product_api.py index a604f45..8c6edd9 100644 --- a/apps/product/pos/api/v1/viewsets/product_api.py +++ b/apps/product/pos/api/v1/viewsets/product_api.py @@ -102,7 +102,10 @@ class POSFreeProductsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSear organization = self.get_device_organization() device = self.get_pos_device() - request.data.update({'organization': organization.id, 'device': device.id}) + request.data.update({ + 'organization': organization.id, + 'device': device.id, + }) serializer = product_serializers.POSFreeProductSerializer(data=request.data) if serializer.is_valid(): @@ -110,3 +113,14 @@ class POSFreeProductsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSear return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN) + + @action( + methods=['post'], + detail=False, + url_path='set_fee', + url_name='set_fee', + name='set_fee' + ) + @transaction.atomic() + def set_company_fee_on_product(self, request): + pass diff --git a/apps/warehouse/migrations/0037_inventoryquotasaleitem_item_share.py b/apps/warehouse/migrations/0037_inventoryquotasaleitem_item_share.py new file mode 100644 index 0000000..2a27a8b --- /dev/null +++ b/apps/warehouse/migrations/0037_inventoryquotasaleitem_item_share.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0 on 2025-09-30 11:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('warehouse', '0036_inventoryquotasaleitem_inventory_calculation'), + ] + + operations = [ + migrations.AddField( + model_name='inventoryquotasaleitem', + name='item_share', + field=models.JSONField(default=dict), + ), + ] diff --git a/apps/warehouse/models.py b/apps/warehouse/models.py index f6c9b13..6179daa 100644 --- a/apps/warehouse/models.py +++ b/apps/warehouse/models.py @@ -179,6 +179,7 @@ class InventoryQuotaSaleItem(BaseModel): is_pre_sale = models.BooleanField(default=False) additional = models.JSONField(default=dict) livestock_statistic = models.JSONField(default=dict) + item_share = models.JSONField(default=dict) inventory_calculation = models.BooleanField(default=False) @property