24 lines
959 B
Python
24 lines
959 B
Python
import logging
|
|
from typing import Any
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from engine.core.models import Product
|
|
from engine.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!"))
|