I am wondering about how to apply offer for consume offer for django oscar 1.6.4,
I was digging in to the code base, and found out that we call consume 2 times when applying a benefit. For example
apps.basket.abstract_models.py def discount(self, discount_value, affected_quantity, incl_tax=True,
offer=None):
"""
Apply a discount to this line
"""
if incl_tax:
if self._discount_excl_tax > 0:
raise RuntimeError(
"Attempting to discount the tax-inclusive price of a line "
"when tax-exclusive discounts are already applied")
self._discount_incl_tax += discount_value
else:
if self._discount_incl_tax > 0:
raise RuntimeError(
"Attempting to discount the tax-exclusive price of a line "
"when tax-inclusive discounts are already applied")
self._discount_excl_tax += discount_value
self.consume(affected_quantity, offer=offer)
And then again in apps.offer.conditions.py in each condition, they have def consume_items(self, offer, basket, affected_lines): and call line.consume(quantity_to_consume, offer=offer) method again.
I don't think it's supposed to call consume twice like this?
Thanks for reporting this - it doesn't look right that consume() is called twice. This was introduced in #2410. There is quite a lot going on there and the fix isn't immediately obvious to me.
Hi, my work around for this scenario for my custom condition and benefit is I dont implement consume_items for custom condition, Dont sure it is a right thing to do or not.
@pjstevns would be grateful for your thoughts on how best to resolve this. I think one approach would be to drop Condition.consume_items completely, since the consumption now happens in the offer itself. However this would mean a backward incompatible change to the public API.
I'll prepare a fix for this asap.
@prince-tanapong could you please provide an example of a conditional offer where this is a problem?
I'm currently working on the assumption that you are relying on benefit.max_affected_items or on offer.max_applications, but I'd like to rule out other scenarios where multiple calls to consume may become an issue.
Fix delivered in PR https://github.com/django-oscar/django-oscar/pull/2970
Most helpful comment
I'll prepare a fix for this asap.