create bank account for organization
This commit is contained in:
@@ -321,6 +321,21 @@ class BankAccountViewSet(ModelViewSet):
|
||||
queryset = BankAccountInformation.objects.all()
|
||||
serializer_class = BankAccountSerializer
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" add bank account for each organization """
|
||||
|
||||
if 'organization' not in request.data.keys():
|
||||
organization = get_organization_by_user(request.user)
|
||||
request.data.update({'organization': organization.id})
|
||||
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
serializer.save()
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
|
||||
class GeneralOTPViewSet(ModelViewSet):
|
||||
""" general OTP user authorization """
|
||||
|
||||
@@ -48,6 +48,8 @@ class BankAccountSerializer(serializers.ModelSerializer):
|
||||
fields = [
|
||||
'id',
|
||||
'user',
|
||||
'organization',
|
||||
'account_type',
|
||||
'account',
|
||||
'name',
|
||||
'card',
|
||||
@@ -55,6 +57,8 @@ class BankAccountSerializer(serializers.ModelSerializer):
|
||||
]
|
||||
extra_kwargs = {
|
||||
'user': {'required': False},
|
||||
'organization': {'required': False},
|
||||
'account_type': {'required': False},
|
||||
'account': {'required': False},
|
||||
'card': {'required': False},
|
||||
'sheba': {'required': False}
|
||||
@@ -64,6 +68,8 @@ class BankAccountSerializer(serializers.ModelSerializer):
|
||||
""" update user bank account information """
|
||||
instance.name = validated_data.get('name', instance.name)
|
||||
instance.account = validated_data.get('account', instance.account)
|
||||
instance.organization = validated_data.get('organization', instance.organization)
|
||||
instance.account_type = validated_data.get('account_type', instance.account_type)
|
||||
instance.card = validated_data.get('card', instance.card)
|
||||
instance.sheba = validated_data.get('sheba', instance.sheba)
|
||||
instance.save()
|
||||
|
||||
@@ -13,6 +13,7 @@ from .api import (
|
||||
ProvinceViewSet,
|
||||
OrganizationViewSet,
|
||||
OrganizationTypeViewSet,
|
||||
BankAccountViewSet,
|
||||
GeneralOTPViewSet,
|
||||
LogoutView
|
||||
)
|
||||
@@ -23,11 +24,12 @@ router.register(r'city', CityViewSet, basename='city')
|
||||
router.register(r'province', ProvinceViewSet, basename='province')
|
||||
router.register(r'organization', OrganizationViewSet, basename='organization')
|
||||
router.register(r'organization-type', OrganizationTypeViewSet, basename='organization_type')
|
||||
router.register(r'bank_account', BankAccountViewSet, basename='bank_account')
|
||||
router.register(r'otp', GeneralOTPViewSet, basename='otp')
|
||||
|
||||
urlpatterns = [
|
||||
path('login/', CustomizedTokenObtainPairView.as_view(), name='token_obtain_pair'),
|
||||
path('logout/', LogoutView.as_view(), name='logut'),
|
||||
path('logout/', LogoutView.as_view(), name='logout'),
|
||||
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
||||
path('token/verify/', TokenVerifyView.as_view(), name='token_verify'),
|
||||
path('token/revoke/', TokenBlacklistView.as_view(), name='revoke_token'),
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0 on 2025-08-06 11:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0027_remove_organizationstats_total_buyers_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='bankaccountinformation',
|
||||
name='account_type',
|
||||
field=models.CharField(default='USR', max_length=10),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0 on 2025-08-06 12:31
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0028_bankaccountinformation_account_type'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='bankaccountinformation',
|
||||
name='organization',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='bank_information', to='authentication.organization'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.0 on 2025-08-06 12:32
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0029_bankaccountinformation_organization'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='bankaccountinformation',
|
||||
name='user',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='bank_information', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
@@ -161,8 +161,20 @@ class BankAccountInformation(BaseModel):
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="bank_information"
|
||||
related_name="bank_information",
|
||||
null=True
|
||||
)
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='bank_information',
|
||||
null=True
|
||||
)
|
||||
type_choices = (
|
||||
('ORG', 'organization'),
|
||||
('USR', 'user'),
|
||||
)
|
||||
account_type = models.CharField(max_length=10, default='USR')
|
||||
name = models.CharField(max_length=150)
|
||||
card = models.CharField(max_length=25, unique=True)
|
||||
account = models.CharField(max_length=25, unique=True)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0 on 2025-08-06 11:48
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pos_device', '0040_alter_deviceactivationcode_expires_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deviceactivationcode',
|
||||
name='expires_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2025, 8, 6, 15, 18, 11, 325715)),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0 on 2025-08-06 12:31
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pos_device', '0041_alter_deviceactivationcode_expires_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deviceactivationcode',
|
||||
name='expires_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2025, 8, 6, 16, 1, 24, 371720)),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0 on 2025-08-06 12:32
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pos_device', '0042_alter_deviceactivationcode_expires_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deviceactivationcode',
|
||||
name='expires_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2025, 8, 6, 16, 2, 15, 965402)),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0 on 2025-08-06 12:33
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pos_device', '0043_alter_deviceactivationcode_expires_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deviceactivationcode',
|
||||
name='expires_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2025, 8, 6, 16, 3, 12, 730390)),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user