add payment type api
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-09-05 18:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('finance', '0003_cashtransactionfolder_cashtransaction_folder'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
name='expence_balance',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
name='income_balance',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
name='total_balance',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-09-05 19:12
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('finance', '0004_cashtransaction_expence_balance_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
old_name='expence_balance',
|
||||||
|
new_name='expence_balance_usd',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
old_name='income_balance',
|
||||||
|
new_name='expence_balance_uzs',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
old_name='total_balance',
|
||||||
|
new_name='income_balance_usd',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
name='income_balance_uzs',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
name='total_balance_usd',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='cashtransaction',
|
||||||
|
name='total_balance_uzs',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -28,6 +28,13 @@ class CashTransaction(BaseModel):
|
|||||||
CashTransactionFolder, on_delete=models.SET_NULL, related_name='cash_transactions',
|
CashTransactionFolder, on_delete=models.SET_NULL, related_name='cash_transactions',
|
||||||
null=True, blank=True
|
null=True, blank=True
|
||||||
)
|
)
|
||||||
|
total_balance_usd = models.PositiveBigIntegerField(default=0)
|
||||||
|
income_balance_usd = models.PositiveBigIntegerField(default=0)
|
||||||
|
expence_balance_usd = models.PositiveBigIntegerField(default=0)
|
||||||
|
|
||||||
|
total_balance_uzs = models.PositiveBigIntegerField(default=0)
|
||||||
|
income_balance_uzs = models.PositiveBigIntegerField(default=0)
|
||||||
|
expence_balance_uzs = models.PositiveBigIntegerField(default=0)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|||||||
12
core/apps/finance/serializers/payment_type.py
Normal file
12
core/apps/finance/serializers/payment_type.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from core.apps.finance.models import PaymentType
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentTypeSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = PaymentType
|
||||||
|
fields = [
|
||||||
|
'id', 'name'
|
||||||
|
]
|
||||||
|
|
||||||
@@ -2,6 +2,7 @@ from django.urls import path, include
|
|||||||
|
|
||||||
from core.apps.finance.views import cash_transaction as cash_views
|
from core.apps.finance.views import cash_transaction as cash_views
|
||||||
from core.apps.finance.views import cash_transaction_folder as folder_views
|
from core.apps.finance.views import cash_transaction_folder as folder_views
|
||||||
|
from core.apps.finance.views import payment_type as pt_views
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -19,4 +20,12 @@ urlpatterns = [
|
|||||||
path('<uuid:id>/update/', folder_views.CashTransactionFolderUpdateApiView.as_view()),
|
path('<uuid:id>/update/', folder_views.CashTransactionFolderUpdateApiView.as_view()),
|
||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
|
path('payment_type/', include(
|
||||||
|
[
|
||||||
|
path('create/', pt_views.PaymentTypeCreateApiView.as_view()),
|
||||||
|
path('list/', pt_views.PaymentListApiView.as_view()),
|
||||||
|
path('<uuid:id>/delete/', pt_views.PaymentDeleteApiView.as_view()),
|
||||||
|
path('<uuid:id>/update/', pt_views.PaymentUpdateApiView.as_view()),
|
||||||
|
]
|
||||||
|
))
|
||||||
]
|
]
|
||||||
56
core/apps/finance/views/payment_type.py
Normal file
56
core/apps/finance/views/payment_type.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
|
from rest_framework import generics, views
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from core.apps.accounts.permissions.permissions import HasRolePermission
|
||||||
|
from core.apps.finance.models import PaymentType
|
||||||
|
from core.apps.finance.serializers.payment_type import PaymentTypeSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentTypeCreateApiView(generics.GenericAPIView):
|
||||||
|
serializer_class = PaymentTypeSerializer
|
||||||
|
queryset = PaymentType.objects.all()
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
ser = self.serializer_class(data=request.data)
|
||||||
|
if ser.is_valid(raise_exception=True):
|
||||||
|
ser.save()
|
||||||
|
return Response({'success': True}, status=201)
|
||||||
|
return Response(ser.errors, status=400)
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentListApiView(views.APIView):
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
queryset = PaymentType.objects.all()
|
||||||
|
ser = PaymentTypeSerializer(queryset, many=True)
|
||||||
|
return Response(ser.data, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentDeleteApiView(views.APIView):
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
|
||||||
|
def delete(self, request, id):
|
||||||
|
obj = get_object_or_404(PaymentType, id=id)
|
||||||
|
obj.delete()
|
||||||
|
return Response(status=204)
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentUpdateApiView(generics.GenericAPIView):
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
queryset = PaymentType.objects.all()
|
||||||
|
serializer_class = PaymentTypeSerializer
|
||||||
|
|
||||||
|
def patch(self, request, id):
|
||||||
|
obj = get_object_or_404(PaymentType, id=id)
|
||||||
|
ser = self.serializer_class(data=request.data, instance=obj, partial=True)
|
||||||
|
if ser.is_valid():
|
||||||
|
ser.save()
|
||||||
|
return Response({'success': True}, status=200)
|
||||||
|
return Response(ser.errors, status=400)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user