Skip to content

Commit

Permalink
Merge pull request #3512 from stephenmoloney/fix/populate-db-currency
Browse files Browse the repository at this point in the history
Fix for populatedb and currency issue
  • Loading branch information
maarcingebala committed Jan 9, 2019
2 parents 511e85a + eaa4924 commit 04a15be
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions saleor/core/utils/random_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def create_products(products_data, placeholder_dir, create_images):
defaults['weight'] = get_weight(defaults['weight'])
defaults['category_id'] = defaults.pop('category')
defaults['product_type_id'] = defaults.pop('product_type')
defaults['price'] = get_in_default_currency(
defaults, 'price', settings.DEFAULT_CURRENCY)
defaults['attributes'] = json.loads(defaults['attributes'])
product, _ = Product.objects.update_or_create(pk=pk, defaults=defaults)

Expand All @@ -203,9 +205,19 @@ def create_product_variants(variants_data):
continue
defaults['product_id'] = product_id
defaults['attributes'] = json.loads(defaults['attributes'])
defaults['price_override'] = get_in_default_currency(
defaults, 'price_override', settings.DEFAULT_CURRENCY)
defaults['cost_price'] = get_in_default_currency(
defaults, 'cost_price', settings.DEFAULT_CURRENCY)
ProductVariant.objects.update_or_create(pk=pk, defaults=defaults)


def get_in_default_currency(defaults, field, currency):
if field in defaults and defaults[field] is not None:
return Money(defaults[field].amount, currency)
return None


def create_products_by_schema(placeholder_dir, create_images):
path = os.path.join(settings.PROJECT_ROOT, 'saleor', 'static', 'db.json')
with open(path) as f:
Expand Down

0 comments on commit 04a15be

Please sign in to comment.