Ejemplo n.º 1
0
def on_going_non_reporting():
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=21)
    domains = EWSGhanaConfig.get_all_enabled_domains()

    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            try:
                user_location = SQLLocation.objects.get(domain=domain, location_id=user.location._id)
            except AttributeError:
                continue
            if user_location:
                facilities = []
                if user_location.location_type == 'district':
                    facilities = user_location.get_children()
                elif user_location.location_type == 'region':
                    facilities = SQLLocation.objects.filter(domain=domain,
                                                            parent__parent__location_id=user.location._id)
                fac = set()
                for facility in facilities:
                    sp = facility.supply_point_id
                    if sp and not StockTransaction.objects.filter(
                            case_id=sp, type="stockonhand", report__date__gte=date).exists():
                        fac.add(str(facility.name))
                if fac and user.get_verified_number():
                    message = ONGOING_NON_REPORTING % " \n".join(fac)
                    send_sms_to_verified_number(user.get_verified_number(), message)
                    if user.email:
                        email = str(user.email)
                        send_mail('ONGOING NON REPORTING', message, '*****@*****.**', [email])
Ejemplo n.º 2
0
def third_soh_to_super():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        facilities = SQLLocation.objects.filter(
            location_type__name__in=reporting_types(domain))
        users = CommCareUser.by_domain(domain)
        third_soh_process_users_and_facilities(users, facilities)
Ejemplo n.º 3
0
def first_soh_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            role = user.user_data.get('role')
            if role and role != IN_CHARGE_ROLE:
                first_soh_process_user(user)
Ejemplo n.º 4
0
def second_soh_reminder():
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=DAYS_UNTIL_LATE)
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            second_soh_process_user(user, date)
Ejemplo n.º 5
0
def second_soh_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            roles = user.user_data.get('role')
            if roles and IN_CHARGE_ROLE in roles:
                second_soh_process_user(user)
Ejemplo n.º 6
0
def second_soh_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            roles = user.user_data.get('role')
            if roles and IN_CHARGE_ROLE in roles:
                second_soh_process_user(user)
Ejemplo n.º 7
0
def reminder_to_visit_website():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            thirteen_days_ago = datetime.datetime.utcnow() - datetime.timedelta(weeks=13)
            if user.location and user.last_login < thirteen_days_ago and user.get_verified_number()\
                    and user.location.location_type.name in ['district', 'region', 'country']:
                    message = WEB_REMINDER % user.name
                    verified_number = user.get_verified_number()
                    send_sms_to_verified_number(verified_number, message)
                    if can_receive_email(user, verified_number):
                        email = str(user.email)
                        send_mail('REMINDER TO VISIT WEBSITE', message, '*****@*****.**', [email])
Ejemplo n.º 8
0
def reminder_to_visit_website():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            if user.location and user.last_login < datetime.datetime.now() - datetime.timedelta(weeks=13) and\
                    user.get_verified_number() and \
                    (user.location.location_type == 'district' or user.location.location_type == 'region'
                     or user.location.location_type == 'country'):
                    message = WEB_REMINDER % user.name
                    send_sms_to_verified_number(user.get_verified_number(), message)
                    if user.email:
                        email = str(user.email)
                        send_mail('REMINDER TO VISIT WEBSITE', message, '*****@*****.**', [email])
Ejemplo n.º 9
0
def reminder_to_visit_website():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            thirteen_days_ago = datetime.datetime.utcnow(
            ) - datetime.timedelta(weeks=13)
            if user.location and user.last_login < thirteen_days_ago and user.get_verified_number()\
                    and user.location.location_type.name in ['district', 'region', 'country']:
                message = WEB_REMINDER % user.name
                verified_number = user.get_verified_number()
                send_sms_to_verified_number(verified_number, message)
                if can_receive_email(user, verified_number):
                    email = str(user.email)
                    send_mail('REMINDER TO VISIT WEBSITE', message,
                              '*****@*****.**', [email])
Ejemplo n.º 10
0
def report_reminder():
    sp_ids = set()
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=7)
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            if user.location:
                sp = SupplyPointCase.get_by_location(user.location)
                if sp and not StockTransaction.objects.filter(
                    case_id=sp._id, type="stockonhand", report__date__gte=date).exists()\
                        and user.get_verified_number():
                    sp_ids.add(sp._id)
                    message = REPORT_REMINDER % (user.name, user.location.name)
                    send_sms_to_verified_number(user.get_verified_number(), message)
                    if user.email:
                        email = str(user.email)
                        send_mail('REPORT REMINDER', message, '*****@*****.**', [email])
Ejemplo n.º 11
0
def urgent_stockout():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            try:
                user_location = SQLLocation.objects.get(domain=domain, location_id=user.location._id)
            except AttributeError:
                continue
            if user_location:
                facilities = []
                if user_location.location_type == 'district':
                    facilities = user_location.get_children()
                elif user_location.location_type == 'region':
                    facilities = SQLLocation.objects.filter(domain=domain,
                                                            parent__parent__location_id=user.location._id)
                elif user_location.location_type == 'country':
                    facilities = SQLLocation.objects.filter(domain=domain,
                                                            parent__parent__parent__location_id=user.location._id)
                stocked_out_products = set()
                fac = set()
                no_rep = 0
                for facility in facilities:
                    sp = facility.supply_point_id
                    if sp:
                        stocked_out = StockTransaction.objects.filter(
                            case_id=sp, type="stockonhand", stock_on_hand=0)
                        if stocked_out.exists():
                            no_rep += 1
                            fac.add(str(facility))
                            for product in stocked_out:
                                stocked_out_products.add(
                                    SQLProduct.objects.get(product_id=product.product_id).name)

                if fac and no_rep >= len(facilities) / 2 and user.get_verified_number():
                    message = URGENT_STOCKOUT % (user_location.name, ", ".join(sorted(
                        [str(product) for product in stocked_out_products])))
                    send_sms_to_verified_number(user.get_verified_number(), message)
                    if user.email:
                        email = str(user.email)
                        send_mail('URGENT STOCKOUT', message, '*****@*****.**', [email])
Ejemplo n.º 12
0
def reminder_to_visit_website():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        VisitWebsiteReminder(domain).send()
Ejemplo n.º 13
0
def stockout_notification_to_web_supers():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        StockoutReminder(domain).send()
Ejemplo n.º 14
0
def second_soh_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        SecondSOHReminder(domain).send()
Ejemplo n.º 15
0
def stockout_notification_to_web_supers():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        StockoutReminder(domain).send()
Ejemplo n.º 16
0
def second_soh_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        SecondSOHReminder(domain).send()
Ejemplo n.º 17
0
def urgent_stockout():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        UrgentStockoutAlert(domain).send()
Ejemplo n.º 18
0
def reminder_to_submit_rrirv():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            rrirv_process_user(user)
Ejemplo n.º 19
0
 def _get_logistics_domains(self):
     return ILSGatewayConfig.get_all_enabled_domains() + EWSGhanaConfig.get_all_enabled_domains()
Ejemplo n.º 20
0
def report_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            report_reminder_process_user(user)
Ejemplo n.º 21
0
def on_going_stockout():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            on_going_stockout_process_user(user)
Ejemplo n.º 22
0
def stockout_notification_to_web_supers():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            stockout_process_user(user)
Ejemplo n.º 23
0
def on_going_stockout():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        OnGoingStockouts(domain).send()
        OnGoingStockoutsRMS(domain).send()
Ejemplo n.º 24
0
def urgent_stockout():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        UrgentStockoutAlert(domain)
Ejemplo n.º 25
0
 def _get_logistics_domains(self):
     from custom.ewsghana.models import EWSGhanaConfig
     return ILSGatewayConfig.get_all_enabled_domains(
     ) + EWSGhanaConfig.get_all_enabled_domains()
Ejemplo n.º 26
0
def urgent_non_reporting():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        UrgentNonReporting(domain).send()
Ejemplo n.º 27
0
def third_soh_to_super():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        facilities = SQLLocation.objects.filter(location_type__name__in=reporting_types(domain))
        users = CommCareUser.by_domain(domain)
        third_soh_process_users_and_facilities(users, facilities)
Ejemplo n.º 28
0
def first_soh_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        FirstSOHReminder(domain).send()
Ejemplo n.º 29
0
def stockout_notification_to_web_supers():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            stockout_process_user(user)
Ejemplo n.º 30
0
def third_soh_to_super():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        ThirdSOHReminder(domain).send()
Ejemplo n.º 31
0
def reminder_to_submit_rrirv():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            rrirv_process_user(user)
Ejemplo n.º 32
0
def reminder_to_submit_rrirv():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        RRIRVReminder(domain).send()
Ejemplo n.º 33
0
def reminder_to_visit_website():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            visit_website_process_user(user)
Ejemplo n.º 34
0
def third_soh_to_super():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        ThirdSOHReminder(domain).send()
Ejemplo n.º 35
0
def urgent_non_reporting():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            urgent_non_reporting_process_user(user)
Ejemplo n.º 36
0
def reminder_to_submit_rrirv():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        RRIRVReminder(domain).send()
Ejemplo n.º 37
0
def report_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            report_reminder_process_user(user)
Ejemplo n.º 38
0
def on_going_non_reporting():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        OnGoingNonReporting(domain).send()
Ejemplo n.º 39
0
def on_going_non_reporting():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        OnGoingNonReporting(domain).send()
Ejemplo n.º 40
0
def urgent_non_reporting():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        UrgentNonReporting(domain)
Ejemplo n.º 41
0
def on_going_stockout():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        OnGoingStockouts(domain).send()
        OnGoingStockoutsRMS(domain).send()
Ejemplo n.º 42
0
def first_soh_reminder():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        FirstSOHReminder(domain).send()
Ejemplo n.º 43
0
def reminder_to_visit_website():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            visit_website_process_user(user)
Ejemplo n.º 44
0
 def _get_logistics_domains(self):
     from custom.ewsghana.models import EWSGhanaConfig
     return ILSGatewayConfig.get_all_enabled_domains() + EWSGhanaConfig.get_all_enabled_domains()
Ejemplo n.º 45
0
def reminder_to_visit_website():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        VisitWebsiteReminder(domain).send()
Ejemplo n.º 46
0
def on_going_stockout():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            on_going_stockout_process_user(user)
Ejemplo n.º 47
0
def urgent_non_reporting():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        for user in CommCareUser.by_domain(domain):
            urgent_non_reporting_process_user(user)