prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  'Completed' attribute missing from order-statistics API
  **I'm submitting a ...**  (check one with "x")
  - [x] bug report
  - [ ] feature request
  - [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server
  
  **Current behavior:**
  Right now the response contains the following fields
   ```
         "placed": 0,
          "draft": 0,
          "cancelled": 0,
          "total": 0,
          "expired": 0,
          "pending": 0
  ```
  The attribute `completed` is missing from the response. 
  Image for reference : https://user-images.githubusercontent.com/13910561/29230756-f5dabe20-7f01-11e7-8c5f-58ee69c38e65.png
  
  **Expected behavior:**
  `completed` attribute should be there.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `app/api/order_statistics/tickets.py`
  Content:
  ```
  1 from flask_rest_jsonapi import ResourceDetail
  2 from marshmallow_jsonapi.flask import Schema
  3 from marshmallow_jsonapi import fields
  4 from sqlalchemy import func
  5 
  6 from app.api.helpers.utilities import dasherize
  7 from app.api.bootstrap import api
  8 from app.models import db
  9 from app.models.order import Order, OrderTicket
  10 from app.models.ticket import Ticket
  11 from app.api.helpers.db import get_count
  12 
  13 
  14 class OrderStatisticsTicketSchema(Schema):
  15     """
  16     Api schema
  17     """
  18 
  19     class Meta:
  20         """
  21         Meta class
  22         """
  23         type_ = 'order-statistics-ticket'
  24         self_view = 'v1.order_statistics_ticket_detail'
  25         self_view_kwargs = {'id': '<id>'}
  26         inflect = dasherize
  27 
  28     id = fields.Str()
  29     identifier = fields.Str()
  30     tickets = fields.Method("tickets_count")
  31     orders = fields.Method("orders_count")
  32     sales = fields.Method("sales_count")
  33 
  34     def tickets_count(self, obj):
  35         obj_id = obj.id
  36         total = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
  37             OrderTicket.ticket_id == obj_id).scalar()
  38         draft = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
  39             OrderTicket.ticket_id == obj_id, Order.status == 'draft').scalar()
  40         cancelled = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
  41             OrderTicket.ticket_id == obj_id, Order.status == 'cancelled').scalar()
  42         pending = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
  43             OrderTicket.ticket_id == obj_id, Order.status == 'pending').scalar()
  44         expired = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
  45             OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()
  46         placed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
  47             OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()
  48         result = {
  49             'total': total or 0,
  50             'draft': draft or 0,
  51             'cancelled': cancelled or 0,
  52             'pending': pending or 0,
  53             'expired': expired or 0,
  54             'placed': placed or 0
  55         }
  56         return result
  57 
  58     def orders_count(self, obj):
  59         obj_id = obj.id
  60         total = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id))
  61         draft = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,
  62                                                                                    Order.status == 'draft'))
  63         cancelled = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,
  64                                                                                        Order.status == 'cancelled'))
  65         pending = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,
  66                                                                                      Order.status == 'pending'))
  67         expired = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,
  68                                                                                      Order.status == 'expired'))
  69         placed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,
  70                                                                                     Order.status == 'placed'))
  71         result = {
  72             'total': total or 0,
  73             'draft': draft or 0,
  74             'cancelled': cancelled or 0,
  75             'pending': pending or 0,
  76             'expired': expired or 0,
  77             'placed': placed or 0
  78         }
  79         return result
  80 
  81     def sales_count(self, obj):
  82         obj_id = obj.id
  83         total = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
  84             OrderTicket.ticket_id == obj_id).scalar()
  85         draft = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
  86             OrderTicket.ticket_id == obj_id, Order.status == 'draft').scalar()
  87         cancelled = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
  88             OrderTicket.ticket_id == obj_id, Order.status == 'cancelled').scalar()
  89         pending = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
  90             OrderTicket.ticket_id == obj_id, Order.status == 'pending').scalar()
  91         expired = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
  92             OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()
  93         placed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
  94             OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()
  95         result = {
  96             'total': total or 0,
  97             'draft': draft or 0,
  98             'cancelled': cancelled or 0,
  99             'pending': pending or 0,
  100             'expired': expired or 0,
  101             'placed': placed or 0
  102         }
  103         return result
  104 
  105 
  106 class OrderStatisticsTicketDetail(ResourceDetail):
  107     """
  108     detail by id
  109     """
  110     methods = ['GET']
  111     decorators = (api.has_permission('is_coorganizer', fetch="event_id", fetch_as="event_id", model=Ticket),)
  112     schema = OrderStatisticsTicketSchema
  113     data_layer = {'session': db.session,
  114                   'model': Ticket}
  115
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/app/api/order_statistics/tickets.py b/app/api/order_statistics/tickets.py
  --- a/app/api/order_statistics/tickets.py
  +++ b/app/api/order_statistics/tickets.py
  @@ -45,13 +45,16 @@
               OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()
           placed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
               OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()
  +        completed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
  +            OrderTicket.ticket_id == obj_id, Order.status == 'completed').scalar()
           result = {
               'total': total or 0,
               'draft': draft or 0,
               'cancelled': cancelled or 0,
               'pending': pending or 0,
               'expired': expired or 0,
  -            'placed': placed or 0
  +            'placed': placed or 0,
  +            'completed': completed or 0
           }
           return result
   
  @@ -68,13 +71,16 @@
                                                                                        Order.status == 'expired'))
           placed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,
                                                                                       Order.status == 'placed'))
  +        completed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,
  +                                                                                       Order.status == 'completed'))
           result = {
               'total': total or 0,
               'draft': draft or 0,
               'cancelled': cancelled or 0,
               'pending': pending or 0,
               'expired': expired or 0,
  -            'placed': placed or 0
  +            'placed': placed or 0,
  +            'completed': completed or 0
           }
           return result
   
  @@ -92,13 +98,16 @@
               OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()
           placed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
               OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()
  +        completed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(
  +            OrderTicket.ticket_id == obj_id, Order.status == 'completed').scalar()
           result = {
               'total': total or 0,
               'draft': draft or 0,
               'cancelled': cancelled or 0,
               'pending': pending or 0,
               'expired': expired or 0,
  -            'placed': placed or 0
  +            'placed': placed or 0,
  +            'completed': completed or 0
           }
           return result
  
verification_info: {"golden_diff": "diff --git a/app/api/order_statistics/tickets.py b/app/api/order_statistics/tickets.py\n--- a/app/api/order_statistics/tickets.py\n+++ b/app/api/order_statistics/tickets.py\n@@ -45,13 +45,16 @@\n             OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()\n         placed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n             OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()\n+        completed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n+            OrderTicket.ticket_id == obj_id, Order.status == 'completed').scalar()\n         result = {\n             'total': total or 0,\n             'draft': draft or 0,\n             'cancelled': cancelled or 0,\n             'pending': pending or 0,\n             'expired': expired or 0,\n-            'placed': placed or 0\n+            'placed': placed or 0,\n+            'completed': completed or 0\n         }\n         return result\n \n@@ -68,13 +71,16 @@\n                                                                                      Order.status == 'expired'))\n         placed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                     Order.status == 'placed'))\n+        completed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n+                                                                                       Order.status == 'completed'))\n         result = {\n             'total': total or 0,\n             'draft': draft or 0,\n             'cancelled': cancelled or 0,\n             'pending': pending or 0,\n             'expired': expired or 0,\n-            'placed': placed or 0\n+            'placed': placed or 0,\n+            'completed': completed or 0\n         }\n         return result\n \n@@ -92,13 +98,16 @@\n             OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()\n         placed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n             OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()\n+        completed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n+            OrderTicket.ticket_id == obj_id, Order.status == 'completed').scalar()\n         result = {\n             'total': total or 0,\n             'draft': draft or 0,\n             'cancelled': cancelled or 0,\n             'pending': pending or 0,\n             'expired': expired or 0,\n-            'placed': placed or 0\n+            'placed': placed or 0,\n+            'completed': completed or 0\n         }\n         return result\n", "issue": "'Completed' attribute missing from order-statistics API\n**I'm submitting a ...**  (check one with \"x\")\r\n- [x] bug report\r\n- [ ] feature request\r\n- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server\r\n\r\n**Current behavior:**\r\nRight now the response contains the following fields\r\n ```\r\n       \"placed\": 0,\r\n        \"draft\": 0,\r\n        \"cancelled\": 0,\r\n        \"total\": 0,\r\n        \"expired\": 0,\r\n        \"pending\": 0\r\n```\r\nThe attribute `completed` is missing from the response. \r\nImage for reference : https://user-images.githubusercontent.com/13910561/29230756-f5dabe20-7f01-11e7-8c5f-58ee69c38e65.png\r\n\r\n**Expected behavior:**\r\n`completed` attribute should be there.\n", "before_files": [{"content": "from flask_rest_jsonapi import ResourceDetail\nfrom marshmallow_jsonapi.flask import Schema\nfrom marshmallow_jsonapi import fields\nfrom sqlalchemy import func\n\nfrom app.api.helpers.utilities import dasherize\nfrom app.api.bootstrap import api\nfrom app.models import db\nfrom app.models.order import Order, OrderTicket\nfrom app.models.ticket import Ticket\nfrom app.api.helpers.db import get_count\n\n\nclass OrderStatisticsTicketSchema(Schema):\n    \"\"\"\n    Api schema\n    \"\"\"\n\n    class Meta:\n        \"\"\"\n        Meta class\n        \"\"\"\n        type_ = 'order-statistics-ticket'\n        self_view = 'v1.order_statistics_ticket_detail'\n        self_view_kwargs = {'id': '<id>'}\n        inflect = dasherize\n\n    id = fields.Str()\n    identifier = fields.Str()\n    tickets = fields.Method(\"tickets_count\")\n    orders = fields.Method(\"orders_count\")\n    sales = fields.Method(\"sales_count\")\n\n    def tickets_count(self, obj):\n        obj_id = obj.id\n        total = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id).scalar()\n        draft = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'draft').scalar()\n        cancelled = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'cancelled').scalar()\n        pending = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'pending').scalar()\n        expired = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()\n        placed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()\n        result = {\n            'total': total or 0,\n            'draft': draft or 0,\n            'cancelled': cancelled or 0,\n            'pending': pending or 0,\n            'expired': expired or 0,\n            'placed': placed or 0\n        }\n        return result\n\n    def orders_count(self, obj):\n        obj_id = obj.id\n        total = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id))\n        draft = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                   Order.status == 'draft'))\n        cancelled = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                       Order.status == 'cancelled'))\n        pending = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                     Order.status == 'pending'))\n        expired = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                     Order.status == 'expired'))\n        placed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                    Order.status == 'placed'))\n        result = {\n            'total': total or 0,\n            'draft': draft or 0,\n            'cancelled': cancelled or 0,\n            'pending': pending or 0,\n            'expired': expired or 0,\n            'placed': placed or 0\n        }\n        return result\n\n    def sales_count(self, obj):\n        obj_id = obj.id\n        total = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id).scalar()\n        draft = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'draft').scalar()\n        cancelled = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'cancelled').scalar()\n        pending = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'pending').scalar()\n        expired = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()\n        placed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()\n        result = {\n            'total': total or 0,\n            'draft': draft or 0,\n            'cancelled': cancelled or 0,\n            'pending': pending or 0,\n            'expired': expired or 0,\n            'placed': placed or 0\n        }\n        return result\n\n\nclass OrderStatisticsTicketDetail(ResourceDetail):\n    \"\"\"\n    detail by id\n    \"\"\"\n    methods = ['GET']\n    decorators = (api.has_permission('is_coorganizer', fetch=\"event_id\", fetch_as=\"event_id\", model=Ticket),)\n    schema = OrderStatisticsTicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n", "path": "app/api/order_statistics/tickets.py"}], "after_files": [{"content": "from flask_rest_jsonapi import ResourceDetail\nfrom marshmallow_jsonapi.flask import Schema\nfrom marshmallow_jsonapi import fields\nfrom sqlalchemy import func\n\nfrom app.api.helpers.utilities import dasherize\nfrom app.api.bootstrap import api\nfrom app.models import db\nfrom app.models.order import Order, OrderTicket\nfrom app.models.ticket import Ticket\nfrom app.api.helpers.db import get_count\n\n\nclass OrderStatisticsTicketSchema(Schema):\n    \"\"\"\n    Api schema\n    \"\"\"\n\n    class Meta:\n        \"\"\"\n        Meta class\n        \"\"\"\n        type_ = 'order-statistics-ticket'\n        self_view = 'v1.order_statistics_ticket_detail'\n        self_view_kwargs = {'id': '<id>'}\n        inflect = dasherize\n\n    id = fields.Str()\n    identifier = fields.Str()\n    tickets = fields.Method(\"tickets_count\")\n    orders = fields.Method(\"orders_count\")\n    sales = fields.Method(\"sales_count\")\n\n    def tickets_count(self, obj):\n        obj_id = obj.id\n        total = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id).scalar()\n        draft = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'draft').scalar()\n        cancelled = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'cancelled').scalar()\n        pending = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'pending').scalar()\n        expired = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()\n        placed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()\n        completed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'completed').scalar()\n        result = {\n            'total': total or 0,\n            'draft': draft or 0,\n            'cancelled': cancelled or 0,\n            'pending': pending or 0,\n            'expired': expired or 0,\n            'placed': placed or 0,\n            'completed': completed or 0\n        }\n        return result\n\n    def orders_count(self, obj):\n        obj_id = obj.id\n        total = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id))\n        draft = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                   Order.status == 'draft'))\n        cancelled = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                       Order.status == 'cancelled'))\n        pending = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                     Order.status == 'pending'))\n        expired = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                     Order.status == 'expired'))\n        placed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                    Order.status == 'placed'))\n        completed = get_count(db.session.query(Order).join(Order.order_tickets).filter(OrderTicket.ticket_id == obj_id,\n                                                                                       Order.status == 'completed'))\n        result = {\n            'total': total or 0,\n            'draft': draft or 0,\n            'cancelled': cancelled or 0,\n            'pending': pending or 0,\n            'expired': expired or 0,\n            'placed': placed or 0,\n            'completed': completed or 0\n        }\n        return result\n\n    def sales_count(self, obj):\n        obj_id = obj.id\n        total = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id).scalar()\n        draft = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'draft').scalar()\n        cancelled = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'cancelled').scalar()\n        pending = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'pending').scalar()\n        expired = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'expired').scalar()\n        placed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'placed').scalar()\n        completed = db.session.query(func.sum(Order.amount.label('sum'))).join(Order.order_tickets).filter(\n            OrderTicket.ticket_id == obj_id, Order.status == 'completed').scalar()\n        result = {\n            'total': total or 0,\n            'draft': draft or 0,\n            'cancelled': cancelled or 0,\n            'pending': pending or 0,\n            'expired': expired or 0,\n            'placed': placed or 0,\n            'completed': completed or 0\n        }\n        return result\n\n\nclass OrderStatisticsTicketDetail(ResourceDetail):\n    \"\"\"\n    detail by id\n    \"\"\"\n    methods = ['GET']\n    decorators = (api.has_permission('is_coorganizer', fetch=\"event_id\", fetch_as=\"event_id\", model=Ticket),)\n    schema = OrderStatisticsTicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n", "path": "app/api/order_statistics/tickets.py"}]}