예제 #1
0
 def check_day(*args, **kwargs):
     comp = date_generator_func()
     appropriate_day = get_business_day_of_month_before(comp.year, comp.month, day)
     if comp.date() == appropriate_day:
         return f(*args, **kwargs)
     else:
         pass
예제 #2
0
def construct_soh_summary(location):
    now = datetime.utcnow()
    return construct_summary(
        location,
        SupplyPointStatusTypes.SOH_FACILITY,
        [SupplyPointStatusValues.SUBMITTED],
        get_business_day_of_month_before(now.year, now.month, 5)
    )
예제 #3
0
def construct_delivery_summary(location):
    now = datetime.utcnow()
    return construct_summary(
        location,
        SupplyPointStatusTypes.DELIVERY_FACILITY,
        [SupplyPointStatusValues.RECEIVED, SupplyPointStatusValues.NOT_RECEIVED],
        get_business_day_of_month_before(now.year, now.month, 5)
    )
예제 #4
0
def randr_reported_on_time(supply_point, year, month):
    reminder_date = datetime.combine(get_business_day_of_month_before(year, month, 5), time())
#    last_report = last_status_before(supply_point, get_business_day_of_month(year, month, -1), SupplyPointStatusTypes.R_AND_R_FACILITY, value=SupplyPointStatusValues.SUBMITTED)
    last_day_of_the_month = (datetime(year=year, month=month, day=1)+timedelta(days=32)).replace(day=1)-timedelta(seconds=1)
    last_report = last_status_before(supply_point, last_day_of_the_month, SupplyPointStatusTypes.R_AND_R_FACILITY, value=SupplyPointStatusValues.SUBMITTED)
    if last_report:
        return _reported_on_time(reminder_date, last_report.status_date)

    else:
        return OnTimeStates.NO_DATA
예제 #5
0
def soh_thank_you_task():
    """
    Last business day before the 20th at 4:00 PM Tanzania time
    """
    now = datetime.utcnow()
    business_day = get_business_day_of_month_before(month=now.month, year=now.year, day=20)
    if now.day != business_day.day:
        return

    last_month = datetime(now.year, now.month, 1) - timedelta(days=1)
    for domain in ILSGatewayConfig.get_all_enabled_domains():
        SOHThankYouReminder(domain=domain, date=last_month).send()
예제 #6
0
def soh_thank_you_task():
    """
    Last business day before the 20th at 4:00 PM Tanzania time
    """
    now = datetime.utcnow()
    business_day = get_business_day_of_month_before(month=now.month, year=now.year, day=20)
    if now.day != business_day.day:
        return

    last_month = datetime(now.year, now.month, 1) - timedelta(days=1)
    for domain in ILSGatewayConfig.get_all_enabled_domains():
        SOHThankYouReminder(domain=domain, date=last_month).send()
예제 #7
0
def randr_summary_task():
    """
        on 17th day of month or before if it's not a business day @ 3pm Tanzania time
    """

    now = datetime.utcnow()
    business_day = get_business_day_of_month_before(month=now.month, year=now.year, day=17)
    if now.day != business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(
                user, REMINDER_MONTHLY_RANDR_SUMMARY, **construct_randr_summary(user.location)
            )
예제 #8
0
def randr_summary_task():
    """
        on 17th day of month or before if it's not a business day @ 3pm Tanzania time
    """

    now = datetime.utcnow()
    business_day = get_business_day_of_month_before(month=now.month, year=now.year, day=17)
    if now.day != business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(
                user, REMINDER_MONTHLY_RANDR_SUMMARY, **construct_randr_summary(user.location)
            )
예제 #9
0
def randr_reported_on_time(supply_point, year, month):
    reminder_date = datetime.combine(
        get_business_day_of_month_before(year, month, 5), time())
    #    last_report = last_status_before(supply_point, get_business_day_of_month(year, month, -1), SupplyPointStatusTypes.R_AND_R_FACILITY, value=SupplyPointStatusValues.SUBMITTED)
    last_day_of_the_month = (datetime(year=year, month=month, day=1) +
                             timedelta(days=32)).replace(day=1) - timedelta(
                                 seconds=1)
    last_report = last_status_before(supply_point,
                                     last_day_of_the_month,
                                     SupplyPointStatusTypes.R_AND_R_FACILITY,
                                     value=SupplyPointStatusValues.SUBMITTED)
    if last_report:
        return _reported_on_time(reminder_date, last_report.status_date)

    else:
        return OnTimeStates.NO_DATA
예제 #10
0
    def handle(self):
        if len(self.args) < 2:
            return self.help()

        command = self.args[0]
        rest = " ".join(self.args[1:])
        msd_code = self.args[1].lower()
        fw_message = " ".join(self.args[2:])

        try:
            sql_location = SQLLocation.objects.get(domain=self.domain, site_code__iexact=msd_code)
        except SQLLocation.DoesNotExist:
            sql_location = self.get_district_by_name(rest)

        if not sql_location:
            self.respond(TEST_HANDLER_BAD_CODE, code=msd_code)
            return True

        if command in ['soh', 'hmk']:
            self.send_message(sql_location, SOH_HELP_MESSAGE)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(location_id=sql_location.location_id,
                                             status_type=SupplyPointStatusTypes.SOH_FACILITY,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['la']:
            self.send_message(sql_location, LOSS_ADJUST_HELP)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(location_id=sql_location.location_id,
                                             status_type=SupplyPointStatusTypes.LOSS_ADJUSTMENT_FACILITY,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['supervision']:
            self.send_message(sql_location, SUPERVISION_REMINDER)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(location_id=sql_location.location_id,
                                             status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['randr']:
            if sql_location.location_type.name == 'DISTRICT':
                self.send_message(sql_location, SUBMITTED_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT
            else:
                self.send_message(sql_location, SUBMITTED_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.R_AND_R_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(location_id=sql_location.location_id,
                                             status_type=status_type,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['delivery']:
            if sql_location.location_type.name == 'DISTRICT':
                self.send_message(sql_location, DELIVERY_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.DELIVERY_DISTRICT
            else:
                self.send_message(sql_location, DELIVERY_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.DELIVERY_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(location_id=sql_location.location_id,
                                             status_type=status_type,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['fw']:
            if fw_message:
                self.send_message(sql_location, fw_message)
        elif command in ["latedelivery"]:
            self.send_message(sql_location, DELIVERY_LATE_DISTRICT, group_name="changeme", group_total=1,
                              not_responded_count=2, not_received_count=3)
        elif command in ["randr_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_RANDR_SUMMARY, **reports.construct_summary(
                sql_location.couch_location,
                SupplyPointStatusTypes.R_AND_R_FACILITY,
                [SupplyPointStatusValues.SUBMITTED, SupplyPointStatusValues.NOT_SUBMITTED],
                get_business_day_of_month_before(now.year, now.month, 5)
            ))
        elif command in ["soh_report"]:
            now = datetime.utcnow()
            last_month = datetime(now.year, now.month, 1) - timedelta(days=1)
            self.respond(
                REMINDER_MONTHLY_SOH_SUMMARY,
                **reports.construct_summary(
                    sql_location.couch_location,
                    SupplyPointStatusTypes.SOH_FACILITY,
                    [SupplyPointStatusValues.SUBMITTED],
                    get_business_day_of_month_before(last_month.year, last_month.month, -1)
                )
            )
        elif command in ["delivery_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_DELIVERY_SUMMARY,
                         **reports.construct_summary(sql_location.couch_location,
                                                     SupplyPointStatusTypes.DELIVERY_FACILITY,
                                                     [SupplyPointStatusValues.RECEIVED,
                                                     SupplyPointStatusValues.NOT_RECEIVED],
                                                     get_business_day_of_month_before(now.year, now.month, 15)))
        elif command in ["soh_thank_you"]:
            self.send_message(sql_location, SOH_THANK_YOU)

        self.respond(TEST_HANDLER_CONFIRM)
        return True
예제 #11
0
def send_for_day(date, cutoff, reminder_class, **kwargs):
    now = datetime.utcnow()
    date = get_business_day_of_month_before(now.year, now.month, date)
    cutoff = get_business_day_of_month_before(now.year, now.month, cutoff)
    if now.day == date.day:
        send_for_all_domains(cutoff, reminder_class, **kwargs)
예제 #12
0
def get_facility_cutoff():
    now = datetime.utcnow()
    return get_business_day_of_month_before(now.year, now.month, 5)
예제 #13
0
def get_district_cutoff():
    now = datetime.utcnow()
    return get_business_day_of_month_before(now.year, now.month, 13)
예제 #14
0
    def handle(self):
        if len(self.args) < 2:
            return self.help()

        command = self.args[0]
        rest = " ".join(self.args[1:])
        msd_code = self.args[1]
        fw_message = " ".join(self.args[2:])

        loc = get_location(self.domain, None, msd_code) or self.get_district_by_name(rest)
        if not loc['location']:
            self.respond(TEST_HANDLER_BAD_CODE, code=msd_code)
            return

        if command in ['soh', 'hmk']:
            self.send_message(loc['location'], SOH_HELP_MESSAGE)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=SupplyPointStatusTypes.SOH_FACILITY,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['supervision']:
            self.send_message(loc['location'], SUPERVISION_REMINDER)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['randr']:
            if loc['location'].location_type == 'DISTRICT':
                self.send_message(loc['location'], SUBMITTED_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT
            else:
                self.send_message(loc['location'], SUBMITTED_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.R_AND_R_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=status_type,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['delivery']:
            if loc['location'].location_type == 'DISTRICT':
                self.send_message(loc['location'], DELIVERY_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.DELIVERY_DISTRICT
            else:
                self.send_message(loc['location'], DELIVERY_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.DELIVERY_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=status_type,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['fw']:
            if fw_message:
                self.send_message(loc['location'], fw_message)
        elif command in ["latedelivery"]:
            self.send_message(loc['location'], DELIVERY_LATE_DISTRICT, group_name="changeme", group_total=1,
                              not_responded_count=2, not_received_count=3)
            self.respond(TEST_HANDLER_CONFIRM)
        elif command in ["randr_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_RANDR_SUMMARY,
                         **reports.construct_summary(loc['case'],
                                                     SupplyPointStatusTypes.R_AND_R_FACILITY,
                                                     [SupplyPointStatusValues.SUBMITTED, SupplyPointStatusValues.NOT_SUBMITTED],
                                                     get_business_day_of_month_before(now.year, now.month, 5)))
        elif command in ["soh_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_SOH_SUMMARY,
                         **reports.construct_summary(loc['case'],
                                                     SupplyPointStatusTypes.SOH_FACILITY,
                                                     [SupplyPointStatusValues.SUBMITTED],
                                                     get_business_day_of_month_before(now.year, now.month, -1)))
        elif command in ["delivery_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_DELIVERY_SUMMARY,
                         **reports.construct_summary(loc['case'],
                                                     SupplyPointStatusTypes.DELIVERY_FACILITY,
                                                     [SupplyPointStatusValues.RECEIVED,
                                                     SupplyPointStatusValues.NOT_RECEIVED],
                                                     get_business_day_of_month_before(now.year, now.month, 15)))
        elif command in ["soh_thank_you"]:
            self.respond(SOH_THANK_YOU)
예제 #15
0
def send_for_day(date, cutoff, reminder_class, **kwargs):
    now = datetime.utcnow()
    date = get_business_day_of_month_before(now.year, now.month, date)
    cutoff = get_business_day_of_month_before(now.year, now.month, cutoff)
    if now.day == date.day:
        send_for_all_domains(cutoff, reminder_class, **kwargs)
예제 #16
0
 def testBusinessDaysBefore(self):
     self.assertEqual(date(2011, 8, 1), get_business_day_of_month_before(2011, 8, 1))
     self.assertEqual(date(2011, 8, 5), get_business_day_of_month_before(2011, 8, 5))
     self.assertEqual(date(2011, 8, 5), get_business_day_of_month_before(2011, 8, 6))
     self.assertEqual(date(2011, 8, 5), get_business_day_of_month_before(2011, 8, 7))
     self.assertEqual(date(2011, 8, 8), get_business_day_of_month_before(2011, 8, 8))
     
     # random 
     self.assertEqual(date(2011, 8, 26), get_business_day_of_month_before(2011, 8, 26))
     self.assertEqual(date(2011, 8, 26), get_business_day_of_month_before(2011, 8, 27))
     self.assertEqual(date(2011, 8, 29), get_business_day_of_month_before(2011, 8, 29))
     self.assertEqual(date(2011, 10, 14), get_business_day_of_month_before(2011, 10, 15))
     self.assertEqual(date(2011, 12, 20), get_business_day_of_month_before(2011, 12, 20))
     
     
     # fail
     try:
         get_business_day_of_month_before(2011, 10, 1)
         self.fail("previous call should have failed")
     except ValueError: pass
     
예제 #17
0
def get_district_cutoff():
    now = datetime.utcnow()
    return get_business_day_of_month_before(now.year, now.month, 13)
예제 #18
0
def get_facility_cutoff():
    now = datetime.utcnow()
    return get_business_day_of_month_before(now.year, now.month, 5)
예제 #19
0
    def handle(self):
        if len(self.args) < 2:
            return self.help()

        command = self.args[0]
        rest = " ".join(self.args[1:])
        msd_code = self.args[1]
        fw_message = " ".join(self.args[2:])

        loc = get_location(self.domain, None,
                           msd_code) or self.get_district_by_name(rest)
        if not loc['location']:
            self.respond(TEST_HANDLER_BAD_CODE, code=msd_code)
            return

        if command in ['soh', 'hmk']:
            self.send_message(loc['location'], SOH_HELP_MESSAGE)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(
                supply_point=loc['case']._id,
                status_type=SupplyPointStatusTypes.SOH_FACILITY,
                status_value=SupplyPointStatusValues.REMINDER_SENT,
                status_date=now)
        elif command in ['supervision']:
            self.send_message(loc['location'], SUPERVISION_REMINDER)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(
                supply_point=loc['case']._id,
                status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY,
                status_value=SupplyPointStatusValues.REMINDER_SENT,
                status_date=now)
        elif command in ['randr']:
            if loc['location'].location_type == 'DISTRICT':
                self.send_message(loc['location'], SUBMITTED_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT
            else:
                self.send_message(loc['location'], SUBMITTED_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.R_AND_R_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(
                supply_point=loc['case']._id,
                status_type=status_type,
                status_value=SupplyPointStatusValues.REMINDER_SENT,
                status_date=now)
        elif command in ['delivery']:
            if loc['location'].location_type == 'DISTRICT':
                self.send_message(loc['location'], DELIVERY_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.DELIVERY_DISTRICT
            else:
                self.send_message(loc['location'], DELIVERY_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.DELIVERY_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(
                supply_point=loc['case']._id,
                status_type=status_type,
                status_value=SupplyPointStatusValues.REMINDER_SENT,
                status_date=now)
        elif command in ['fw']:
            if fw_message:
                self.send_message(loc['location'], fw_message)
        elif command in ["latedelivery"]:
            self.send_message(loc['location'],
                              DELIVERY_LATE_DISTRICT,
                              group_name="changeme",
                              group_total=1,
                              not_responded_count=2,
                              not_received_count=3)
            self.respond(TEST_HANDLER_CONFIRM)
        elif command in ["randr_report"]:
            now = datetime.utcnow()
            self.respond(
                REMINDER_MONTHLY_RANDR_SUMMARY,
                **reports.construct_summary(
                    loc['case'], SupplyPointStatusTypes.R_AND_R_FACILITY, [
                        SupplyPointStatusValues.SUBMITTED,
                        SupplyPointStatusValues.NOT_SUBMITTED
                    ],
                    get_business_day_of_month_before(now.year, now.month, 5)))
        elif command in ["soh_report"]:
            now = datetime.utcnow()
            self.respond(
                REMINDER_MONTHLY_SOH_SUMMARY,
                **reports.construct_summary(
                    loc['case'], SupplyPointStatusTypes.SOH_FACILITY,
                    [SupplyPointStatusValues.SUBMITTED],
                    get_business_day_of_month_before(now.year, now.month, -1)))
        elif command in ["delivery_report"]:
            now = datetime.utcnow()
            self.respond(
                REMINDER_MONTHLY_DELIVERY_SUMMARY,
                **reports.construct_summary(
                    loc['case'], SupplyPointStatusTypes.DELIVERY_FACILITY, [
                        SupplyPointStatusValues.RECEIVED,
                        SupplyPointStatusValues.NOT_RECEIVED
                    ],
                    get_business_day_of_month_before(now.year, now.month, 15)))
        elif command in ["soh_thank_you"]:
            self.respond(SOH_THANK_YOU)
예제 #20
0
    def handle(self):
        if len(self.args) < 2:
            return self.help()

        command = self.args[0]
        rest = " ".join(self.args[1:])
        msd_code = self.args[1].lower()
        fw_message = " ".join(self.args[2:])

        try:
            sql_location = SQLLocation.objects.get(domain=self.domain,
                                                   site_code__iexact=msd_code)
        except SQLLocation.DoesNotExist:
            sql_location = self.get_district_by_name(rest)

        if not sql_location:
            self.respond(TEST_HANDLER_BAD_CODE, code=msd_code)
            return True

        if command in ['soh', 'hmk']:
            self.send_message(sql_location, SOH_HELP_MESSAGE)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(
                location_id=sql_location.location_id,
                status_type=SupplyPointStatusTypes.SOH_FACILITY,
                status_value=SupplyPointStatusValues.REMINDER_SENT,
                status_date=now)
        elif command in ['la']:
            self.send_message(sql_location, LOSS_ADJUST_HELP)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(
                location_id=sql_location.location_id,
                status_type=SupplyPointStatusTypes.LOSS_ADJUSTMENT_FACILITY,
                status_value=SupplyPointStatusValues.REMINDER_SENT,
                status_date=now)
        elif command in ['delivery']:
            if sql_location.location_type.name == 'DISTRICT':
                self.send_message(sql_location, DELIVERY_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.DELIVERY_DISTRICT
            else:
                self.send_message(sql_location, DELIVERY_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.DELIVERY_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(
                location_id=sql_location.location_id,
                status_type=status_type,
                status_value=SupplyPointStatusValues.REMINDER_SENT,
                status_date=now)
        elif command in ['fw']:
            if fw_message:
                self.send_message(sql_location, fw_message)
        elif command in ["latedelivery"]:
            self.send_message(sql_location,
                              DELIVERY_LATE_DISTRICT,
                              group_name="changeme",
                              group_total=1,
                              not_responded_count=2,
                              not_received_count=3)
        elif command in ["soh_report"]:
            now = datetime.utcnow()
            last_month = datetime(now.year, now.month, 1) - timedelta(days=1)
            self.respond(
                REMINDER_MONTHLY_SOH_SUMMARY,
                **reports.construct_summary(
                    sql_location, SupplyPointStatusTypes.SOH_FACILITY,
                    [SupplyPointStatusValues.SUBMITTED],
                    get_business_day_of_month_before(last_month.year,
                                                     last_month.month, -1)))
        elif command in ["delivery_report"]:
            now = datetime.utcnow()
            self.respond(
                REMINDER_MONTHLY_DELIVERY_SUMMARY,
                **reports.construct_summary(
                    sql_location, SupplyPointStatusTypes.DELIVERY_FACILITY, [
                        SupplyPointStatusValues.RECEIVED,
                        SupplyPointStatusValues.NOT_RECEIVED
                    ],
                    get_business_day_of_month_before(now.year, now.month, 15)))
        self.respond(TEST_HANDLER_CONFIRM)
        return True