Plug createopes into loadkfetdevdata
This commit is contained in:
parent
0356ec34ae
commit
36dc6439a8
1 changed files with 3 additions and 61 deletions
|
@ -5,15 +5,14 @@ Crée des utilisateurs, des articles et des opérations aléatoires
|
|||
import os
|
||||
import random
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.models import User, Group, Permission, ContentType
|
||||
from django.core.management import call_command
|
||||
|
||||
from gestioncof.management.base import MyBaseCommand
|
||||
from gestioncof.models import CofProfile
|
||||
from kfet.models import (Account, Article, OperationGroup, Operation,
|
||||
Checkout, CheckoutStatement)
|
||||
from kfet.models import (Account, Checkout, CheckoutStatement)
|
||||
|
||||
# Où sont stockés les fichiers json
|
||||
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)),
|
||||
|
@ -130,61 +129,4 @@ class Command(MyBaseCommand):
|
|||
# Opérations
|
||||
# ---
|
||||
|
||||
self.stdout.write("Génération d'opérations")
|
||||
|
||||
articles = Article.objects.all()
|
||||
accounts = Account.objects.exclude(trigramme='LIQ')
|
||||
|
||||
num_op = 100
|
||||
# Operations are put uniformly over the span of a week
|
||||
past_date = 3600*24*7
|
||||
|
||||
for i in range(num_op):
|
||||
if random.random() > 0.25:
|
||||
account = random.choice(accounts)
|
||||
else:
|
||||
account = liq_account
|
||||
|
||||
amount = Decimal('0')
|
||||
at = timezone.now() - timedelta(
|
||||
seconds=random.randint(0, past_date))
|
||||
|
||||
opegroup = OperationGroup(
|
||||
on_acc=account,
|
||||
checkout=checkout,
|
||||
at=at,
|
||||
is_cof=account.cofprofile.is_cof)
|
||||
|
||||
opegroup.save()
|
||||
|
||||
for j in range(random.randint(1, 4)):
|
||||
typevar = random.random()
|
||||
if typevar > 0.9 and account != liq_account:
|
||||
ope = Operation(
|
||||
group=opegroup,
|
||||
type=Operation.DEPOSIT,
|
||||
amount=Decimal(random.randint(1, 99)/10,)
|
||||
)
|
||||
elif typevar > 0.8 and account != liq_account:
|
||||
ope = Operation(
|
||||
group=opegroup,
|
||||
type=Operation.WITHDRAW,
|
||||
amount=-Decimal(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.save()
|
||||
amount += ope.amount
|
||||
|
||||
opegroup.amount = amount
|
||||
opegroup.save()
|
||||
call_command('createopes','100', '7')
|
||||
|
|
Loading…
Reference in a new issue