Ejemplo n.º 1
0
 def setUp(self):
     TestScript.setUp(self)
     location = Location.objects.get(code='de')
     facilitytype = SupplyPointType.objects.get(code='hc')
     rms = Facility.objects.get(code='garms')
     facility = Facility(code='dedh', name='Dangme East District Hospital',
                    location=location, active=True,
                    type=facilitytype, supplied_by=rms)
     facility.save()
Ejemplo n.º 2
0
 def setUp(self):
     TestScript.setUp(self)
     location = Location.objects.get(code='de')
     facilitytype = SupplyPointType.objects.get(code='hc')
     rms = Facility.objects.get(code='garms')
     facility = Facility(code='dedh',
                         name='Dangme East District Hospital',
                         location=location,
                         active=True,
                         type=facilitytype,
                         supplied_by=rms)
     facility.save()
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def setUp(self):
        settings.LOGISTICS_STOCKED_BY = 'user'
        TestScript.setUp(self)
        location = Location.objects.get(code='de')
        facilitytype = SupplyPointType.objects.get(code='hc')
        self.rms = SupplyPoint.objects.get(code='garms')
        facility, created = SupplyPoint.objects.get_or_create(code='dedh',
                                                           name='Dangme East District Hospital',
                                                           location=location, active=True,
                                                           type=facilitytype, supplied_by=self.rms)
        assert facility.supplied_by == self.rms
        mc = Product.objects.get(sms_code='mc')
        self.lf = Product.objects.get(sms_code='lf')
        ProductStock(product=mc, supply_point=facility,
                     monthly_consumption=8).save()
        ProductStock(product=self.lf, supply_point=facility,
                     monthly_consumption=5).save()
        facility = SupplyPoint(code='tf', name='Test Facility',
                       location=location, active=True,
                       type=facilitytype, supplied_by=self.rms)
        facility.save()
        mc = Product.objects.get(sms_code='mc')
        mg = Product.objects.get(sms_code='mg')
        self.mc_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=mc, monthly_consumption=10)
        self.mc_stock.save()
        self.lf_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=self.lf, monthly_consumption=10)
        self.lf_stock.save()
        self.mg_stock = ProductStock(is_active=False, supply_point=facility,
                                     product=mg, monthly_consumption=10)
        self.mg_stock.save()

        ng = Product.objects.get(sms_code='ng')
        self.ng_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=ng, monthly_consumption=None)
        self.ng_stock.save()
        
        self.contact = Contact(name='test user')
        self.contact.save()
        self.connection = Connection(backend=Backend.objects.all()[0],
                                     identity="888",
                                     contact=self.contact)
        self.connection.save()
        self.contact.supply_point = facility
        self.contact.save()
        self.contact.commodities.add(ng)
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    def setUp(self):
        settings.LOGISTICS_STOCKED_BY = 'user'
        TestScript.setUp(self)
        location = Location.objects.get(code='de')
        facilitytype = SupplyPointType.objects.get(code='hc')
        self.rms = SupplyPoint.objects.get(code='garms')
        facility, created = SupplyPoint.objects.get_or_create(
            code='dedh',
            name='Dangme East District Hospital',
            location=location,
            active=True,
            type=facilitytype,
            supplied_by=self.rms)
        assert facility.supplied_by == self.rms
        mc = Product.objects.get(sms_code='mc')
        self.lf = Product.objects.get(sms_code='lf')
        ProductStock(product=mc, supply_point=facility,
                     monthly_consumption=8).save()
        ProductStock(product=self.lf,
                     supply_point=facility,
                     monthly_consumption=5).save()
        facility = SupplyPoint(code='tf',
                               name='Test Facility',
                               location=location,
                               active=True,
                               type=facilitytype,
                               supplied_by=self.rms)
        facility.save()
        mc = Product.objects.get(sms_code='mc')
        mg = Product.objects.get(sms_code='mg')
        self.mc_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=mc,
                                     monthly_consumption=10)
        self.mc_stock.save()
        self.lf_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=self.lf,
                                     monthly_consumption=10)
        self.lf_stock.save()
        self.mg_stock = ProductStock(is_active=False,
                                     supply_point=facility,
                                     product=mg,
                                     monthly_consumption=10)
        self.mg_stock.save()

        ng = Product.objects.get(sms_code='ng')
        self.ng_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=ng,
                                     monthly_consumption=None)
        self.ng_stock.save()

        self.contact = Contact(name='test user')
        self.contact.save()
        self.connection = Connection(backend=Backend.objects.all()[0],
                                     identity="888",
                                     contact=self.contact)
        self.connection.save()
        self.contact.supply_point = facility
        self.contact.save()
        self.contact.commodities.add(ng)