예제 #1
0
    def test_stock_on_hand_overstocked(self):
        with localize('sw'):
            reminder_trans = unicode(REMINDER_TRANS)
            soh_overstocked = unicode(SOH_OVERSTOCKED)
        script = """
            5551234 > Hmk Id 400 Dp 900 Ip 678
            5551234 < %(reminder_trans)s
        """ % {
            "reminder_trans": reminder_trans
        }
        self.run_script(script)

        stock_state = overstocked_products(self.facility.sql_location)
        self.assertListEqual([(u'dp', 900, 600), (u'ip', 678, 600)],
                             stock_state)

        script = """
            5551234 > Hmk Id 400 Dp 900 Ip 678
            5551234 < %(reminder_trans)s
            5551234 < %(soh_overstocked)s
        """ % {
            "reminder_trans": reminder_trans,
            "soh_overstocked": soh_overstocked % {
                'overstocked_list': 'dp: 900 ip: 678',
                'products_list': 'dp: 600 ip: 600'
            }
        }
        self.run_script(script)
예제 #2
0
    def send(self):
        for sql_location in self.get_sql_locations():
            stockedout_products_set = set(stockedout_products(sql_location))
            slab_config = SLABConfig.objects.get(sql_location=sql_location)
            overstocked_str = ""
            for closest_sql_location in slab_config.closest_supply_points.all(
            ):
                overstocked_products_set = set([
                    overstock[0]
                    for overstock in overstocked_products(closest_sql_location)
                ])
                intersection = stockedout_products_set.intersection(
                    overstocked_products_set)
                if intersection:
                    overstocked_str += "%s (%s)" % (closest_sql_location.name,
                                                    ', '.join(
                                                        sorted(intersection)))

            if not overstocked_str:
                continue

            for user in self.get_location_users(sql_location):
                send_translated_message(
                    user, REMINDER_STOCKOUT % {
                        'products_list': ', '.join(
                            sorted(stockedout_products_set)),
                        'overstocked_list': overstocked_str
                    })
예제 #3
0
파일: soh.py 프로젝트: kkrampa/commcare-hq
    def get_message(self, data):
        if not self._is_pilot_location():
            return SOH_CONFIRM
        else:
            overstocked_msg = ""
            products_msg = ""
            for product_code, stock_on_hand, six_month_consumption in overstocked_products(self.sql_location):
                overstocked_msg += "%s: %s " % (product_code, stock_on_hand)
                products_msg += "%s: %s " % (product_code, six_month_consumption)

            if overstocked_msg and products_msg:
                self.respond(
                    SOH_OVERSTOCKED, overstocked_list=overstocked_msg.strip(), products_list=products_msg.strip()
                )
            return REMINDER_TRANS
예제 #4
0
파일: soh.py 프로젝트: tstalka/commcare-hq
    def get_message(self, data):
        if not self._is_pilot_location():
            return SOH_CONFIRM
        else:
            overstocked_msg = ""
            products_msg = ""
            for product_code, stock_on_hand, six_month_consumption in overstocked_products(self.sql_location):
                overstocked_msg += "%s: %s " % (product_code, stock_on_hand)
                products_msg += "%s: %s " % (product_code, six_month_consumption)

            if overstocked_msg and products_msg:
                self.respond(
                    SOH_OVERSTOCKED, overstocked_list=overstocked_msg.strip(), products_list=products_msg.strip()
                )
            return REMINDER_TRANS
예제 #5
0
    def test_stock_on_hand_overstocked(self):
        with localize('sw'):
            reminder_trans = unicode(REMINDER_TRANS)
            soh_overstocked = unicode(SOH_OVERSTOCKED)
        script = """
            5551234 > Hmk Id 400 Dp 900 Ip 678
            5551234 < %(reminder_trans)s
        """ % {"reminder_trans": reminder_trans}
        self.run_script(script)

        stock_state = overstocked_products(self.facility.sql_location)
        self.assertListEqual([(u'dp', 900, 600), (u'ip', 678, 600)], stock_state)

        script = """
            5551234 > Hmk Id 400 Dp 900 Ip 678
            5551234 < %(reminder_trans)s
            5551234 < %(soh_overstocked)s
        """ % {"reminder_trans": reminder_trans,
               "soh_overstocked": soh_overstocked % {'overstocked_list': 'dp: 900 ip: 678',
                                                     'products_list': 'dp: 600 ip: 600'}}
        self.run_script(script)
예제 #6
0
    def send(self):
        for sql_location in self.get_sql_locations():
            stockedout_products_set = set(stockedout_products(sql_location))
            slab_config = SLABConfig.objects.get(sql_location=sql_location)
            overstocked_str = ""
            for closest_sql_location in slab_config.closest_supply_points.all():
                overstocked_products_set = set(
                    [overstock[0] for overstock in overstocked_products(closest_sql_location)]
                )
                intersection = stockedout_products_set.intersection(overstocked_products_set)
                if intersection:
                    overstocked_str += "%s (%s)" % (closest_sql_location.name, ', '.join(sorted(intersection)))

            if not overstocked_str:
                continue

            for user in self.get_location_users(sql_location):
                send_translated_message(user, REMINDER_STOCKOUT % {
                    'products_list': ', '.join(sorted(stockedout_products_set)),
                    'overstocked_list': overstocked_str
                })