Browse Source

courses pricing updated with only hving rub pricings

master
Mohsen Taba 3 weeks ago
parent
commit
521f1a91f5
  1. 13
      apps/course/models/course.py
  2. 6
      apps/course/serializers/admin.py
  3. 2
      apps/course/views/course.py

13
apps/course/models/course.py

@ -417,24 +417,17 @@ class Course(models.Model):
return self.__class__.recalculate_lessons_count_for_course(self.pk) return self.__class__.recalculate_lessons_count_for_course(self.pk)
def get_currency_for_language(self, lang): def get_currency_for_language(self, lang):
normalized = (lang or 'en').lower()
if normalized.startswith('ru'):
return CURRENCY_RUB
return CURRENCY_USD
return CURRENCY_RUB
def get_price_for_language(self, lang): def get_price_for_language(self, lang):
if self.is_free: if self.is_free:
return Decimal('0.00') return Decimal('0.00')
if self.get_currency_for_language(lang) == CURRENCY_RUB:
return Decimal(self.price_rub or 0)
return Decimal(self.price or 0)
return Decimal(self.price_rub or 0)
def get_final_price_for_language(self, lang): def get_final_price_for_language(self, lang):
if self.is_free: if self.is_free:
return Decimal('0.00') return Decimal('0.00')
if self.get_currency_for_language(lang) == CURRENCY_RUB:
return Decimal(self.final_price_rub or 0)
return Decimal(self.final_price or 0)
return Decimal(self.final_price_rub or 0)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

6
apps/course/serializers/admin.py

@ -146,10 +146,8 @@ class AdminCourseListSerializer(serializers.ModelSerializer):
'lessons_count', 'lessons_count',
'status', 'status',
'is_free', 'is_free',
'price',
'price_rub', 'price_rub',
'discount_percentage', 'discount_percentage',
'final_price',
'final_price_rub', 'final_price_rub',
'participant_count', 'participant_count',
'created_at' 'created_at'
@ -220,10 +218,8 @@ class AdminCourseDetailSerializer(serializers.ModelSerializer):
'short_description', 'short_description',
'status', 'status',
'is_free', 'is_free',
'price',
'price_rub', 'price_rub',
'discount_percentage', 'discount_percentage',
'final_price',
'final_price_rub', 'final_price_rub',
'is_group_chat_locked', 'is_group_chat_locked',
'is_professor_chat_locked', 'is_professor_chat_locked',
@ -233,7 +229,7 @@ class AdminCourseDetailSerializer(serializers.ModelSerializer):
'created_at', 'created_at',
'updated_at' 'updated_at'
] ]
read_only_fields = ['id', 'final_price', 'final_price_rub', 'created_at', 'updated_at']
read_only_fields = ['id', 'final_price_rub', 'created_at', 'updated_at']
def get_professor_name(self, obj): def get_professor_name(self, obj):
return ", ".join([p.fullname for p in obj.professors.all()]) return ", ".join([p.fullname for p in obj.professors.all()])

2
apps/course/views/course.py

@ -176,7 +176,7 @@ class CourseListAPIView(ListAPIView):
if is_free := filters.get('is_free'): if is_free := filters.get('is_free'):
is_free = is_free.lower() == 'true' is_free = is_free.lower() == 'true'
queryset = queryset.filter( queryset = queryset.filter(
Q(is_free=is_free) | Q(price=0) if is_free else Q(is_free=False, price__gt=0)
Q(is_free=is_free) | Q(price_rub=0) if is_free else Q(is_free=False, price_rub__gt=0)
) )
if is_online := filters.get('is_online'): if is_online := filters.get('is_online'):
is_online = is_online.lower() == 'true' is_online = is_online.lower() == 'true'

Loading…
Cancel
Save