Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voucher application with suspended offer #289

Open
samar-hassan opened this issue Aug 8, 2022 · 1 comment
Open

Voucher application with suspended offer #289

samar-hassan opened this issue Aug 8, 2022 · 1 comment
Labels

Comments

@samar-hassan
Copy link
Contributor

Voucher is being applied even if the only offer attached to the that voucher is suspended.

@maerteijn
Copy link
Member

This shouldn't be the case as django-oscar-api is just using the regular django-oscar machinery for applying offers.

In apply_offers, we just call the oscar applicator:

def apply_offers(request, basket):
    "Apply offers and discounts to cart"
    basket.reset_offer_applications()
    if not basket.is_empty:
        Applicator().apply(basket, request.user, request)

In the default oscar applicator, offers are retrieved by using the active Manager:

  def get_site_offers(self):
        """
        Return site offers that are available to all users
        """
        ConditionalOffer = get_model('offer', 'ConditionalOffer')
        qs = ConditionalOffer.active.filter(offer_type=ConditionalOffer.SITE)

The active manager makes sure inactive of suspended offers are not queried, see the unit test for this in oscar:

    def test_filters_out_suspended_offers(self):
        # Create offer that is available but with the wrong status
        factories.create_offer(
            status=models.ConditionalOffer.SUSPENDED)
        filtered_offers = models.ConditionalOffer.active.all()
        self.assertEqual(0, len(filtered_offers))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants