How to get max discount(1 per product in basket) in Django oscar?

40 Views Asked by At

As I understand the current oscar mechanism is as follows: 1 bypass all offers 2 for each offer, bypass all the lines of the cart and calculate the discount 3 add up all discounts received I need to choose the best one for each line from all the discounts. Now I have only % discount on the product.

So I did this:

class PercentageDiscountBenefit(Benefit):
...
def apply(self, basket, condition, offer, discount_percent=None,
              max_total_discount=None, **kwargs):
....
 line_discount = self.round(discount_percent / D('100.0') * price
                                       * int(quantity_affected), basket.currency)
            #ksen1
            if line_discount<line.discount_value:
                line_discount = 0
            #ksen1end
            if discount_amount_available is not None:
                line_discount = min(line_discount, discount_amount_available)
                discount_amount_available -= line_discount

            apply_discount(line, line_discount, quantity_affected, offer)

            affected_items += quantity_affected
            discount += line_discount

        return BasketDiscount(discount)

It works if you make priority=% discount value. But I would like to find a more universal solution, while in my head there is only a global rewriting of the entire module. Are there more elegant solutions?

0

There are 0 best solutions below