Example #1
0
def sps_with_latest_status(sps, status_type, status_value, year, month):
    """
    This method is used by the dashboard.
    """
    # filter out people who submitted in the wrong month
    if status_type.startswith('rr'):
        sps = DeliveryGroups(month).submitting(sps, month)
    elif status_type.startswith('del'):
        sps = DeliveryGroups(month).delivering(sps, month)
    if not sps.count():
        return SupplyPoint.objects.none()
    inner = sps.filter(supplypointstatus__status_type=status_type,
                       supplypointstatus__status_date__month=month,
                       supplypointstatus__status_date__year=year)\
                        .annotate(max_sp_status_id=Max('supplypointstatus__id'))
    ids = SupplyPointStatus.objects.filter(status_type=status_type,
                                           status_value=status_value,
                                           id__in=inner.values('max_sp_status_id').query)\
                                           .distinct()\
                                            .values_list("supply_point", flat=True)
    f = sps.filter(id__in=ids)
    return f
Example #2
0
def sps_with_latest_status(sps, status_type, status_value, year, month):
    """
    This method is used by the dashboard.
    """
    # filter out people who submitted in the wrong month
    if status_type.startswith('rr'):
        sps = DeliveryGroups(month).submitting(sps, month)
    elif status_type.startswith('del'):
        sps = DeliveryGroups(month).delivering(sps, month)
    if not sps.count():
        return SupplyPoint.objects.none()
    inner = sps.filter(supplypointstatus__status_type=status_type,
                       supplypointstatus__status_date__month=month,
                       supplypointstatus__status_date__year=year)\
                        .annotate(max_sp_status_id=Max('supplypointstatus__id'))
    ids = SupplyPointStatus.objects.filter(status_type=status_type,
                                           status_value=status_value,
                                           id__in=inner.values('max_sp_status_id').query)\
                                           .distinct()\
                                            .values_list("supply_point", flat=True)
    f = sps.filter(id__in=ids)
    return f