Fix IntegrityError on Wallet, SupplierProfile, and dummy data creation during user registration
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 49s
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 49s
This commit is contained in:
parent
3092b10cc7
commit
6d07eda7eb
1 changed files with 62 additions and 46 deletions
|
|
@ -115,79 +115,95 @@ class RegisterSerializer(serializers.Serializer):
|
|||
email=validated_data['email'],
|
||||
password=validated_data['password']
|
||||
)
|
||||
SupplierProfile.objects.create(
|
||||
SupplierProfile.objects.update_or_create(
|
||||
user=user,
|
||||
phone=validated_data['phone'],
|
||||
status='unverified'
|
||||
defaults={
|
||||
'phone': validated_data['phone'],
|
||||
'status': 'unverified'
|
||||
}
|
||||
)
|
||||
|
||||
is_test_user = validated_data['email'].startswith('test_seller_') or validated_data['username'] == 'demo_seller'
|
||||
|
||||
wallet = Wallet.objects.create(
|
||||
wallet, _ = Wallet.objects.update_or_create(
|
||||
supplier=user,
|
||||
outstanding=850.00 if is_test_user else 0.00,
|
||||
withdrawn=1250.00 if is_test_user else 0.00
|
||||
defaults={
|
||||
'outstanding': 850.00 if is_test_user else 0.00,
|
||||
'withdrawn': 1250.00 if is_test_user else 0.00
|
||||
}
|
||||
)
|
||||
|
||||
if is_test_user:
|
||||
# Seed default products
|
||||
Product.objects.create(
|
||||
supplier=user,
|
||||
title='Silk Scarf',
|
||||
category='Apparel',
|
||||
price=45.00,
|
||||
stock=25,
|
||||
Product.objects.update_or_create(
|
||||
sku=f'APP-SILK-{user.id}',
|
||||
image='https://images.unsplash.com/photo-1544022613-e87ca75a784a?auto=format&fit=crop&q=80&w=100'
|
||||
defaults={
|
||||
'supplier': user,
|
||||
'title': 'Silk Scarf',
|
||||
'category': 'Apparel',
|
||||
'price': 45.00,
|
||||
'stock': 25,
|
||||
'image': 'https://images.unsplash.com/photo-1544022613-e87ca75a784a?auto=format&fit=crop&q=80&w=100'
|
||||
}
|
||||
)
|
||||
|
||||
# Seed default orders
|
||||
Order.objects.create(
|
||||
supplier=user,
|
||||
Order.objects.update_or_create(
|
||||
order_id=f'OR-8721-{user.id}',
|
||||
date='2026-08-05',
|
||||
item='Handmade Wool Blanket',
|
||||
quantity=1,
|
||||
customer='Alice Smith',
|
||||
total=85.00,
|
||||
status='Pending Acceptance'
|
||||
defaults={
|
||||
'supplier': user,
|
||||
'date': '2026-08-05',
|
||||
'item': 'Handmade Wool Blanket',
|
||||
'quantity': 1,
|
||||
'customer': 'Alice Smith',
|
||||
'total': 85.00,
|
||||
'status': 'Pending Acceptance'
|
||||
}
|
||||
)
|
||||
Order.objects.create(
|
||||
supplier=user,
|
||||
Order.objects.update_or_create(
|
||||
order_id=f'ORD-8501-{user.id}',
|
||||
date='2026-08-08',
|
||||
item='Brass Elephant Figurine',
|
||||
quantity=1,
|
||||
customer='Bruce Wayne',
|
||||
total=120.00,
|
||||
status='Pending Acceptance'
|
||||
defaults={
|
||||
'supplier': user,
|
||||
'date': '2026-08-08',
|
||||
'item': 'Brass Elephant Figurine',
|
||||
'quantity': 1,
|
||||
'customer': 'Bruce Wayne',
|
||||
'total': 120.00,
|
||||
'status': 'Pending Acceptance'
|
||||
}
|
||||
)
|
||||
|
||||
# Seed default returns
|
||||
ReturnRequest.objects.create(
|
||||
supplier=user,
|
||||
ReturnRequest.objects.update_or_create(
|
||||
return_id=f'RET-5510-{user.id}',
|
||||
order_id=f'OR-3920-{user.id}',
|
||||
customer='Bob Johnson',
|
||||
item='Silk Scarf',
|
||||
reason='Ordered wrong color variant.',
|
||||
status='Pending Approval'
|
||||
defaults={
|
||||
'supplier': user,
|
||||
'order_id': f'OR-3920-{user.id}',
|
||||
'customer': 'Bob Johnson',
|
||||
'item': 'Silk Scarf',
|
||||
'reason': 'Ordered wrong color variant.',
|
||||
'status': 'Pending Approval'
|
||||
}
|
||||
)
|
||||
|
||||
# Seed default wallet transactions
|
||||
WalletTransaction.objects.create(
|
||||
wallet=wallet,
|
||||
WalletTransaction.objects.update_or_create(
|
||||
tx_id=f'TX-9031-{user.id}',
|
||||
date='2026-08-01',
|
||||
amount=500.00,
|
||||
status='Transferred'
|
||||
defaults={
|
||||
'wallet': wallet,
|
||||
'date': '2026-08-01',
|
||||
'amount': 500.00,
|
||||
'status': 'Transferred'
|
||||
}
|
||||
)
|
||||
WalletTransaction.objects.create(
|
||||
wallet=wallet,
|
||||
WalletTransaction.objects.update_or_create(
|
||||
tx_id=f'TX-9022-{user.id}',
|
||||
date='2026-07-15',
|
||||
amount=750.00,
|
||||
status='Transferred'
|
||||
defaults={
|
||||
'wallet': wallet,
|
||||
'date': '2026-07-15',
|
||||
'amount': 750.00,
|
||||
'status': 'Transferred'
|
||||
}
|
||||
)
|
||||
|
||||
return user
|
||||
|
|
|
|||
Loading…
Reference in a new issue