forked from DGNum/gestioCOF
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 os
|
||||||
import random
|
import random
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.contrib.auth.models import User, Group, Permission, ContentType
|
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.management.base import MyBaseCommand
|
||||||
from gestioncof.models import CofProfile
|
from gestioncof.models import CofProfile
|
||||||
from kfet.models import (Account, Article, OperationGroup, Operation,
|
from kfet.models import (Account, Checkout, CheckoutStatement)
|
||||||
Checkout, CheckoutStatement)
|
|
||||||
|
|
||||||
# Où sont stockés les fichiers json
|
# Où sont stockés les fichiers json
|
||||||
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)),
|
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)),
|
||||||
|
@ -130,61 +129,4 @@ class Command(MyBaseCommand):
|
||||||
# Opérations
|
# Opérations
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
self.stdout.write("Génération d'opérations")
|
call_command('createopes','100', '7')
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue