Commit f5620c0a by Ivan Ivic Committed by Ivan Ivic

[ECOM-6746] Editing Single Course Coupon Code to Multi-Course Redeems all Codes

parent 758c42f5
""" Changes ConditionalOffer max_global_applications for single use vouchers from one to None. """
from __future__ import unicode_literals
from django.core.management import BaseCommand
from oscar.core.loading import get_model
ConditionalOffer = get_model('offer', 'ConditionalOffer')
class Command(BaseCommand):
def handle(self, *args, **options):
offers = ConditionalOffer.objects.filter(max_global_applications=1, vouchers__usage='Single use')
if offers:
for offer in offers:
self.stdout.write(
'Setting max_global_applications field to None for ConditionalOffer [{}]...'.format(offer)
)
offer.max_global_applications = None
offer.save()
self.stdout.write('Done.')
else:
self.stdout.write('Nothing to do here.')
from __future__ import unicode_literals
from StringIO import StringIO
from django.core.management import call_command
from oscar.core.loading import get_model
from oscar.test import factories
from ecommerce.tests.testcases import TestCase
ConditionalOffer = get_model('offer', 'ConditionalOffer')
Voucher = get_model('voucher', 'Voucher')
class SetMaxApplicationsToNoneCommandTest(TestCase):
command = 'set_max_applications_to_none'
filter_condition = {
'max_global_applications': 1,
'vouchers__usage': Voucher.SINGLE_USE
}
def call_command_and_return_output(self):
output = StringIO()
call_command(self.command, stdout=output)
return output
def test_command_on_one_sample(self):
"""Verify the command changes single use vouchers offer with max_global_applications value set to one."""
offer = factories.ConditionalOfferFactory(max_global_applications=1)
voucher = factories.VoucherFactory(usage=Voucher.SINGLE_USE)
voucher.offers.add(offer)
self.assertEqual(ConditionalOffer.objects.filter(**self.filter_condition).count(), 1)
output = self.call_command_and_return_output()
actual_output = output.getvalue().strip()
self.assertTrue(actual_output.startswith(
'Setting max_global_applications field to None for ConditionalOffer [{}]...'.format(offer)
))
self.assertTrue(actual_output.endswith('Done.'))
self.assertEqual(ConditionalOffer.objects.filter(**self.filter_condition).count(), 0)
def test_command_without_sample(self):
"""Verify the command is only showing a message when no queryset is found."""
self.assertEqual(ConditionalOffer.objects.filter(**self.filter_condition).count(), 0)
output = self.call_command_and_return_output()
self.assertEqual('Nothing to do here.', output.getvalue().strip())
self.assertEqual(ConditionalOffer.objects.filter(**self.filter_condition).count(), 0)
def test_command_only_target_single_use_vouchers(self):
"""Verify the command doesn't target multi-use vouchers."""
offer = factories.ConditionalOfferFactory(max_global_applications=1)
voucher = factories.VoucherFactory(usage=Voucher.MULTI_USE)
voucher.offers.add(offer)
output = self.call_command_and_return_output()
self.assertEqual('Nothing to do here.', output.getvalue().strip())
unaffected_offer = ConditionalOffer.objects.get(id=offer.id)
self.assertEqual(unaffected_offer.max_global_applications, 1)
self.assertEqual(unaffected_offer.vouchers.first().usage, Voucher.MULTI_USE)
......@@ -186,7 +186,10 @@ define([
expect(SpecUtils.formGroup(view, '[name=max_uses]')).toBeVisible();
});
it('should set different values for max_uses field for different voucher types', function() {
it('should set different values for max_uses field for different voucher types', function () {
view.$('[name=voucher_type]').val('Single use').trigger('change');
expect(view.$('[name=max_uses]').val()).toBe('');
expect(view.$('[name=max_uses]').attr('min')).toBe('');
view.$('[name=voucher_type]').val('Once per customer').trigger('change');
expect(view.$('[name=max_uses]').val()).toBe('1');
expect(view.$('[name=max_uses]').attr('min')).toBe('1');
......@@ -195,6 +198,11 @@ define([
expect(view.$('[name=max_uses]').attr('min')).toBe('2');
});
it('should unset max_uses field for singe-use voucher', function () {
view.$('[name=voucher_type]').val('Single use').trigger('change');
expect(view.model.get('max_uses')).toBe(undefined);
});
it('should hide quantity field when code entered', function () {
view.$('[name=code]').val('E34T4GR342').trigger('input');
expect(SpecUtils.formGroup(view, '[name=quantity]')).not.toBeVisible();
......
......@@ -462,7 +462,8 @@ define([
*/
if (voucherType === 'Single use') {
this.setLimitToElement(this.$(maxUsesFieldSelector), '', '');
this.hideField(maxUsesFieldSelector, 1);
this.hideField(maxUsesFieldSelector, '');
this.model.unset('max_uses');
} else {
if (this.model.get('coupon_type') === 'Discount code' && this.$('[name=quantity]').val() === 1) {
this.formGroup('[name=code]').removeClass(this.hiddenClass);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment