From 36dc6439a80d5673e518715ff0bbe8a4cc8d2b16 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sun, 19 Mar 2017 16:03:39 -0300 Subject: [PATCH] Plug createopes into loadkfetdevdata --- kfet/management/commands/loadkfetdevdata.py | 64 +-------------------- 1 file changed, 3 insertions(+), 61 deletions(-) diff --git a/kfet/management/commands/loadkfetdevdata.py b/kfet/management/commands/loadkfetdevdata.py index 705f6f27..8eee85a9 100644 --- a/kfet/management/commands/loadkfetdevdata.py +++ b/kfet/management/commands/loadkfetdevdata.py @@ -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')