
from collections import Counter


def count_ordered_articles(article):
    """Count how often the article has been ordered, grouped by the
    order's payment state.
    """
    counter = Counter()
    for order_item in article.order_items:
        counter[order_item.order.payment_state] += order_item.quantity
    return dict(counter)


from collections import Counter

from ..shop.models import PaymentState


def count_ordered_articles(article):
    """Count how often the article has been ordered, grouped by the
    order's payment state.
    """
    counter = Counter({state: 0 for state in PaymentState})

    for order_item in article.order_items:
        counter[order_item.order.payment_state] += order_item.quantity

    return dict(counter)

Make sure every payment state is
Make sure every payment state is

  
  from collections import Counter
+ 
+ from ..shop.models import PaymentState
  
  
  def count_ordered_articles(article):
      """Count how often the article has been ordered, grouped by the
      order's payment state.
      """
-     counter = Counter()
+     counter = Counter({state: 0 for state in PaymentState})
+ 
      for order_item in article.order_items:
          counter[order_item.order.payment_state] += order_item.quantity
+ 
      return dict(counter)
  
Make sure every payment state is
## Code Before:

from collections import Counter


def count_ordered_articles(article):
    """Count how often the article has been ordered, grouped by the
    order's payment state.
    """
    counter = Counter()
    for order_item in article.order_items:
        counter[order_item.order.payment_state] += order_item.quantity
    return dict(counter)

## Instruction:
Make sure every payment state is
## Code After:

from collections import Counter

from ..shop.models import PaymentState


def count_ordered_articles(article):
    """Count how often the article has been ordered, grouped by the
    order's payment state.
    """
    counter = Counter({state: 0 for state in PaymentState})

    for order_item in article.order_items:
        counter[order_item.order.payment_state] += order_item.quantity

    return dict(counter)
