schon/core/management/commands/fix_prices.py
Egor fureunoir Gorbunov 6ee3870ab0 Features: 1) Add a management command to fix product stock prices; 2) Introduce 'products' field to CategoryType in GraphQL schema to fetch products associated with a category; 3) Enable GraphQL resolvers to utilize type hinting for better clarity.
Fixes: 1) Correct multiple unaligned code blocks in various Python scripts and GraphQL resolvers; 2) Improve condition formatting for readability in mutations and queries; 3) Resolve missing related_name in product model.

Extra: Simplify and refactor Windows scripts removing legacy spinner logic for clarity and better user feedback; adjust spacing, comments, and formatting across various files; update imports for unused QuerySet.
2025-06-17 11:13:11 +03:00

23 lines
881 B
Python

import logging
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, **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:
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!"))