Example #1
0
    def testReminderSet(self):
        people = list(randr.get_facility_people(datetime.utcnow()))
        self.assertEqual(1, len(people))
        for person in people:
            self.assertEqual(self.contact, person)

        sp = self.contact.supply_point
        sp.groups = (SupplyPointGroup.objects.get\
                     (code=DeliveryGroups().current_delivering_group()),)
        sp.save()
        self.assertEqual(1, len(list(supervision.get_people())))

        supervision.set_supervision_statuses()

        self.assertEqual(0, len(list(supervision.get_people())))

        SupplyPointStatus.objects.all().delete()

        self.assertEqual(1, len(list(supervision.get_people())))

        s = SupplyPointStatus(
            supply_point=sp,
            status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY,
            status_value=SupplyPointStatusValues.RECEIVED)
        s.save()

        self.assertEqual(0, len(list(supervision.get_people())))
Example #2
0
 def setUp(self):
     super(TestSOHThankYou, self).setUp()
     Contact.objects.all().delete()
     self.contact = register_user(self, "778", "someone")
     sp = self.contact.supply_point
     sp.groups = (SupplyPointGroup.objects.get\
                  (code=DeliveryGroups().current_submitting_group()),)
     sp.save()
Example #3
0
    def testDeliveryGroupBasic(self):
        original_submitting = SupplyPoint.objects.filter\
            (type__code=SupplyPointCodes.FACILITY,
             groups__code=DeliveryGroups().current_submitting_group()).count()

        #add another submitting facility
        sp = SupplyPoint.objects.filter\
            (type__code=SupplyPointCodes.FACILITY).exclude\
            (groups__code=DeliveryGroups().current_submitting_group())[0]
        sp.groups = (SupplyPointGroup.objects.get\
                     (code=DeliveryGroups().current_submitting_group()),)
        sp.save()

        new_submitting = SupplyPoint.objects.filter\
            (type__code=SupplyPointCodes.FACILITY,
             groups__code=DeliveryGroups().current_submitting_group()).count()

        self.assertEqual(original_submitting + 1, new_submitting)
Example #4
0
def construct_randr_summary(supply_point):
    children = supply_point.children().filter(
        groups__code=DeliveryGroups().current_submitting_group())
    # assumes being run in the same month we care about.
    cutoff = randr.get_facility_cutoff()
    return _construct_status_dict(SupplyPointStatusTypes.R_AND_R_FACILITY, [
        SupplyPointStatusValues.SUBMITTED,
        SupplyPointStatusValues.NOT_SUBMITTED
    ], children, DateSpan(cutoff, datetime.utcnow()))
Example #5
0
 def setUp(self):
     super(TestDeliveryReminder, self).setUp()
     Contact.objects.all().delete()
     ProductReport.objects.all().delete()
     self.contact = register_user(self, "778", "someone")
     sp = self.contact.supply_point
     sp.groups = (SupplyPointGroup.objects.get\
                  (code=DeliveryGroups().current_delivering_group()),)
     sp.save()
Example #6
0
    def testGroupExclusion(self):
        people = list(delivery.get_facility_people(datetime.utcnow()))
        self.assertEqual(1, len(people))
        for person in people:
            self.assertEqual(self.contact, person)

        sp = self.contact.supply_point
        sp.groups = (SupplyPointGroup.objects.get\
                     (code=DeliveryGroups().current_submitting_group()),)
        sp.save()
        people = list(delivery.get_facility_people(datetime.utcnow()))
        self.assertEqual(0, len(people))

        sp = self.contact.supply_point
        sp.groups = (SupplyPointGroup.objects.get\
                     (code=DeliveryGroups().current_processing_group()),)
        sp.save()
        people = list(delivery.get_facility_people(datetime.utcnow()))
        self.assertEqual(0, len(people))
Example #7
0
def get_facility_people(cutoff):
    # Facilities:
    # Group A gets a reminder every three months starting in January.
    # Then it rotates accordingly.
    current_group = DeliveryGroups().current_submitting_group()

    for contact in Contact.objects.filter\
            (supply_point__type__code=SupplyPointCodes.FACILITY,
             supply_point__groups__code__in=current_group):
        if not contact.supply_point.supplypointstatus_set.filter\
                (status_type=SupplyPointStatusTypes.R_AND_R_FACILITY,
                 status_date__gte=cutoff).exists():
            yield contact
Example #8
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 #9
0
 def __init__(self, facilities=None, year=None, month=None):
     if not (year and month):
         self.month = datetime.utcnow().month
         self.year = datetime.utcnow().year
     else:
         self.month = month
         self.year = year
     if facilities is None:
         facilities = SupplyPoint.objects.filter(
             type__code="facility", contact__is_active=True).distinct()
     self.facilities = facilities
     self.report_month = self.month - 1 if self.month > 1 else 12
     self.report_year = self.year if self.report_month < 12 else self.year - 1
     self.dg = DeliveryGroups(month=month, facs=self.facilities)
     self._submission_chart = None
Example #10
0
def get_facility_people(cutoff):
    # Facilities:
    # Group A gets a reminder every three months starting in March.
    # Then it rotates accordingly.
    # All people at all Districts get all reminders each month.
    # For facilities the reminder should go out if we haven't received 
    # any status of type of del_fac
    current_group = DeliveryGroups().current_delivering_group()
    
    for contact in Contact.objects.filter\
            (supply_point__type__code=SupplyPointCodes.FACILITY,
             supply_point__groups__code__in=current_group):
        if not contact.supply_point.supplypointstatus_set.filter\
                (status_type=SupplyPointStatusTypes.DELIVERY_FACILITY,
                 status_date__gte=cutoff).exists():
            yield contact
    def setUp(self):
        super(TestReportSummaryBase, self).setUp()
        Contact.objects.all().delete()
        ProductReport.objects.all().delete()

        self.district_contact = register_user(self, "777", "someone")
        sp = SupplyPoint.objects.get(name="TEST DISTRICT")
        sp.groups = (SupplyPointGroup.objects.get\
                     (code=DeliveryGroups().current_submitting_group()),)
        self.district_contact.supply_point = sp
        self.district_contact.save()

        contact1 = register_user(self, "778", "Test User1", "d10001", "VETA 1")
        contact2 = register_user(self, "779", "Test User2", "d10002", "VETA 2")
        contact3 = register_user(self, "780", "Test User3", "d10003", "VETA 3")
        self.facility_contacts = [contact1, contact2, contact3]
        for contact in self.facility_contacts:
            # make sure parentage is right
            self.assertEqual(contact.supply_point.supplied_by,
                             self.district_contact.supply_point)
            # make sure group is right
            contact.supply_point.groups = (SupplyPointGroup.objects.get\
                                           (code=self.relevant_group),)
            contact.supply_point.save()
 def relevant_group(self):
     return DeliveryGroups().current_submitting_group()
 def relevant_group(self):
     # this doesn't really matter since it's relevant every month
     return DeliveryGroups().current_delivering_group()
 def relevant_group(self):
     return DeliveryGroups().current_delivering_group()
Example #15
0
 def submitting_group(self):
     return DeliveryGroups(self.month).current_submitting_group()