add different operation types
This commit is contained in:
parent
bb78091cc5
commit
066df73b62
1 changed files with 39 additions and 18 deletions
|
@ -52,12 +52,13 @@ class Command(MyBaseCommand):
|
|||
gaulois_trigramme = map('{:03d}'.format, range(50))
|
||||
|
||||
romains = CofProfile.objects.filter(user__last_name='Romain')
|
||||
romains_trigramme = map(lambda x: str(100+x), range(50))
|
||||
romains_trigramme = map(lambda x: str(100+x), range(99))
|
||||
|
||||
for (profile, trigramme) in zip(gaulois, gaulois_trigramme):
|
||||
account, _ = Account.objects.get_or_create(
|
||||
trigramme=trigramme,
|
||||
cofprofile=profile
|
||||
cofprofile=profile,
|
||||
defaults={'balance': random.randint(1, 999)/10}
|
||||
)
|
||||
|
||||
if profile.user.first_name == 'Abraracourcix':
|
||||
|
@ -66,7 +67,8 @@ class Command(MyBaseCommand):
|
|||
for (profile, trigramme) in zip(romains, romains_trigramme):
|
||||
account, _ = Account.objects.get_or_create(
|
||||
trigramme=trigramme,
|
||||
cofprofile=profile
|
||||
cofprofile=profile,
|
||||
defaults={'balance': random.randint(1, 999)/10}
|
||||
)
|
||||
|
||||
if random.random() > 0.75:
|
||||
|
@ -76,22 +78,27 @@ class Command(MyBaseCommand):
|
|||
|
||||
liq_user, _ = User.objects.get_or_create(username='liquide')
|
||||
liq_profile, _ = CofProfile.objects.get_or_create(user=liq_user)
|
||||
account = Account.objects.get_or_create(cofprofile=liq_profile,
|
||||
trigramme='LIQ')
|
||||
liq_account = Account.objects.get_or_create(cofprofile=liq_profile,
|
||||
trigramme='LIQ')
|
||||
|
||||
# ---
|
||||
# Opérations
|
||||
# ---
|
||||
|
||||
articles = Article.objects.all()
|
||||
accounts = Account.objects.all()
|
||||
accounts = Account.objects.exclude(trigramme='LIQ')
|
||||
checkout = Checkout.objects.all()[0]
|
||||
|
||||
num_op = 100
|
||||
past_date = 3600*24*5
|
||||
# Operations are put uniformly over the span of a week
|
||||
past_date = 3600*24*7
|
||||
|
||||
for i in range(num_op):
|
||||
account = random.choice(accounts)
|
||||
if random.random() > 0.25:
|
||||
account = random.choice(accounts)
|
||||
else:
|
||||
account = liq_account
|
||||
|
||||
amount = 0
|
||||
at = timezone.now() - timedelta(
|
||||
seconds=random.randint(0, past_date))
|
||||
|
@ -105,17 +112,31 @@ class Command(MyBaseCommand):
|
|||
opegroup.save()
|
||||
|
||||
for j in range(random.randint(1, 4)):
|
||||
# For now, all operations are purchases, w/o addcost
|
||||
article = random.choice(articles)
|
||||
nb = random.randint(1, 5)
|
||||
typevar = random.random()
|
||||
if typevar > 0.9 and account != liq_account:
|
||||
ope = Operation(
|
||||
group=opegroup,
|
||||
type=Operation.DEPOSIT,
|
||||
amount=random.randint(1, 99)/10,
|
||||
)
|
||||
elif typevar > 0.8 and account != liq_account:
|
||||
ope = Operation(
|
||||
group=opegroup,
|
||||
type=Operation.WITHDRAW,
|
||||
amount=random.randint(1, 99)/10,
|
||||
)
|
||||
else:
|
||||
article = random.choice(articles)
|
||||
nb = random.randint(1, 5)
|
||||
|
||||
ope = Operation(
|
||||
group=opegroup,
|
||||
type=Operation.PURCHASE,
|
||||
amount=-article.price*nb,
|
||||
article=article,
|
||||
article_nb=nb
|
||||
)
|
||||
|
||||
ope = Operation(
|
||||
group=opegroup,
|
||||
type=Operation.PURCHASE,
|
||||
amount=-article.price*nb,
|
||||
article=article,
|
||||
article_nb=nb
|
||||
)
|
||||
ope.save()
|
||||
amount += ope.amount
|
||||
|
||||
|
|
Loading…
Reference in a new issue