This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Sync mobile seats expiry and price with web seat
LEARNER-10092
- Loading branch information
1 parent
147a01a
commit b4a64a4
Showing
4 changed files
with
211 additions
and
82 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
ecommerce/extensions/iap/management/commands/sync_mobile_seats_price_and_expiry_with_web.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
This command sync mobile seat price and expiry with web seat price and expiry. | ||
""" | ||
import logging | ||
|
||
from django.core.management import BaseCommand | ||
|
||
from ecommerce.core.constants import SEAT_PRODUCT_CLASS_NAME | ||
from ecommerce.courses.constants import CertificateType | ||
from ecommerce.extensions.catalogue.models import Product | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Sync expiry and price of mobile seats with respective web seat. | ||
""" | ||
|
||
help = 'Sync expiry and price of mobile seats with respective web seat.' | ||
|
||
def handle(self, *args, **options): | ||
mobile_enabled_products = Product.objects.filter( | ||
structure=Product.PARENT, | ||
product_class__name=SEAT_PRODUCT_CLASS_NAME, | ||
children__attribute_values__attribute__name="certificate_type", | ||
children__attribute_values__value_text=CertificateType.VERIFIED, | ||
children__stockrecords__isnull=False, | ||
children__stockrecords__partner_sku__icontains="mobile", | ||
).distinct() | ||
|
||
for product in mobile_enabled_products: | ||
mobile_seats = Product.objects.filter( | ||
parent=product, | ||
attribute_values__attribute__name="certificate_type", | ||
attribute_values__value_text=CertificateType.VERIFIED, | ||
stockrecords__partner_sku__icontains="mobile", | ||
) | ||
|
||
web_seat = Product.objects.filter( | ||
parent=product, | ||
attribute_values__attribute__name="certificate_type", | ||
attribute_values__value_text=CertificateType.VERIFIED, | ||
).exclude(stockrecords__partner_sku__icontains="mobile").first() | ||
|
||
for mobile_seat in mobile_seats: | ||
info = 'Syncing {} with {}'.format(mobile_seat.title, web_seat.title) | ||
logger.info(info) | ||
|
||
stock_record = mobile_seat.stockrecords.all()[0] | ||
stock_record.price_excl_tax = web_seat.stockrecords.all()[0].price_excl_tax | ||
mobile_seat.expires = web_seat.expires | ||
stock_record.save() | ||
mobile_seat.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ensions/iap/management/commands/tests/test_sync_mobile_seats_price_and_expiry_with_web.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Tests for the sync_mobile_seats_price_and_expiry_with_web command""" | ||
from datetime import datetime | ||
|
||
from django.core.management import call_command | ||
|
||
from ecommerce.extensions.iap.management.commands.tests.testutils import BaseIAPManagementCommandTests | ||
|
||
|
||
class SyncMobileSeatsTests(BaseIAPManagementCommandTests): | ||
""" | ||
Tests for the sync_mobile_seats_price_and_expiry_with_web command. | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
self.command = 'sync_mobile_seats_price_and_expiry_with_web' | ||
self.course_with_all_seats = self.create_course_and_seats(create_mobile_seats=True, create_web_seat=True) | ||
self.course_with_web_seat_only = self.create_course_and_seats(create_mobile_seats=False, create_web_seat=True) | ||
self.course_with_audit_seat = self.create_course_and_seats(create_mobile_seats=False, create_web_seat=False) | ||
self.course_with_unsync_seats = self.create_course_and_seats(create_mobile_seats=True, create_web_seat=True) | ||
self.course_with_unsync_seats2 = self.create_course_and_seats(create_mobile_seats=True, create_web_seat=True) | ||
mobile_seats = self.get_mobile_seats_for_course(self.course_with_unsync_seats) | ||
mobile_seats = list(mobile_seats) + list(self.get_mobile_seats_for_course(self.course_with_unsync_seats2)) | ||
|
||
for mobile_seat in mobile_seats: | ||
mobile_seat.expiry = datetime.now() | ||
mobile_seat.save() | ||
|
||
stockrecord = mobile_seat.stockrecords.all()[0] | ||
stockrecord.price_excl_tax += 10 | ||
stockrecord.save() | ||
|
||
def test_sync_mobile_seat(self): | ||
web_seat = self.get_web_seat_for_course(self.course_with_unsync_seats) | ||
web_seat_expiry = web_seat.expires | ||
web_seat_price = web_seat.stockrecords.all()[0].price_excl_tax | ||
|
||
web_seat = self.get_web_seat_for_course(self.course_with_unsync_seats2) | ||
web_seat_expiry2 = web_seat.expires | ||
web_seat_price2 = web_seat.stockrecords.all()[0].price_excl_tax | ||
|
||
call_command(self.command) | ||
self.verify_course_seats_update(self.course_with_unsync_seats, web_seat_expiry, web_seat_price) | ||
self.verify_course_seats_update(self.course_with_unsync_seats2, web_seat_expiry2, web_seat_price2) | ||
|
||
def verify_course_seats_update(self, course, expiry, price): | ||
mobile_seats = self.get_mobile_seats_for_course(course) | ||
for mobile_seat in mobile_seats: | ||
assert mobile_seat.expires == expiry | ||
assert mobile_seat.stockrecords.all()[0].price_excl_tax == price |
Oops, something went wrong.