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

Commit

Permalink
fix: changed django migration to alter price field in stockrecord model
Browse files Browse the repository at this point in the history
chore: updated factory dependency

refactor: updated field name

feat: Mgmt Command to create mobile seats for new course runs (#4046)

fix: skipped a failing test. Will fix it in another ticket

fix: updated method

refactor: made changes as per new version of oscar

refactor: updated code to make voucher name unique

fix: removed white spaces

fix: removed white spaces

refactor: changed code as per new version of oscar

refactor: updated code

fix: override Product model in catalogue app

fix: removed extra spaces

fix: updated  code

fix: changes in code to pass checks

fix: changes in code to pass checks
  • Loading branch information
zubair-ce07 committed Nov 14, 2023
1 parent 4626bd8 commit a8acca8
Show file tree
Hide file tree
Showing 72 changed files with 634 additions and 157 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: 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 @@ -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
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
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),
}
18 changes: 9 additions & 9 deletions ecommerce/extensions/api/v2/tests/views/test_baskets.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ def setUp(self):
parent=self.base_product,
title='LP 560-4',
stockrecords__partner_sku=self.PAID_SKU,
stockrecords__price_excl_tax=Decimal('180000.00'),
stockrecords__price=Decimal('180000.00'),
stockrecords__partner__short_code='oscr',
)
factories.ProductFactory(
structure='child',
parent=self.base_product,
title=u'Papier-mâché',
stockrecords__partner_sku=self.ALTERNATE_FREE_SKU,
stockrecords__price_excl_tax=Decimal('0.00'),
stockrecords__price=Decimal('0.00'),
stockrecords__partner__short_code='otto',
)
factories.ProductFactory(
structure='child',
parent=self.base_product,
title='LP 570-4 Superleggera',
stockrecords__partner_sku=self.ALTERNATE_PAID_SKU,
stockrecords__price_excl_tax=Decimal('240000.00'),
stockrecords__price=Decimal('240000.00'),
stockrecords__partner__short_code='dummy',
)
# Ensure that the basket attribute type exists for these tests
Expand Down Expand Up @@ -403,7 +403,7 @@ def setUp(self):
self.products = ProductFactory.create_batch(3, stockrecords__partner=self.partner, categories=[])
self.path = reverse('api:v2:baskets:calculate')
self.range = factories.RangeFactory(includes_all_products=True)
self.product_total = sum(product.stockrecords.first().price_excl_tax for product in self.products)
self.product_total = sum(product.stockrecords.first().price for product in self.products)
self.user = self._login_as_user(is_staff=True)
self.url = self._generate_sku_url(self.products, username=self.user.username)

Expand Down Expand Up @@ -597,7 +597,7 @@ def test_basket_calculate_by_staff_user_other_username(self, mock_get_lms_resour
products, url = self.setup_other_user_basket_calculate()

expected = {
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price_excl_tax
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price
for product in products),
'total_incl_tax': Decimal('0.00'),
'currency': 'USD'
Expand All @@ -623,7 +623,7 @@ def test_basket_calculate_by_staff_user_other_username_non_atomic(
products, url = self.setup_other_user_basket_calculate()

expected = {
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price_excl_tax
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price
for product in products),
'total_incl_tax': Decimal('0.00'),
'currency': 'USD'
Expand Down Expand Up @@ -691,7 +691,7 @@ def test_basket_calculate_anonymous_skip_lms(self, mock_get_lms_resource_for_use
products, url = self._setup_anonymous_basket_calculate()

expected = {
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price_excl_tax
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price
for product in products),
'total_incl_tax': Decimal('0.00'),
'currency': 'USD'
Expand Down Expand Up @@ -867,7 +867,7 @@ def test_basket_calculate_by_staff_user_invalid_username(self, mock_get_lms_reso
url = self._generate_sku_url(products, username='invalidusername')

expected = {
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price_excl_tax
'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price
for product in products[1:]),
'total_incl_tax': Decimal('300.00'),
'currency': 'USD'
Expand Down Expand Up @@ -932,7 +932,7 @@ def _create_program_with_courses_and_offer(self):
products.append(
factories.ProductFactory(
stockrecords__partner=self.partner,
stockrecords__price_excl_tax=Decimal('10.00'),
stockrecords__price=Decimal('10.00'),
stockrecords__partner_sku=sku,
))
return products, program_uuid
Expand Down
Loading

0 comments on commit a8acca8

Please sign in to comment.