schon/core/management/commands/fix_prices.py
Egor fureunoir Gorbunov af127045ae Features: None;
Fixes: 1) Update logging configuration to align all logger instances to use "django" instead of "evibes"; 2) Remove unused logging configuration for "django.request";

Extra: 1) Add detailed error logging in GraphQL execution to include exception messages.
2025-07-06 17:22:14 +03:00

23 lines
887 B
Python

import logging
from django.core.management.base import BaseCommand
from core.models import Product
from core.vendors import AbstractVendor
logger = logging.getLogger("django")
class Command(BaseCommand):
def handle(self, *args, **options):
self.stdout.write(self.style.SUCCESS("Starting fixing stocks' prices..."))
for product in Product.objects.filter(stocks__isnull=False):
for stock in product.stocks.all():
try:
stock.price = AbstractVendor.round_price_marketologically(stock.price)
stock.save()
except Exception as e:
self.stdout.write(self.style.WARNING(f"Couldn't fix price on {stock.uuid}"))
self.stdout.write(self.style.WARNING(f"Error: {e}"))
self.stdout.write(self.style.SUCCESS("Successfully fixed stocks' prices!"))