Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
f5620c0a
Commit
f5620c0a
authored
Jan 09, 2017
by
Ivan Ivic
Committed by
Ivan Ivic
Jan 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ECOM-6746] Editing Single Course Coupon Code to Multi-Course Redeems all Codes
parent
758c42f5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
2 deletions
+91
-2
ecommerce/extensions/offer/management/__init__.py
+0
-0
ecommerce/extensions/offer/management/commands/__init__.py
+0
-0
ecommerce/extensions/offer/management/commands/set_max_applications_to_none.py
+22
-0
ecommerce/extensions/offer/tests/test_commands.py
+58
-0
ecommerce/static/js/test/specs/views/coupon_form_view_spec.js
+9
-1
ecommerce/static/js/views/coupon_form_view.js
+2
-1
No files found.
ecommerce/extensions/offer/management/__init__.py
0 → 100644
View file @
f5620c0a
ecommerce/extensions/offer/management/commands/__init__.py
0 → 100644
View file @
f5620c0a
ecommerce/extensions/offer/management/commands/set_max_applications_to_none.py
0 → 100644
View file @
f5620c0a
""" 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.'
)
ecommerce/extensions/offer/tests/test_commands.py
0 → 100644
View file @
f5620c0a
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
)
ecommerce/static/js/test/specs/views/coupon_form_view_spec.js
View file @
f5620c0a
...
@@ -186,7 +186,10 @@ define([
...
@@ -186,7 +186,10 @@ define([
expect
(
SpecUtils
.
formGroup
(
view
,
'[name=max_uses]'
)).
toBeVisible
();
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'
);
view
.
$
(
'[name=voucher_type]'
).
val
(
'Once per customer'
).
trigger
(
'change'
);
expect
(
view
.
$
(
'[name=max_uses]'
).
val
()).
toBe
(
'1'
);
expect
(
view
.
$
(
'[name=max_uses]'
).
val
()).
toBe
(
'1'
);
expect
(
view
.
$
(
'[name=max_uses]'
).
attr
(
'min'
)).
toBe
(
'1'
);
expect
(
view
.
$
(
'[name=max_uses]'
).
attr
(
'min'
)).
toBe
(
'1'
);
...
@@ -195,6 +198,11 @@ define([
...
@@ -195,6 +198,11 @@ define([
expect
(
view
.
$
(
'[name=max_uses]'
).
attr
(
'min'
)).
toBe
(
'2'
);
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
()
{
it
(
'should hide quantity field when code entered'
,
function
()
{
view
.
$
(
'[name=code]'
).
val
(
'E34T4GR342'
).
trigger
(
'input'
);
view
.
$
(
'[name=code]'
).
val
(
'E34T4GR342'
).
trigger
(
'input'
);
expect
(
SpecUtils
.
formGroup
(
view
,
'[name=quantity]'
)).
not
.
toBeVisible
();
expect
(
SpecUtils
.
formGroup
(
view
,
'[name=quantity]'
)).
not
.
toBeVisible
();
...
...
ecommerce/static/js/views/coupon_form_view.js
View file @
f5620c0a
...
@@ -462,7 +462,8 @@ define([
...
@@ -462,7 +462,8 @@ define([
*/
*/
if
(
voucherType
===
'Single use'
)
{
if
(
voucherType
===
'Single use'
)
{
this
.
setLimitToElement
(
this
.
$
(
maxUsesFieldSelector
),
''
,
''
);
this
.
setLimitToElement
(
this
.
$
(
maxUsesFieldSelector
),
''
,
''
);
this
.
hideField
(
maxUsesFieldSelector
,
1
);
this
.
hideField
(
maxUsesFieldSelector
,
''
);
this
.
model
.
unset
(
'max_uses'
);
}
else
{
}
else
{
if
(
this
.
model
.
get
(
'coupon_type'
)
===
'Discount code'
&&
this
.
$
(
'[name=quantity]'
).
val
()
===
1
)
{
if
(
this
.
model
.
get
(
'coupon_type'
)
===
'Discount code'
&&
this
.
$
(
'[name=quantity]'
).
val
()
===
1
)
{
this
.
formGroup
(
'[name=code]'
).
removeClass
(
this
.
hiddenClass
);
this
.
formGroup
(
'[name=code]'
).
removeClass
(
this
.
hiddenClass
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment