コード例 #1
0
ファイル: receipt.py プロジェクト: andile2012/logistics
 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()
コード例 #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()
コード例 #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
コード例 #4
0
ファイル: stockonhand.py プロジェクト: andile2012/logistics
    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)
コード例 #5
0
ファイル: stockonhand.py プロジェクト: dslowikowski/logistics
 def testProductReportsHelper(self):
     sdp = SupplyPoint()
     m = Message()
     p = ProductReportsHelper(sdp, Reports.SOH, m)
     p.add_product_stock('lf', 10, save=False)
     p.add_product_stock('mc', 30, save=False)
     p.add_product_stock('aa', 0, save=False)
     p.add_product_stock('oq', 0, save=False)
     self.assertEquals(p.all(), "lf 10, aa 0, oq 0, mc 30")
     self.assertEquals(p.stockouts(), "aa oq")
     my_iter = p._getTokens("ab10cd20")
     self.assertEquals(my_iter.next(), 'ab')
     self.assertEquals(my_iter.next(), '10')
     self.assertEquals(my_iter.next(), 'cd')
     self.assertEquals(my_iter.next(), '20')
コード例 #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
コード例 #7
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
コード例 #8
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
コード例 #9
0
ファイル: util.py プロジェクト: dslowikowski/logistics
def report_stock(test_class,
                 hsa,
                 product_string,
                 managers=None,
                 products_back=""):
    """
    Reports stock. 
    """

    stock_report = ProductReportsHelper(SupplyPoint(), Reports.SOH)
    stock_report.parse(product_string)
    product_list = " ".join(stock_report.reported_products()).strip()
    manager_msgs = []
    if managers:

        for manager in managers:
            "%(hsa)s needs the following products: %(products)s. Respond 'ready %(hsa_id)s' when products are ready for pick up."
            manager_msgs.append("""
                %(phone)s < %(confirm)s
            """ % {"phone": manager.default_connection.identity,
                   "confirm": config.Messages.SUPERVISOR_SOH_NOTIFICATION % \
                    {"hsa": hsa.name,
                     "products": products_back,
                     "hsa_id": hsa.supply_point.code}})
    a = """
           %(phone)s > soh %(products)s
           %(phone)s < %(confirm)s
           %(manager_msgs)s
        """ % {
        "phone": hsa.default_connection.identity,
        "products": product_string,
        "confirm": config.Messages.SOH_ORDER_CONFIRM % {
            "products": product_list
        },
        "manager_msgs": "".join(manager_msgs)
    }
    test_class.runScript(a)
コード例 #10
0
ファイル: stockonhand.py プロジェクト: dslowikowski/logistics
    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)