Skip to content

WIP: Refs #14913 fix voucher order count

Diwas Sharma requested to merge fix/voucher_application_count into master

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.

  1. 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 a OrderDiscount object
  2. Deleting order records which had used the Voucher
    • Deleting an order will delete OrderDiscount associated with it due to cascading

Changes

  • ignores the value stored in num_order and computes the order count for OrderDiscount model

Alternative Approach

  • Manually re-sync num_order property with OrderDiscount 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

Merge request reports