def get_message_for_location(self, location):
        supply_point = SupplyInterface(location.domain).get_by_location(location)
        if not supply_point:
            return

        on_time_products, missing_products = report_status(location.sql_location, days_until_late=DAYS_UNTIL_LATE)

        if not on_time_products:
            return SECOND_STOCK_ON_HAND_REMINDER, {}
        elif missing_products:
            products_names = ', '.join([
                product.name
                for product in missing_products
            ])

            return SECOND_INCOMPLETE_SOH_REMINDER, {'products': products_names}

        return None, {}
Example #2
0
 def get_consumption(self, loc):
     if (not self.include_consumption
             or loc.location_type_name in self.administrative_types
             or not self.consumption_dict):
         return {}
     if loc.location_id in self.supply_point_map:
         sp_id = self.supply_point_map[loc.location_id]
     else:
         # this only happens if the supply point case did
         # not already exist
         sp_id = SupplyInterface(
             self.domain).get_or_create_by_location(loc).location_id
     return {
         p.code: get_loaded_default_monthly_consumption(
             self.consumption_dict, self.domain, p._id,
             loc.location_type_name, sp_id) or ''
         for p in self.products
     }
Example #3
0
    def __init__(self, domain, verified_contact, location=None):
        self.domain = domain
        self.verified_contact = verified_contact

        self.location = location
        self.case = None
        u = verified_contact.owner

        if domain.commtrack_enabled:
            # if user is not actually a user, we let someone else process
            if not isinstance(u, CouchUser):
                raise NotAUserClassError

            if not self.location:
                self.location = u.location

            if self.location:
                self.case = SupplyInterface(domain.name).get_by_location(self.location)

        self.commtrack_settings = domain.commtrack_settings
Example #4
0
def make_supply_point(domain, location):
    # a supply point is currently just a case with a special type
    case_id = uuid.uuid4().hex
    user_id = const.get_commtrack_user_id(domain)
    owner_id = location.location_id
    kwargs = {
        'external_id': location.external_id
    } if location.external_id else {}
    caseblock = CaseBlock(case_id=case_id,
                          create=True,
                          case_name=location.name,
                          user_id=user_id,
                          owner_id=owner_id,
                          case_type=const.SUPPLY_POINT_CASE_TYPE,
                          update={
                              'location_id': location.location_id,
                          },
                          **kwargs)
    _submit_commtrack_caseblock(domain, caseblock, "make_supply_point")
    return SupplyInterface(domain).get_supply_point(case_id)
Example #5
0
def bootstrap_user(loc,
                   username=TEST_USER,
                   domain=TEST_DOMAIN,
                   phone_number=TEST_NUMBER,
                   password=TEST_PASSWORD,
                   backend=TEST_BACKEND,
                   first_name='',
                   last_name='',
                   home_loc=None,
                   user_data=None,
                   language=None):
    user_data = user_data or {}
    user = CommCareUser.create(domain,
                               username,
                               password,
                               user_data=user_data,
                               first_name=first_name,
                               last_name=last_name)
    if language:
        user.language = language
    if home_loc == loc.site_code:
        interface = SupplyInterface(domain)
        if not interface.get_by_location(loc):
            interface.create_from_location(domain, loc)

        user.set_location(loc)

    user.phone_numbers = [phone_number]
    user.save()

    entry = user.get_or_create_phone_entry(phone_number)
    entry.set_two_way()
    entry.set_verified()
    entry.backend_id = backend
    entry.save()
    return CommCareUser.wrap(user.to_json())
Example #6
0
 def setUp(self):
     super(LocationsTest, self).setUp()
     self.accessor = SupplyInterface(self.domain.name)
     self.user = self.users[0]
Example #7
0
def get_supply_point_and_location(domain, site_code):
    location = Location.by_site_code(domain, site_code)
    if location:
        case = SupplyInterface(domain).get_by_location(location)