def fema():
    """
        Custom Report to list all open requests for items that FEMA can supply

        @ToDo: Filter to just Sites that FEMA support
    """

    ritable = s3db.req_req_item
    rtable = db.req_req
    itable = db.supply_item
    ictable = db.supply_item_category
    citable = db.supply_catalog_item
    query = (ictable.name == "FEMA") & \
            (citable.item_category_id == ictable.id) & \
            (citable.item_id == itable.id) & \
            (itable.deleted != True)
    fema_items = db(query).select(itable.id)
    fema_item_ids = [item.id for item in fema_items]

    REQ_STATUS_COMPLETE = 2
    s3.filter = (rtable.deleted != True) & \
                (rtable.is_template == False) & \
                (rtable.commit_status != REQ_STATUS_COMPLETE) & \
                (rtable.transit_status != REQ_STATUS_COMPLETE) & \
                (rtable.fulfil_status != REQ_STATUS_COMPLETE) & \
                (ritable.req_id == rtable.id) & \
                (ritable.quantity > ritable.quantity_commit) & \
                (ritable.quantity_transit > ritable.quantity) & \
                (ritable.quantity > ritable.quantity_fulfil) & \
                (ritable.deleted != True) & \
                (ritable.item_id.belongs(fema_item_ids))

    # Filter Widgets
    filter_widgets = [
        s3base.S3OptionsFilter("req_id$site_id",
                               label = T("Facility"),
                               #cols = 3,
                               ),
    ]
    s3db.configure("req_req_item", filter_widgets = filter_widgets)

    return req_item()

# -----------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/controllers/req.py/fema/swapped operands of `>`