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
77c460d3
Commit
77c460d3
authored
May 19, 2015
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #102 from edx/refund-properties
Added can_approve and can_deny properties to Refund model
parents
03d0d09d
3635514f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletions
+42
-1
ecommerce/extensions/refund/models.py
+15
-0
ecommerce/extensions/refund/tests/test_models.py
+27
-1
No files found.
ecommerce/extensions/refund/models.py
View file @
77c460d3
...
@@ -6,6 +6,7 @@ from oscar.core.utils import get_default_currency
...
@@ -6,6 +6,7 @@ from oscar.core.utils import get_default_currency
from
simple_history.models
import
HistoricalRecords
from
simple_history.models
import
HistoricalRecords
from
ecommerce.extensions.refund.exceptions
import
InvalidStatus
from
ecommerce.extensions.refund.exceptions
import
InvalidStatus
from
ecommerce.extensions.refund.status
import
REFUND
class
StatusMixin
(
object
):
class
StatusMixin
(
object
):
...
@@ -68,6 +69,20 @@ class Refund(StatusMixin, TimeStampedModel):
...
@@ -68,6 +69,20 @@ class Refund(StatusMixin, TimeStampedModel):
num_items
+=
line
.
quantity
num_items
+=
line
.
quantity
return
num_items
return
num_items
@property
def
can_approve
(
self
):
"""
Returns a boolean indicating if this Refund can be approved.
"""
return
self
.
status
not
in
(
REFUND
.
COMPLETE
,
REFUND
.
DENIED
)
@property
def
can_deny
(
self
):
"""
Returns a boolean indicating if this Refund can be denied.
"""
return
self
.
status
==
settings
.
OSCAR_INITIAL_REFUND_STATUS
class
RefundLine
(
StatusMixin
,
TimeStampedModel
):
class
RefundLine
(
StatusMixin
,
TimeStampedModel
):
"""A refund line, used to represent the state of a single item as part of a larger Refund."""
"""A refund line, used to represent the state of a single item as part of a larger Refund."""
...
...
ecommerce/extensions/refund/tests/test_models.py
View file @
77c460d3
import
ddt
from
django.test
import
TestCase
,
override_settings
from
django.test
import
TestCase
,
override_settings
from
oscar.core.loading
import
get_model
from
oscar.core.loading
import
get_model
...
@@ -62,7 +63,8 @@ class StatusTestsMixin(object):
...
@@ -62,7 +63,8 @@ class StatusTestsMixin(object):
self
.
assertEqual
(
instance
.
status
,
new_status
,
'Refund status was not updated!'
)
self
.
assertEqual
(
instance
.
status
,
new_status
,
'Refund status was not updated!'
)
@override_settings
(
OSCAR_REFUND_STATUS_PIPELINE
=
OSCAR_REFUND_STATUS_PIPELINE
)
@ddt.ddt
@override_settings
(
OSCAR_REFUND_STATUS_PIPELINE
=
OSCAR_REFUND_STATUS_PIPELINE
,
OSCAR_INITIAL_REFUND_STATUS
=
REFUND
.
OPEN
)
class
RefundTests
(
StatusTestsMixin
,
TestCase
):
class
RefundTests
(
StatusTestsMixin
,
TestCase
):
pipeline
=
OSCAR_REFUND_STATUS_PIPELINE
pipeline
=
OSCAR_REFUND_STATUS_PIPELINE
...
@@ -82,6 +84,30 @@ class RefundTests(StatusTestsMixin, TestCase):
...
@@ -82,6 +84,30 @@ class RefundTests(StatusTestsMixin, TestCase):
""" Refund.all_statuses should return all possible statuses for a refund. """
""" Refund.all_statuses should return all possible statuses for a refund. """
self
.
assertEqual
(
Refund
.
all_statuses
(),
OSCAR_REFUND_STATUS_PIPELINE
.
keys
())
self
.
assertEqual
(
Refund
.
all_statuses
(),
OSCAR_REFUND_STATUS_PIPELINE
.
keys
())
@ddt.unpack
@ddt.data
(
(
REFUND
.
OPEN
,
True
),
(
REFUND
.
ERROR
,
True
),
(
REFUND
.
DENIED
,
False
),
(
REFUND
.
COMPLETE
,
False
),
)
def
test_can_approve
(
self
,
status
,
expected
):
""" The method should return True if the Refund can be approved; otherwise, False. """
refund
=
self
.
_get_instance
(
status
=
status
)
self
.
assertEqual
(
refund
.
can_approve
,
expected
)
@ddt.unpack
@ddt.data
(
(
REFUND
.
OPEN
,
True
),
(
REFUND
.
ERROR
,
False
),
(
REFUND
.
DENIED
,
False
),
(
REFUND
.
COMPLETE
,
False
),
)
def
test_can_deny
(
self
,
status
,
expected
):
""" The method should return True if the Refund can be denied; otherwise, False. """
refund
=
self
.
_get_instance
(
status
=
status
)
self
.
assertEqual
(
refund
.
can_deny
,
expected
)
@override_settings
(
OSCAR_REFUND_LINE_STATUS_PIPELINE
=
OSCAR_REFUND_LINE_STATUS_PIPELINE
)
@override_settings
(
OSCAR_REFUND_LINE_STATUS_PIPELINE
=
OSCAR_REFUND_LINE_STATUS_PIPELINE
)
class
RefundLineTests
(
StatusTestsMixin
,
TestCase
):
class
RefundLineTests
(
StatusTestsMixin
,
TestCase
):
...
...
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