22 lines
718 B
Python
22 lines
718 B
Python
"""Establishment app tasks."""
|
|
import logging
|
|
from celery import shared_task
|
|
from establishment import models
|
|
from location.models import Country
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@shared_task
|
|
def recalculate_price_levels_by_country(country_id):
|
|
try:
|
|
country = Country.objects.get(pk=country_id)
|
|
except Country.DoesNotExist as ex:
|
|
logger.error(f'ESTABLISHMENT. Country does not exist. ID {country_id}')
|
|
else:
|
|
qs = models.Establishment.objects.filter(address__city__country=country)
|
|
for establishment in qs:
|
|
establishment.recalculate_price_level(low_price=country.low_price,
|
|
high_price=country.high_price)
|