Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed currency issue in faker #32

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions nxtbn/product/management/commands/fake_populate_product.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.conf import settings
from django.core.management.base import BaseCommand
import requests
from nxtbn.core.currency.utils import normalize_amount_currencywise
from nxtbn.product.models import Category, Collection, Product, ProductVariant
from django.contrib.auth import get_user_model
from nxtbn.product import ProductType, StockStatus, WeightUnits
Expand All @@ -8,6 +10,7 @@
from django.core.files.temp import NamedTemporaryFile
from django.core.files import File
import random
from tqdm import tqdm

User = get_user_model()

Expand All @@ -31,7 +34,7 @@ def handle(self, *args, **options):
categories = Category.objects.all()
collections = Collection.objects.all()

for _ in range(num_products):
for _ in tqdm(range(num_products)):
category = random.choice(categories)
collection = random.choice(collections)
product_type = random.choice(ProductType.choices)
Expand Down Expand Up @@ -77,7 +80,8 @@ def handle(self, *args, **options):
default_variant = ProductVariant.objects.create(
product=product,
name='Default',
price=random.uniform(10, 1000),
currency=settings.BASE_CURRENCY,
price=normalize_amount_currencywise(random.uniform(10, 1000), settings.BASE_CURRENCY),
cost_per_unit=random.uniform(5, 500),
compare_at_price=random.uniform(15, 1500),
sku=fake.uuid4(),
Expand All @@ -94,7 +98,8 @@ def handle(self, *args, **options):
variant = ProductVariant.objects.create(
product=product,
name=fake.word(),
price=random.uniform(10, 1000),
currency=settings.BASE_CURRENCY,
price=normalize_amount_currencywise(random.uniform(10, 1000), settings.BASE_CURRENCY),
cost_per_unit=random.uniform(5, 500),
compare_at_price=random.uniform(15, 1500),
sku=fake.uuid4(),
Expand Down