Generate dummy baskets with no fixed price items

This commit is contained in:
Gabriel Augendre 2023-03-27 18:28:14 +02:00
parent 0f0e4f854a
commit e3bb57396b
2 changed files with 29 additions and 8 deletions

View file

@ -75,5 +75,16 @@
"unit_price_cents": 290,
"display_order": 7
}
},
{
"model": "purchase.product",
"fields": {
"created_at": "2022-04-28T16:08:20.471Z",
"updated_at": "2022-04-28T16:09:34.003Z",
"name": "Tomme de ch\u00e8vre",
"image": "",
"unit_price_cents": 0,
"display_order": 8
}
}
]

View file

@ -52,13 +52,23 @@ class Command(BaseCommand):
)
items = []
for product in selected_products:
items.append(
BasketItem(
product=product,
basket=basket,
quantity=random.randint(1, 3),
unit_price_cents=product.unit_price_cents,
),
)
if not product.has_fixed_price:
items.append(
BasketItem(
product=product,
basket=basket,
quantity=1,
unit_price_cents=random.randint(317, 514),
),
)
else:
items.append(
BasketItem(
product=product,
basket=basket,
quantity=random.randint(1, 3),
unit_price_cents=product.unit_price_cents,
),
)
BasketItem.objects.bulk_create(items)
return count