add different operation types

This commit is contained in:
Ludovic Stephan 2017-02-08 15:11:38 -02:00
parent bb78091cc5
commit 066df73b62

View file

@ -52,12 +52,13 @@ class Command(MyBaseCommand):
gaulois_trigramme = map('{:03d}'.format, range(50)) gaulois_trigramme = map('{:03d}'.format, range(50))
romains = CofProfile.objects.filter(user__last_name='Romain') 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): for (profile, trigramme) in zip(gaulois, gaulois_trigramme):
account, _ = Account.objects.get_or_create( account, _ = Account.objects.get_or_create(
trigramme=trigramme, trigramme=trigramme,
cofprofile=profile cofprofile=profile,
defaults={'balance': random.randint(1, 999)/10}
) )
if profile.user.first_name == 'Abraracourcix': if profile.user.first_name == 'Abraracourcix':
@ -66,7 +67,8 @@ class Command(MyBaseCommand):
for (profile, trigramme) in zip(romains, romains_trigramme): for (profile, trigramme) in zip(romains, romains_trigramme):
account, _ = Account.objects.get_or_create( account, _ = Account.objects.get_or_create(
trigramme=trigramme, trigramme=trigramme,
cofprofile=profile cofprofile=profile,
defaults={'balance': random.randint(1, 999)/10}
) )
if random.random() > 0.75: if random.random() > 0.75:
@ -76,22 +78,27 @@ class Command(MyBaseCommand):
liq_user, _ = User.objects.get_or_create(username='liquide') liq_user, _ = User.objects.get_or_create(username='liquide')
liq_profile, _ = CofProfile.objects.get_or_create(user=liq_user) liq_profile, _ = CofProfile.objects.get_or_create(user=liq_user)
account = Account.objects.get_or_create(cofprofile=liq_profile, liq_account = Account.objects.get_or_create(cofprofile=liq_profile,
trigramme='LIQ') trigramme='LIQ')
# --- # ---
# Opérations # Opérations
# --- # ---
articles = Article.objects.all() articles = Article.objects.all()
accounts = Account.objects.all() accounts = Account.objects.exclude(trigramme='LIQ')
checkout = Checkout.objects.all()[0] checkout = Checkout.objects.all()[0]
num_op = 100 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): 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 amount = 0
at = timezone.now() - timedelta( at = timezone.now() - timedelta(
seconds=random.randint(0, past_date)) seconds=random.randint(0, past_date))
@ -105,17 +112,31 @@ class Command(MyBaseCommand):
opegroup.save() opegroup.save()
for j in range(random.randint(1, 4)): for j in range(random.randint(1, 4)):
# For now, all operations are purchases, w/o addcost typevar = random.random()
article = random.choice(articles) if typevar > 0.9 and account != liq_account:
nb = random.randint(1, 5) 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() ope.save()
amount += ope.amount amount += ope.amount