* Renamed GlobalSettings.get_yuan_rate -> full_yuan_rate property
* In GlobalSettingsSerializer show full yuan rate
This commit is contained in:
parent
46de21309f
commit
e5e93ab6d5
|
|
@ -66,7 +66,8 @@ class GlobalSettings(models.Model):
|
|||
InMemoryCache.set('GlobalSettings', obj)
|
||||
return obj
|
||||
|
||||
def get_yuan_rate(self):
|
||||
@property
|
||||
def full_yuan_rate(self):
|
||||
""" Get rate either from CurrencyAPI or from DB (if fresh enough) """
|
||||
if self.yuan_rate_last_updated is not None:
|
||||
diff_minutes = (timezone.now() - self.yuan_rate_last_updated).total_seconds() / 60
|
||||
|
|
@ -294,7 +295,7 @@ class ChecklistQuerySet(models.QuerySet):
|
|||
return self.annotate(
|
||||
_yuan_rate=Case(
|
||||
When(price_snapshot_id__isnull=False, then=F('price_snapshot__yuan_rate')),
|
||||
default=GlobalSettings.load().get_yuan_rate()
|
||||
default=GlobalSettings.load().full_yuan_rate
|
||||
),
|
||||
_price_rub=Ceil(F('_yuan_rate') * F('price_yuan'))
|
||||
)
|
||||
|
|
@ -471,7 +472,7 @@ class Checklist(models.Model):
|
|||
if self.price_snapshot_id:
|
||||
yuan_rate = self.price_snapshot.yuan_rate
|
||||
else:
|
||||
yuan_rate = GlobalSettings.load().get_yuan_rate()
|
||||
yuan_rate = GlobalSettings.load().full_yuan_rate
|
||||
|
||||
return math.ceil(yuan_rate * self.price_yuan)
|
||||
|
||||
|
|
@ -506,7 +507,7 @@ class Checklist(models.Model):
|
|||
if self.price_snapshot_id:
|
||||
return self.price_snapshot.yuan_rate
|
||||
else:
|
||||
return GlobalSettings.load().get_yuan_rate()
|
||||
return GlobalSettings.load().full_yuan_rate
|
||||
|
||||
@property
|
||||
def delivery_price_CN(self) -> Decimal:
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ class AnonymousUserChecklistSerializer(ChecklistSerializer):
|
|||
|
||||
|
||||
class GlobalSettingsSerializer(serializers.ModelSerializer):
|
||||
currency = serializers.DecimalField(source='yuan_rate', read_only=True, max_digits=10, decimal_places=2)
|
||||
currency = serializers.DecimalField(source='full_yuan_rate', read_only=True, max_digits=10, decimal_places=2)
|
||||
yuan_rate_last_updated = serializers.DateTimeField(read_only=True)
|
||||
chinadelivery = serializers.DecimalField(source='delivery_price_CN', max_digits=10, decimal_places=2)
|
||||
commission = serializers.DecimalField(source='commission_rub', max_digits=10, decimal_places=2)
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ class StatisticsAPI(viewsets.GenericViewSet):
|
|||
@action(url_path='orders', detail=False, methods=['get'])
|
||||
def stats_by_orders(self, request, *args, **kwargs):
|
||||
global_settings = GlobalSettings.load()
|
||||
yuan_rate = global_settings.get_yuan_rate()
|
||||
yuan_rate = global_settings.full_yuan_rate
|
||||
|
||||
# Prepare query to collect the stats
|
||||
qs = self.get_queryset() \
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user