Esempio n. 1
0
def _supply_point_from_location(loc, type, parent=None):
    try:
        sp = SupplyPoint.objects.get(location=loc, type=type)
    except SupplyPoint.DoesNotExist:
        sp = SupplyPoint(location=loc)
    sp.name = loc.name
    sp.active = True
    sp.type = type
    sp.code = loc.code
    sp.supplied_by = parent
    sp.save()
    return sp
Esempio n. 2
0
def supply_point_from_location(loc, type, parent=None):
    """
    This utility is used by the loaders to create supply points from locations
    """
    try:
        sp = SupplyPoint.objects.get(location=loc, type=type)
    except SupplyPoint.DoesNotExist:
        sp = SupplyPoint(location=loc)
    sp.name = loc.name
    # sp.active = True
    sp.type = type
    sp.code = loc.code
    sp.supplied_by = parent
    try:
        sp.save()
    except:
        print sp
        raise
    
    return sp
Esempio n. 3
0
def create_supply_point_from_facility(f):
    """ this can't live inside of 'facility' since supply points from logistics
    can be decoupled from facilities from mtrack """
    try:
        f.type
    except HealthFacilityType.DoesNotExist:
        # db is still being initialized. 
        # we skip this step for now and return to it in mtrack_verify
        return None
    try:
        sp = SupplyPoint.objects.get(code=f.code)
    except SupplyPoint.DoesNotExist:
        sp = SupplyPoint(code=f.code)
        sp.name = f.name
        sp.active = True
        # what is this?
        default_loc = Location.tree.root_nodes()[0]
        sp.defaults = {'location':default_loc}
    sp.set_type_from_string(f.type.slug)
    sp.location = get_location_from_facility(f)
    sp.save()
    return sp