WIP: Refs #14913 fix voucher order count
Fix discrepancy between voucher num_order
and order discounts shown in Voucher dashboard.
Few possible reasons why num_order
might be out of sync with actual number of orders where it was used.
- Voucher was used but the basket was not applicable for discount (See: Issue https://thelabnyc.plan.io/issues/14913)
- This will increase the count in
num_order
but will not create aOrderDiscount
object
- This will increase the count in
- Deleting order records which had used the Voucher
- Deleting an order will delete
OrderDiscount
associated with it due to cascading
- Deleting an order will delete
Changes
- ignores the value stored in
num_order
and computes the order count forOrderDiscount
model
Alternative Approach
- Manually re-sync
num_order
property withOrderDiscount
using a code snippet similar to one below- We already have a fix in place for Problem 1
- As long as we never encounter Problem 2, this will be a better fix
voucher.num_order = OrderDiscount.objects.filter(voucher_id__in=ids).count()
Edited by Craig Weber