Error in the redeem loyalty points calculation

In the apply_loyalty_points function, the calculation of available_points is incorrect because it does not properly handle the remaining loyalty points.

Currently:

available_points = lp_entry.loyalty_points - flt(redemption_details.get(lp_entry.name))

It should be:

available_points = lp_entry.loyalty_points - abs(flt(redemption_details.get(lp_entry.name)))

Using abs() ensures the remaining points are calculated correctly for further allocation.

With my sample data, the current logic calculates available_points as 6 in a single allocation, while the correct behavior should split it into two allocations:

  • First allocation: 4

  • Second allocation: 2

My Images: