uncloud-mravi/uncloud_pay/management/commands/bootstrap-user.py
2020-08-01 14:05:36 +02:00

40 lines
1.2 KiB
Python

from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
import datetime
from uncloud_pay.models import *
class Command(BaseCommand):
help = 'Bootstrap user (for testing)'
def add_arguments(self, parser):
parser.add_argument('--username', type=str, required=True)
def handle(self, *args, **options):
user = get_user_model().objects.get(username=options['username'])
addr = BillingAddress.objects.get_or_create(
owner=user,
active=True,
defaults={'organization': 'ungleich',
'name': 'Nico Schottelius',
'street': 'Hauptstrasse 14',
'city': 'Luchsingen',
'postal_code': '8775',
'country': 'CH' }
)
bills = Bill.objects.filter(owner=user)
# not even one bill? create!
if bills:
bill = bills[0]
else:
bill = Bill.objects.create(owner=user)
# find any order that is associated to this bill
orders = Order.objects.filter(owner=user)
print(f"Addr: {addr}")
print(f"Bill: {bill}")