Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Copy]Django Oscar Upgrade to version 3.2 #4109

Open
wants to merge 27 commits into
base: 2u/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1f826da
chore: django oscar version upgrade to 3.1
zubair-ce07 Nov 12, 2023
3efe055
chore: djano oscar version upgrade to 3.1
zubair-ce07 Nov 12, 2023
aa6ed45
feat: master merge
zubair-ce07 Nov 14, 2023
1344114
feat: add data migration to make voucher names unique
mumarkhan999 Nov 14, 2023
9e84c8d
fix: removed code
zubair-ce07 Nov 15, 2023
30357f0
feat: master merge
zubair-ce07 Nov 15, 2023
73c45fc
feat: master merge
zubair-ce07 Nov 15, 2023
f027acb
refactor: updated django oscar templates
zubair-ce07 Nov 16, 2023
fd18782
feat: master merge
zubair-ce07 Nov 16, 2023
91eb425
feat: master merge
zubair-ce07 Dec 5, 2023
13bc01f
refactor: updated price field name
zubair-ce07 Dec 5, 2023
33959c2
refactor: update price field name
zubair-ce07 Dec 5, 2023
bb2fcbb
feat: master merge
zubair-ce07 Jan 8, 2024
c2e0632
feat: added refund functionality
zubair-ce07 Jan 12, 2024
981ccf5
fix: migration issue
zubair-ce07 Jan 19, 2024
1dd66d7
fix: updated field name
zubair-ce07 Jan 19, 2024
92e5d26
refactor: updated field name
zubair-ce07 Jan 22, 2024
efcc407
Merge branch '2u/main' into zubair-django-oscar31-update-copy-3
zubair-ce07 Jan 22, 2024
8e06f46
Merge branch '2u/main' into zubair-django-oscar31-update-copy-3
zubair-ce07 Jan 23, 2024
0073c96
chore: PR to upgrade django oscar to version 3.2
zubair-ce07 Dec 5, 2023
58c3240
feat: resloved reserved keywords conflict
zubair-ce07 Dec 5, 2023
76fc08c
feat: add data mmigration to make basket_lineattribute value json com…
mumarkhan999 Dec 7, 2023
da02c63
fix: merged master
zubair-ce07 Jan 8, 2024
a19b58a
Merge branch 'zubair-django-oscar31-update' into zubair-django-oscar3…
zubair-ce07 Jan 15, 2024
9ab6fc6
Merge branch 'master' into zubair-django-oscar32-update
zubair-ce07 Jan 16, 2024
3255b90
fix: merge migration
zubair-ce07 Jan 24, 2024
f97c2a7
feat: add data mmigration to make order_lineattribute value json comp…
mumarkhan999 Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ FROM ubuntu:focal as app
ENV DEBIAN_FRONTEND noninteractive
# System requirements.
RUN apt update && \
apt-get install -qy \
apt-get install -qy \
curl \
gettext \
git \
language-pack-en \
build-essential \
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ compile_translations: requirements.tox
fake_translations: extract_translations dummy_translations compile_translations

pull_translations:
ifeq ($(OPENEDX_ATLAS_PULL),)
cd ecommerce && tx pull -a -f -t --mode reviewed
else
find ecommerce/conf/locale -mindepth 1 -maxdepth 1 -type d -exec rm -r {} \;
atlas pull $(OPENEDX_ATLAS_ARGS) translations/ecommerce/ecommerce/conf/locale:ecommerce/conf/locale
python manage.py compilemessages
endif

push_translations:
cd ecommerce && tx push -s
Expand Down
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
5 changes: 5 additions & 0 deletions db_keyword_overrides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ MYSQL:
- ShippingEvent.lines
- PaymentEvent.lines
- ProductAlert.key
- HistoricalOption.order
- Option.order
SNOWFLAKE:
- HistoricalOption.order
- Option.order

STITCH:
2 changes: 1 addition & 1 deletion docs/decisions/0008-master-branch-split.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Accepted
Context
-------

Both 2U and the Open edX community used ecommerce's master branch for releases. Occasionally, changes
Both 2U and the Open edX community use ecommerce's master branch for releases. Occasionally, changes
specific to 2U's business case are merged into code, which also influences the structure
of the code that the community runs, even if the changes are not relevant or beneficial
to the community at large.
Expand Down
1 change: 1 addition & 0 deletions ecommerce/conf/locale/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ ignore_dirs:
- i18n
- assets
- node_modules
- tests
- static/bower_components
- static/build
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)
2 changes: 1 addition & 1 deletion 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
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 @@ -252,7 +252,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 @@ -329,7 +329,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 @@ -53,7 +53,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 variant_id:
self.assertEqual(seat.attr.variant_id, variant_id)
Expand Down Expand Up @@ -161,7 +161,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
10 changes: 5 additions & 5 deletions ecommerce/courses/tests/test_publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _create_mobile_seat_for_course(self, course, sku_prefix):
product=mobile_seat,
partner_sku="mobile.{}.{}".format(sku_prefix.lower(), web_stock_record.partner_sku.lower()),
price_currency=web_stock_record.price_currency,
price_excl_tax=web_stock_record.price_excl_tax,
price=web_stock_record.price,
)
return mobile_seat

Expand Down Expand Up @@ -164,7 +164,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 @@ -195,7 +195,7 @@ def test_serialize_seat_for_commerce_api_with_mobile_skus(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 @@ -229,7 +229,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 @@ -247,7 +247,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
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
5 changes: 3 additions & 2 deletions ecommerce/entitlements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ def create_or_update_course_entitlement(
course_entitlement.structure = Product.CHILD
course_entitlement.is_discountable = True
course_entitlement.title = 'Course {}'.format(title)
course_entitlement.parent = parent_entitlement
course_entitlement.attr.certificate_type = certificate_type
course_entitlement.attr.UUID = UUID
course_entitlement.attr.id_verification_required = id_verification_required
course_entitlement.attr.credit_provider = credit_provider
course_entitlement.parent = parent_entitlement

if variant_id:
course_entitlement.attr.variant_id = variant_id
if has_existing_course_entitlement:
Expand All @@ -94,7 +95,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-11-08 13:55

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
Loading
Loading