예제 #1
0
def on_going_process_user(user, test=False):
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=21)
    user_location = user.sql_location
    if not user_location:
        return

    facilities = []
    if user_location.location_type.name == 'district':
        facilities = user_location.get_children()
    elif user_location.location_type.name == 'region':
        facilities = SQLLocation.objects.filter(domain=user.domain,
                                                parent__parent__location_id=user.location._id)
    fac = set()
    for facility in facilities:
        sp = facility.supply_point_id
        if not sp:
            continue
        transactions_exist = StockTransaction.objects.filter(
            case_id=sp,
            type="stockonhand",
            report__date__gte=date
        ).exists()
        if not transactions_exist:
            fac.add(unicode(facility.name))
    verified_number = user.get_verified_number()
    if fac and verified_number:
        message = ONGOING_NON_REPORTING % " \n".join(fac)
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)
        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('ONGOING NON REPORTING', message, '*****@*****.**', [email])
예제 #2
0
def on_going_process_user(user, test=False):
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=21)
    user_location = user.sql_location
    if not user_location:
        return

    facilities = []
    if user_location.location_type.name == 'district':
        facilities = user_location.get_children()
    elif user_location.location_type.name == 'region':
        facilities = SQLLocation.objects.filter(
            domain=user.domain, parent__parent__location_id=user.location._id)
    fac = set()
    for facility in facilities:
        sp = facility.supply_point_id
        if not sp:
            continue
        transactions_exist = StockTransaction.objects.filter(
            case_id=sp, type="stockonhand", report__date__gte=date).exists()
        if not transactions_exist:
            fac.add(unicode(facility.name))
    verified_number = user.get_verified_number()
    if fac and verified_number:
        message = ONGOING_NON_REPORTING % " \n".join(fac)
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)
        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('ONGOING NON REPORTING', message,
                      '*****@*****.**', [email])
예제 #3
0
def report_reminder_process_user(user, test=False):
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=7)

    if not user.location or user.location.location_type.administrative:
        return
    sp = SupplyPointCase.get_by_location(user.location)
    if not sp:
        return
    transaction_exists = StockTransaction.objects.filter(
        case_id=sp._id,
        type="stockonhand",
        report__date__gte=date
    ).exists()
    if sp and not transaction_exists and user.get_verified_number():
        message = REPORT_REMINDER % (user.name, user.location.name)
        verified_number = user.get_verified_number()
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)

        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('REPORT REMINDER', message, '*****@*****.**', [email])
예제 #4
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])
예제 #5
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])
예제 #6
0
def urgent_stockout_process_user(user, test=False):
    user_location = user.sql_location
    if not user_location:
        return

    facilities = []
    if user_location.location_type.name == 'district':
        facilities = user_location.get_children()
    elif user_location.location_type.name == 'region':
        facilities = SQLLocation.objects.filter(
            domain=user.domain, parent__parent__location_id=user.location._id)
    elif user_location.location_type.name == 'country':
        facilities = SQLLocation.objects.filter(
            domain=user.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 = StockState.objects.filter(case_id=sp,
                                                    section_id="stockonhand",
                                                    stock_on_hand=0)
            if stocked_out.exists():
                no_rep += 1
                fac.add(unicode(facility))
                for product in stocked_out:
                    sql_product = SQLProduct.objects.get(
                        product_id=product.product_id)
                    stocked_out_products.add(sql_product.name)

    if fac and no_rep >= (len(facilities) / 2) and user.get_verified_number():
        stockout_str = ", ".join(
            sorted([unicode(product) for product in stocked_out_products]))
        message = URGENT_STOCKOUT % (user_location.name, stockout_str)
        verified_number = user.get_verified_number()
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)

        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('URGENT STOCKOUT', message,
                      '*****@*****.**', [email])
예제 #7
0
def urgent_stockout_process_user(user, test=False):
    user_location = user.sql_location
    if not user_location:
        return

    facilities = []
    if user_location.location_type.name == 'district':
        facilities = user_location.get_children()
    elif user_location.location_type.name == 'region':
        facilities = SQLLocation.objects.filter(domain=user.domain,
                                                parent__parent__location_id=user.location._id)
    elif user_location.location_type.name == 'country':
        facilities = SQLLocation.objects.filter(domain=user.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 = StockState.objects.filter(
                case_id=sp, section_id="stockonhand", stock_on_hand=0
            )
            if stocked_out.exists():
                no_rep += 1
                fac.add(unicode(facility))
                for product in stocked_out:
                    sql_product = SQLProduct.objects.get(product_id=product.product_id)
                    stocked_out_products.add(sql_product.name)

    if fac and no_rep >= (len(facilities) / 2) and user.get_verified_number():
        stockout_str = ", ".join(sorted(
            [unicode(product) for product in stocked_out_products]
        ))
        message = URGENT_STOCKOUT % (user_location.name, stockout_str)
        verified_number = user.get_verified_number()
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)

        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('URGENT STOCKOUT', message, '*****@*****.**', [email])
예제 #8
0
def report_reminder_process_user(user, test=False):
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=7)

    if not user.location or user.location.location_type.administrative:
        return
    sp = SupplyPointCase.get_by_location(user.location)
    if not sp:
        return
    transaction_exists = StockTransaction.objects.filter(
        case_id=sp._id, type="stockonhand", report__date__gte=date).exists()
    if sp and not transaction_exists and user.get_verified_number():
        message = REPORT_REMINDER % (user.name, user.location.name)
        verified_number = user.get_verified_number()
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)

        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('REPORT REMINDER', message,
                      '*****@*****.**', [email])
예제 #9
0
def urgent_non_reporting_process_user(user, test=False):
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=30)
    user_location = user.sql_location
    if not user_location:
        return
    facilities = []
    if user_location.location_type.name == 'district':
        facilities = user_location.get_children()
    elif user_location.location_type.name == 'region':
        facilities = SQLLocation.objects.filter(domain=user.domain,
                                                parent__parent__location_id=user.location._id)
    elif user_location.location_type.name == 'country':
        facilities = SQLLocation.objects.filter(domain=user.domain,
                                                parent__parent__parent__location_id=user.location._id)
    fac = set()
    no_rep = 0
    for facility in facilities:
        sp = facility.supply_point_id
        transaction_exists = StockTransaction.objects.filter(
            case_id=sp,
            type="stockonhand",
            report__date__gte=date
        ).exists()
        if sp and not transaction_exists:
            fac.add(unicode(facility.name))
            no_rep += 1
    if fac and no_rep >= len(facilities) / 2 and user.get_verified_number():
        message = URGENT_NON_REPORTING % user.location.name
        verified_number = user.get_verified_number()
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)
        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('URGENT NON REPORTING', message, '*****@*****.**', [email])
예제 #10
0
def urgent_non_reporting_process_user(user, test=False):
    now = datetime.datetime.utcnow()
    date = now - datetime.timedelta(days=30)
    user_location = user.sql_location
    if not user_location:
        return
    facilities = []
    if user_location.location_type.name == 'district':
        facilities = user_location.get_children()
    elif user_location.location_type.name == 'region':
        facilities = SQLLocation.objects.filter(
            domain=user.domain, parent__parent__location_id=user.location._id)
    elif user_location.location_type.name == 'country':
        facilities = SQLLocation.objects.filter(
            domain=user.domain,
            parent__parent__parent__location_id=user.location._id)
    fac = set()
    no_rep = 0
    for facility in facilities:
        sp = facility.supply_point_id
        transaction_exists = StockTransaction.objects.filter(
            case_id=sp, type="stockonhand", report__date__gte=date).exists()
        if sp and not transaction_exists:
            fac.add(unicode(facility.name))
            no_rep += 1
    if fac and no_rep >= len(facilities) / 2 and user.get_verified_number():
        message = URGENT_NON_REPORTING % user.location.name
        verified_number = user.get_verified_number()
        if not test:
            send_sms_to_verified_number(verified_number, message)
        else:
            send_test_message(verified_number, message)
        if can_receive_email(user, verified_number):
            email = str(user.email)
            send_mail('URGENT NON REPORTING', message,
                      '*****@*****.**', [email])