Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Feat: Upgrade django-oscar to version 3.2 (#4023)
Browse files Browse the repository at this point in the history
* feat: changes to upgrad django-oscar to version 3.2

* chore: upgraded django oscar to version 3.2
  • Loading branch information
zubair-ce07 authored Oct 24, 2023
1 parent 83045eb commit 4d275df
Show file tree
Hide file tree
Showing 93 changed files with 1,766 additions and 1,127 deletions.
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def django_db_setup(django_db_setup, django_db_blocker, django_db_use_migrations
Option.objects.get_or_create(
name='Course Entitlement',
code='course_entitlement',
type=Option.OPTIONAL,
)

coupon, _ = ProductClass.objects.get_or_create(
Expand Down
4 changes: 4 additions & 0 deletions db_keyword_overrides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ MYSQL:
- ShippingEvent.lines
- PaymentEvent.lines
- ProductAlert.key
- HistoricalOption.order
- Option.order
SNOWFLAKE:
- HistoricalOption.order
- Option.order
STITCH:
4 changes: 2 additions & 2 deletions ecommerce/core/management/commands/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from oscar.core.loading import get_model


class PaymentEventFactory(factory.DjangoModelFactory):
class PaymentEventFactory(factory.django.DjangoModelFactory):
id = FuzzyInteger(1000, 999999)

class Meta:
model = get_model('order', 'PaymentEvent')


class SuperUserFactory(factory.DjangoModelFactory):
class SuperUserFactory(factory.django.DjangoModelFactory):
id = FuzzyInteger(1000, 999999)
is_superuser = True
lms_user_id = 56765
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/core/tests/test_create_demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def assert_seats_created(self, course_id, course_title, price):
audit_seat = seats[1]
self.assertFalse(hasattr(audit_seat.attr, 'certificate_type'))
self.assertFalse(audit_seat.attr.id_verification_required)
self.assertEqual(audit_seat.stockrecords.get(partner=self.partner).price_excl_tax, 0)
self.assertEqual(audit_seat.stockrecords.get(partner=self.partner).price, 0)

verified_seat = seats[0]
self.assertEqual(verified_seat.attr.certificate_type, 'verified')
self.assertTrue(verified_seat.attr.id_verification_required)
self.assertEqual(verified_seat.stockrecords.get(partner=self.partner).price_excl_tax, price)
self.assertEqual(verified_seat.stockrecords.get(partner=self.partner).price, price)

@responses.activate
def test_handle(self):
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/core/tests/test_generate_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ def test_create_seat(self, seat_type, mock_logger):
course = Course.objects.get(id='course-v1:test-course-generator+1+1')
seats = course.seat_products
seat = seats[0]
self.assertEqual(seat.stockrecords.get(partner=self.partner).price_excl_tax, price)
self.assertEqual(seat.stockrecords.get(partner=self.partner).price, price)
mock_logger.info.assert_any_call("%s has been set to %s", seat_type, True)
12 changes: 6 additions & 6 deletions ecommerce/coupons/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_is_voucher_applied(self):
"""
Verify is_voucher_applied return correct value.
"""
product = ProductFactory(stockrecords__price_excl_tax=100)
product = ProductFactory(stockrecords__price=100)
voucher, product = prepare_voucher(
_range=RangeFactory(products=[product]),
benefit_value=10
Expand Down Expand Up @@ -92,31 +92,31 @@ def test_fetch_course_catalog(self):
'start_datetime': datetime(2012, 11, 15, 1, 30, tzinfo=UTC),
'end_datetime': datetime(2013, 7, 10, 6, 2, tzinfo=UTC),
'timezone_now': datetime(2013, 1, 1, 1, 1, tzinfo=UTC),
'coupon_available': True
'coupon_available': True,
},
{
'start_datetime': datetime(2012, 11, 15, 1, 30, tzinfo=UTC),
'end_datetime': datetime(2013, 7, 10, 6, 2, tzinfo=UTC),
'timezone_now': datetime(2014, 1, 1, 1, 1, tzinfo=UTC),
'coupon_available': False
'coupon_available': False,
},
{
'start_datetime': datetime(2012, 11, 15, 1, 30, tzinfo=UTC),
'end_datetime': datetime(2013, 7, 10, 6, 2, tzinfo=UTC),
'timezone_now': datetime(2011, 1, 1, 1, 1, tzinfo=UTC),
'coupon_available': False
'coupon_available': False,
},
{
'start_datetime': datetime(2012, 11, 15, 1, 30, tzinfo=UTC),
'end_datetime': datetime(2012, 11, 15, 1, 30, tzinfo=UTC),
'timezone_now': datetime(2012, 11, 15, 1, 30, tzinfo=UTC),
'coupon_available': False
'coupon_available': False,
},
{
'start_datetime': datetime(2012, 11, 15, 1, 30, tzinfo=UTC),
'end_datetime': datetime(2012, 11, 15, 1, 40, tzinfo=UTC),
'timezone_now': datetime(2012, 11, 15, 1, 35, tzinfo=UTC),
'coupon_available': True
'coupon_available': True,
},
)
@ddt.unpack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def get_course_info(course):
if len(seats) == 1:
seat = seats[0]
seat_type = getattr(seat.attr, 'certificate_type', '').lower()
price = seat.stockrecords.all()[0].price_excl_tax
price = seat.stockrecords.all()[0].price
id_verification_required = getattr(seat.attr, 'id_verification_required', False)

return seat_type, price, id_verification_required
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def create_or_update_seat(
course_id
)

stock_record.price_excl_tax = price
stock_record.price = price
stock_record.price_currency = settings.OSCAR_DEFAULT_CURRENCY
stock_record.save()

Expand Down Expand Up @@ -325,7 +325,7 @@ def _create_or_update_enrollment_code(self, seat_type, id_verification_required,
partner_sku=enrollment_code_sku
)

stock_record.price_excl_tax = price
stock_record.price = price
stock_record.price_currency = settings.OSCAR_DEFAULT_CURRENCY
stock_record.save()

Expand Down
2 changes: 1 addition & 1 deletion ecommerce/courses/publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def serialize_seat_for_commerce_api(self, seat):
return {
'name': mode_for_product(seat),
'currency': stock_record.price_currency,
'price': int(stock_record.price_excl_tax),
'price': int(stock_record.price),
'sku': stock_record.partner_sku,
'bulk_sku': bulk_sku,
'expires': self.get_seat_expiration(seat),
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/courses/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ecommerce.courses.models import Course


class CourseFactory(factory.DjangoModelFactory):
class CourseFactory(factory.django.DjangoModelFactory):
class Meta:
model = Course

Expand Down
4 changes: 2 additions & 2 deletions ecommerce/courses/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def assert_course_seat_valid(self, seat, course, certificate_type, id_verificati
self.assertEqual(getattr(seat.attr, 'certificate_type', ''), certificate_type)
self.assertEqual(seat.attr.course_key, course.id)
self.assertEqual(seat.attr.id_verification_required, id_verification_required)
self.assertEqual(seat.stockrecords.first().price_excl_tax, price)
self.assertEqual(seat.stockrecords.first().price, price)

if credit_provider:
self.assertEqual(seat.attr.credit_provider, credit_provider)
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_create_seat_with_enrollment_code(self):
self.assertIsNone(enrollment_code.expires)

stock_record = StockRecord.objects.get(product=enrollment_code)
self.assertEqual(stock_record.price_excl_tax, price)
self.assertEqual(stock_record.price, price)
self.assertEqual(stock_record.price_currency, settings.OSCAR_DEFAULT_CURRENCY)
self.assertEqual(stock_record.partner, self.partner)

Expand Down
6 changes: 3 additions & 3 deletions ecommerce/courses/tests/test_publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_serialize_seat_for_commerce_api(self):
expected = {
'name': 'verified',
'currency': 'USD',
'price': int(stock_record.price_excl_tax),
'price': int(stock_record.price),
'sku': stock_record.partner_sku,
'bulk_sku': None,
'expires': None,
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_serialize_seat_for_commerce_api_with_professional(self, is_verified, ex
expected = {
'name': expected_mode,
'currency': 'USD',
'price': int(stock_record.price_excl_tax),
'price': int(stock_record.price),
'sku': stock_record.partner_sku,
'bulk_sku': None,
'expires': None,
Expand All @@ -177,7 +177,7 @@ def test_serialize_seat_with_enrollment_code(self):
expected = {
'name': 'verified',
'currency': 'USD',
'price': int(stock_record.price_excl_tax),
'price': int(stock_record.price),
'sku': stock_record.partner_sku,
'bulk_sku': ec_stock_record.partner_sku,
'expires': None,
Expand Down
6 changes: 3 additions & 3 deletions ecommerce/credit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ def _get_providers_detail(self, credit_seats):
if code:
discount = format_benefit_value(voucher.benefit)
if discount_type == 'Percentage':
new_price = stockrecord.price_excl_tax - (stockrecord.price_excl_tax * (discount_value / 100))
new_price = stockrecord.price - (stockrecord.price * (discount_value / 100))
else:
new_price = stockrecord.price_excl_tax - discount_value
new_price = stockrecord.price - discount_value
new_price = '{0:.2f}'.format(new_price)
providers_dict[seat.attr.credit_provider].update({
'price': stockrecord.price_excl_tax,
'price': stockrecord.price,
'sku': stockrecord.partner_sku,
'credit_hours': seat.attr.credit_hours,
'discount': discount,
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/enterprise/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def is_offer_max_discount_available(basket, offer):

def _get_basket_discount_value(basket, offer):
"""Calculate the discount value based on benefit type and value"""
sum_basket_lines = basket.all_lines().aggregate(total=Sum('stockrecord__price_excl_tax'))['total'] or Decimal(0.0)
sum_basket_lines = basket.all_lines().aggregate(total=Sum('stockrecord__price'))['total'] or Decimal(0.0)
# calculate discount value that will be covered by the offer
benefit_type = get_benefit_type(offer.benefit)
benefit_value = offer.benefit.value
Expand Down
5 changes: 4 additions & 1 deletion ecommerce/enterprise/tests/test_backfill_opportunity_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def init_data(self, enterprise_customer, opportunity_id=None):
"""
Create database records to test against.
"""
self.create_coupon(enterprise_customer=enterprise_customer, sales_force_id=opportunity_id)
self.create_coupon(
enterprise_customer=enterprise_customer,
sales_force_id=opportunity_id
)

factories.EnterpriseOfferFactory(
condition=factories.EnterpriseCustomerConditionFactory(
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/enterprise/tests/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setUp(self):
self.user = UserFactory()
self.condition = factories.EnterpriseCustomerConditionFactory()

self.test_product = ProductFactory(stockrecords__price_excl_tax=10, categories=[])
self.test_product = ProductFactory(stockrecords__price=10, categories=[])
self.course_run_1 = CourseFactory(partner=self.partner)
self.course_run_1.create_or_update_seat('verified', True, Decimal(100))

Expand Down Expand Up @@ -227,7 +227,7 @@ def test_is_satisfied_free_basket(self):
offer = factories.EnterpriseOfferFactory(partner=self.partner, condition=self.condition)
basket = BasketFactory(site=self.site, owner=self.user)
test_product = factories.ProductFactory(
stockrecords__price_excl_tax=0,
stockrecords__price=0,
stockrecords__partner__short_code='test'
)
basket.add_product(test_product)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def setUp(self):

for i in range(2):
code = '{}EntUserPercentBenefit'.format(i)
voucher = VoucherFactory(code=code)
name = 'Test_1 voucher{}'.format(i)
voucher = VoucherFactory(code=code, name=name)
offer_name = "Coupon [{}]-{}-{}".format(
voucher.pk,
benefit_percent.type,
Expand All @@ -69,7 +70,8 @@ def setUp(self):

for i in range(2):
code = '{}EntUserAbsoluteBenefit'.format(i)
voucher = VoucherFactory(code=code)
name = 'Test_2 voucher {}'.format(i)
voucher = VoucherFactory(code=code, name=name)
offer_name = "Coupon [{}]-{}-{}".format(
voucher.pk,
benefit_absolute.type,
Expand All @@ -93,7 +95,8 @@ def setUp(self):

for i in range(3):
code = '{}NoEntUserPercentBenefit'.format(i)
voucher = VoucherFactory(code=code)
name = 'Test_3 voucher{}'.format(i)
voucher = VoucherFactory(code=code, name=name)
offer_name = "Coupon [{}]-{}-{}".format(
voucher.pk,
benefit.type,
Expand Down
8 changes: 4 additions & 4 deletions ecommerce/entitlements/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_course_entitlement_creation(self):
self.assertEqual(product.attr.UUID, 'foo-bar')

stock_record = StockRecord.objects.get(product=product, partner=self.partner)
self.assertEqual(stock_record.price_excl_tax, 100)
self.assertEqual(stock_record.price, 100)

def test_course_entitlement_update(self):
""" Test course entitlement product update """
Expand All @@ -29,16 +29,16 @@ def test_course_entitlement_update(self):
assert product.attr.variant_id == original_variant_id
stock_record = StockRecord.objects.get(product=product, partner=self.partner)

self.assertEqual(stock_record.price_excl_tax, 100)
self.assertEqual(stock_record.price, 100)
self.assertEqual(product.title, 'Course Foo Bar Entitlement')

new_variant_id = '11111111-1111-1111-1111-11111111'
product = create_or_update_course_entitlement(
'verified', 200, self.partner, 'foo-bar', 'Foo Bar Entitlement', variant_id=new_variant_id)

stock_record = StockRecord.objects.get(product=product, partner=self.partner)
self.assertEqual(stock_record.price_excl_tax, 200)
self.assertEqual(stock_record.price_excl_tax, 200)
self.assertEqual(stock_record.price, 200)
self.assertEqual(stock_record.price, 200)

product.refresh_from_db()
assert product.attr.variant_id == new_variant_id
2 changes: 1 addition & 1 deletion ecommerce/entitlements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def create_or_update_course_entitlement(
'product': course_entitlement,
'partner': partner,
'partner_sku': generate_sku(course_entitlement, partner),
'price_excl_tax': price,
'price': price,
'price_currency': settings.OSCAR_DEFAULT_CURRENCY,
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.20 on 2023-08-24 10:28

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('analytics', '0002_auto_20140827_1705'),
]

operations = [
migrations.AlterModelOptions(
name='userproductview',
options={'ordering': ['-pk'], 'verbose_name': 'User product view', 'verbose_name_plural': 'User product views'},
),
migrations.AlterModelOptions(
name='usersearch',
options={'ordering': ['-pk'], 'verbose_name': 'User search query', 'verbose_name_plural': 'User search queries'},
),
]
6 changes: 3 additions & 3 deletions ecommerce/extensions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,18 @@ class StockRecordSerializer(serializers.ModelSerializer):

class Meta:
model = StockRecord
fields = ('id', 'product', 'partner', 'partner_sku', 'price_currency', 'price_excl_tax',)
fields = ('id', 'product', 'partner', 'partner_sku', 'price_currency', 'price',)


class PartialStockRecordSerializerForUpdate(StockRecordSerializer):
""" Stock record objects serializer for PUT requests.
Allowed fields to update are 'price_currency' and 'price_excl_tax'.
Allowed fields to update are 'price_currency' and 'price'.
"""

class Meta:
model = StockRecord
fields = ('price_currency', 'price_excl_tax',)
fields = ('price_currency', 'price',)


class ProductSerializer(ProductPaymentInfoMixin, serializers.HyperlinkedModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def format_seat(seat):
result = seat_template.format(
course.name,
stock_record.partner_sku,
stock_record.price_excl_tax,
stock_record.price,
)
return result

Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/api/v2/tests/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ def serialize_stockrecord(self, stockrecord):
'product': stockrecord.product.id,
'partner_sku': stockrecord.partner_sku,
'price_currency': stockrecord.price_currency,
'price_excl_tax': str(stockrecord.price_excl_tax),
'price': str(stockrecord.price),
}
Loading

0 comments on commit 4d275df

Please sign in to comment.