Commit 77c460d3 by Clinton Blackburn

Merge pull request #102 from edx/refund-properties

Added can_approve and can_deny properties to Refund model
parents 03d0d09d 3635514f
...@@ -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."""
......
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):
......
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