Skip to content

Commit

Permalink
fix: product title in EN
Browse files Browse the repository at this point in the history
The product titles are hardcoded in English.
It was added a pre-save on Products to change the title
product's to Portuguese.

related to #30
  • Loading branch information
igobranco committed Oct 22, 2024
1 parent 2dfb644 commit c4d06a5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 12 deletions.
26 changes: 25 additions & 1 deletion nau_extensions/signals.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import re

from django.db.models.signals import pre_save
from django.dispatch import receiver
from nau_extensions.financial_manager import \
send_to_financial_manager_if_enabled
from nau_extensions.models import BasketTransactionIntegration
from oscar.core.loading import get_class
from oscar.core.loading import get_class, get_model

post_checkout = get_class("checkout.signals", "post_checkout")
Product = get_model('catalogue', 'Product')


@receiver(
Expand All @@ -23,3 +27,23 @@ def create_and_send_basket_transaction_integration_to_financial_manager(
bti.save()
bti.refresh_from_db()
send_to_financial_manager_if_enabled(bti)


@receiver(pre_save, sender=Product)
def change_product_titles(sender, instance, *_args, **kwargs):
"""
Change Product title that is hardcoded in English.
So we just find and replace the English words to Portuguese on the Product title field.
Also remove the `verified` word, because on NAU this doesn't make sense.
Hardcoded code locations:
- https://github.com/fccn/ecommerce/blob/132e45e7af964c9addbe97deae6ab4327caa6cce/ecommerce/courses/models.py#L57
- https://github.com/fccn/ecommerce/blob/132e45e7af964c9addbe97deae6ab4327caa6cce/ecommerce/courses/models.py#L295
- https://github.com/fccn/ecommerce/blob/132e45e7af964c9addbe97deae6ab4327caa6cce/ecommerce/courses/models.py#L134
- https://github.com/fccn/ecommerce/blob/132e45e7af964c9addbe97deae6ab4327caa6cce/ecommerce/courses/models.py#L131
"""
new_title = instance.title
new_title = new_title.replace('Seat in', 'Lugar em')
new_title = new_title.replace('Enrollment code for verified seat in', 'Código de inscrição para')
new_title = new_title.replace('with verified certificate', 'com certificado pago')
new_title = new_title.replace('with honor certificate', 'com certificado grátis')
instance.title = new_title
16 changes: 8 additions & 8 deletions nau_extensions/tests/test_financial_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_financial_manager_sync_data_basic(self):
# verified
{
"unit_price_incl_vat": Decimal("10.00"),
"description": "Seat in edX Demonstration Course with verified certificate",
"description": "Lugar em edX Demonstration Course com certificado pago",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
Expand All @@ -110,7 +110,7 @@ def test_financial_manager_sync_data_basic(self):
# honor
{
"unit_price_incl_vat": Decimal("0.00"),
"description": "Seat in edX Demonstration Course with honor certificate",
"description": "Lugar em edX Demonstration Course com certificado grátis",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_financial_manager_sync_data_with_quantity(self):
# verified
{
"unit_price_incl_vat": Decimal("10.00"),
"description": "Seat in edX Demonstration Course with verified certificate",
"description": "Lugar em edX Demonstration Course com certificado pago",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
Expand All @@ -205,7 +205,7 @@ def test_financial_manager_sync_data_with_quantity(self):
# honor
{
"unit_price_incl_vat": Decimal("0.00"),
"description": "Seat in edX Demonstration Course with honor certificate",
"description": "Lugar em edX Demonstration Course com certificado grátis",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
Expand Down Expand Up @@ -289,7 +289,7 @@ def test_financial_manager_sync_data_with_tax_rate(self):
# verified
{
"unit_price_incl_vat": Decimal("10.00"),
"description": "Seat in edX Demonstration Course with verified certificate",
"description": "Lugar em edX Demonstration Course com certificado pago",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
Expand All @@ -300,7 +300,7 @@ def test_financial_manager_sync_data_with_tax_rate(self):
# honor
{
"unit_price_incl_vat": Decimal("0.00"),
"description": "Seat in edX Demonstration Course with honor certificate",
"description": "Lugar em edX Demonstration Course com certificado grátis",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
Expand Down Expand Up @@ -370,7 +370,7 @@ def test_financial_manager_sync_data_without_bbi(self):
# verified
{
"unit_price_incl_vat": Decimal("10.00"),
"description": "Seat in edX Demonstration Course with verified certificate",
"description": "Lugar em edX Demonstration Course com certificado pago",
"discount_excl_tax": Decimal("0.00"),
"discount_incl_tax": Decimal("0.00"),
"organization_code": "edX",
Expand All @@ -381,7 +381,7 @@ def test_financial_manager_sync_data_without_bbi(self):
# honor
{
"unit_price_incl_vat": Decimal("0.00"),
"description": "Seat in edX Demonstration Course with honor certificate",
"description": "Lugar em edX Demonstration Course com certificado grátis",
"discount_excl_tax": Decimal("0.00"),
"discount_incl_tax": Decimal("0.00"),
"organization_code": "edX",
Expand Down
55 changes: 52 additions & 3 deletions nau_extensions/tests/test_signals.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

import mock
from nau_extensions.models import BasketTransactionIntegration
from oscar.core.loading import get_model

from ecommerce.courses.tests.factories import CourseFactory
from ecommerce.extensions.checkout.mixins import EdxOrderPlacementMixin
from ecommerce.extensions.test.factories import create_order
from ecommerce.tests.factories import UserFactory
from ecommerce.tests.factories import PartnerFactory, UserFactory
from ecommerce.tests.testcases import TestCase

Product = get_model('catalogue', 'Product')


class SignalsNAUExtensionsTests(TestCase):
"""
Expand All @@ -22,3 +24,50 @@ def test_signal_receiver_create_and_send_basket_transaction_integration_to_finan
EdxOrderPlacementMixin().handle_successful_order(order)
bti = BasketTransactionIntegration.get_by_basket(order.basket)
self.assertTrue(bti is not None)

def test_change_product_title_verified(self):
"""
Test change the product hardcoded names in english to portuguese versions for verified course run.
"""
partner = PartnerFactory(short_code="edX")
course = CourseFactory(
id="course-v1:edX+DemoX+Demo_Course",
name="edX Demonstration Course",
partner=partner,
)
product = course.create_or_update_seat("verified", False, 1)
product.save()
product.refresh_from_db()
self.assertEqual(product.title, "Lugar em edX Demonstration Course com certificado pago")
self.assertEqual(product.parent.title, "Lugar em edX Demonstration Course")

def test_change_product_title_honor(self):
"""
Test change the product hardcoded names in english to portuguese versions for `honor` course run.
"""
partner = PartnerFactory(short_code="edX")
course = CourseFactory(
id="course-v1:edX+DemoX+Demo_Course",
name="edX Demonstration Course",
partner=partner,
)
honor_product = course.create_or_update_seat("honor", False, 0)
honor_product.save()
honor_product.refresh_from_db()
self.assertEqual(honor_product.title, "Lugar em edX Demonstration Course com certificado grátis")
self.assertEqual(honor_product.parent.title, "Lugar em edX Demonstration Course")

def test_change_product_title_enrollment_code(self):
"""
Test change the product hardcoded names in english to portuguese versions for verified course run.
"""
partner = PartnerFactory(short_code="edX")
course = CourseFactory(
id="course-v1:edX+DemoX+Demo_Course",
name="edX Demonstration Course",
partner=partner,
)
product = course.create_or_update_seat("verified", False, 1, create_enrollment_code=True)
product.save()
enrollment_code = course.get_enrollment_code()
self.assertEqual(enrollment_code.title, "Código de inscrição para edX Demonstration Course")

0 comments on commit c4d06a5

Please sign in to comment.