Improves creation efficiency

This commit is contained in:
Ludovic Stephan 2017-03-20 20:19:04 -03:00
parent 6d36d50e9a
commit dd4d1f3061
2 changed files with 15 additions and 15 deletions

View file

@ -78,14 +78,15 @@ class Command(BaseCommand):
# Initialize opegroup amount
amount = Decimal('0')
opegroup = OperationGroup(
opegroup = OperationGroup.objects.create(
on_acc=account,
checkout=checkout,
at=at,
is_cof=account.cofprofile.is_cof
)
opegroup.save()
# Generating operations
ope_list = []
for j in range(random.randint(1, 4)):
# Operation type
typevar = random.random()
@ -125,12 +126,12 @@ class Command(BaseCommand):
ope.addcost_amount = addcost_amount * nb
ope.amount -= ope.addcost_amount
opes_created += 1
ope.save()
ope_list.append(ope)
amount += ope.amount
Operation.objects.bulk_create(ope_list)
opes_created += len(ope_list)
opegroup.amount = amount
opegroup.at = at
opegroup.save()
# Transfer generation
@ -146,25 +147,24 @@ class Command(BaseCommand):
else:
comment = ""
transfergroup = TransferGroup(
transfergroup = TransferGroup.objects.create(
at=at,
comment=comment,
valid_by=random.choice(accounts)
)
transfergroup.save()
# Randomly generate transfer
transfer_list = []
for i in range(random.randint(1, 4)):
transfer = Transfer(
transfer_list.append(Transfer(
group=transfergroup,
from_acc=random.choice(accounts),
to_acc=random.choice(accounts),
amount=Decimal(random.randint(1, 99)/10)
)
transfer.save()
transfers += 1
))
transfergroup.at = at
transfergroup.save()
Transfer.objects.bulk_create(transfer_list)
transfers += len(transfer_list)
self.stdout.write(
"- {:d} opérations créées dont {:d} commandes d'articles"

View file

@ -455,7 +455,7 @@ class OrderArticle(models.Model):
quantity_received = models.IntegerField(default = 0)
class TransferGroup(models.Model):
at = models.DateTimeField(auto_now_add = True)
at = models.DateTimeField(default=timezone.now)
# Optional
comment = models.CharField(
max_length = 255,
@ -491,7 +491,7 @@ class OperationGroup(models.Model):
checkout = models.ForeignKey(
Checkout, on_delete = models.PROTECT,
related_name = "opesgroup")
at = models.DateTimeField(auto_now_add = True)
at = models.DateTimeField(default=timezone.now)
amount = models.DecimalField(
max_digits = 6, decimal_places = 2,
default = 0)