schon/core/management/commands/fix_prices.py
Egor fureunoir Gorbunov 9898212855 Features: 1) Introduced LoggingError exception for invalid log level handling in log method; 2) Updated logging framework to dynamically initialize loggers using __name__ instead of hardcoded "django".
Fixes: 1) Fixed missing `exc_info` flag in critical and error logs to provide richer error context; 2) Addressed redundant code and unused imports in the logging logic for cleaner execution.

Extra: Refactored `LOGGING` configuration for improved readability and runtime adaptability; optimized related log-handling logic throughout the codebase.
2025-11-04 14:40:50 +03:00

24 lines
945 B
Python

import logging
from typing import Any
from django.core.management.base import BaseCommand
from core.models import Product
from core.vendors import AbstractVendor
logger = logging.getLogger(__name__)
class Command(BaseCommand):
def handle(self, *args: list[Any], **options: dict[Any, Any]) -> None:
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!"))