예제 #1
0
 def test_invalid_report_when_toggle_is_on(self):
     EWS_INVALID_REPORT_RESPONSE.set(TEST_DOMAIN, True, NAMESPACE_DOMAIN)
     msg = 'Error! You submitted increases in stock levels of mg without corresponding receipts. ' \
           'Please contact your DHIO or RHIO for assistance.'
     StockTransaction.objects.all().delete()
     a = """
         5551234 > soh mg 25.0 jd 25.25
         5551234 < Dear {}, thank you for reporting the commodities you have in stock.
         5551234 < {}
     """.format(self.user1.full_name, msg)
     self.run_script(a)
     EWS_INVALID_REPORT_RESPONSE.set(TEST_DOMAIN, False, NAMESPACE_DOMAIN)
예제 #2
0
 def test_invalid_report_when_toggle_is_on(self):
     EWS_INVALID_REPORT_RESPONSE.set(TEST_DOMAIN, True, NAMESPACE_DOMAIN)
     msg = 'Error! You submitted increases in stock levels of mg without corresponding receipts. ' \
           'Please contact your DHIO or RHIO for assistance.'
     StockTransaction.objects.all().delete()
     a = """
         5551234 > soh mg 25.0 jd 25.25
         5551234 < Dear {}, thank you for reporting the commodities you have in stock.
         5551234 < {}
     """.format(self.user1.full_name, msg)
     self.run_script(a)
     EWS_INVALID_REPORT_RESPONSE.set(TEST_DOMAIN, False, NAMESPACE_DOMAIN)
예제 #3
0
    def handle(self):
        domain = Domain.get_by_name(self.domain)
        split_text = self.msg.text.split(' ', 1)
        if split_text[0].lower() == 'soh':
            text = split_text[1]
        elif split_text[0].startswith('soh'):
            text = split_text[0][3:]
        else:
            text = self.msg.text

        if not domain.commtrack_enabled:
            return False

        if not self.sql_location:
            self.respond(NO_SUPPLY_POINT_MESSAGE)
            return True

        try:
            parser = self.parser
            formatted_text = EWSFormatter().format(text)
            data = parser.parse(formatted_text)
            if not data:
                return False
            if EWS_INVALID_REPORT_RESPONSE.enabled(self.domain):
                filtered_transactions = self.get_valid_reports(data)

                if not filtered_transactions:
                    return True

                data['transactions'] = filtered_transactions

        except NotAUserClassError:
            return False
        except (SMSError, NoDefaultLocationException):
            self.respond(six.text_type(INVALID_MESSAGE))
            return True
        except ProductCodeException as e:
            self.respond(six.text_type(e))
            return True
        except Exception as e:
            if settings.UNIT_TESTING or settings.DEBUG:
                raise
            self.respond('problem with stock report: %s' % str(e))
            return True

        stockouts = set()
        if self.sql_location.location_type.name in ['Regional Medical Store', 'Central Medical Store']:
            stockouts = set(StockState.objects.filter(
                case_id=self.sql_location.supply_point_id,
                stock_on_hand=0
            ).values_list('sql_product__name', flat=True))

        process(domain.name, data)
        transactions = data['transactions']

        if not self.async_response:
            self.send_messages(parser, stockouts, transactions)
        else:
            send_soh_messages_task.delay(self, parser, stockouts, transactions)
        return True
예제 #4
0
파일: alerts.py 프로젝트: ekush/commcare-hq
    def handle(self):
        verified_contact = self.verified_contact
        user = verified_contact.owner
        domain = Domain.get_by_name(verified_contact.domain)
        splitted_text = self.msg.text.split()
        if splitted_text[0].lower() == 'soh':
            text = ' '.join(self.msg.text.split()[1:])
        else:
            text = self.msg.text

        if not domain.commtrack_enabled:
            return False
        try:
            data = StockAndReceiptParser(domain, verified_contact).parse(text)
            if not data:
                return False
            if EWS_INVALID_REPORT_RESPONSE.enabled(self.domain):
                filtered_transactions = self.get_valid_reports(
                    data, verified_contact)

                if not filtered_transactions:
                    return True

                data['transactions'] = filtered_transactions

        except NotAUserClassError:
            return False
        except Exception, e:  # todo: should we only trap SMSErrors?
            if settings.UNIT_TESTING or settings.DEBUG:
                raise
            send_sms_to_verified_number(
                verified_contact, 'problem with stock report: %s' % str(e))
            return True
예제 #5
0
파일: alerts.py 프로젝트: ekush/commcare-hq
    def handle(self):
        verified_contact = self.verified_contact
        user = verified_contact.owner
        domain = Domain.get_by_name(verified_contact.domain)
        splitted_text = self.msg.text.split()
        if splitted_text[0].lower() == "soh":
            text = " ".join(self.msg.text.split()[1:])
        else:
            text = self.msg.text

        if not domain.commtrack_enabled:
            return False
        try:
            data = StockAndReceiptParser(domain, verified_contact).parse(text)
            if not data:
                return False
            if EWS_INVALID_REPORT_RESPONSE.enabled(self.domain):
                filtered_transactions = self.get_valid_reports(data, verified_contact)

                if not filtered_transactions:
                    return True

                data["transactions"] = filtered_transactions

        except NotAUserClassError:
            return False
        except Exception, e:  # todo: should we only trap SMSErrors?
            if settings.UNIT_TESTING or settings.DEBUG:
                raise
            send_sms_to_verified_number(verified_contact, "problem with stock report: %s" % str(e))
            return True
예제 #6
0
    def handle(self):
        verified_contact = self.verified_contact
        domain = Domain.get_by_name(verified_contact.domain)
        split_text = self.msg.text.split(' ', 1)
        if split_text[0].lower() == 'soh':
            text = split_text[1]
        elif split_text[0].startswith('soh'):
            text = split_text[0][3:]
        else:
            text = self.msg.text

        if not domain.commtrack_enabled:
            return False

        if not self.sql_location:
            self.respond(NO_SUPPLY_POINT_MESSAGE)
            return True

        try:
            parser = EWSStockAndReceiptParser(domain, verified_contact)
            formatted_text = EWSFormatter().format(text)
            data = parser.parse(formatted_text)
            if not data:
                return False
            if EWS_INVALID_REPORT_RESPONSE.enabled(self.domain):
                filtered_transactions = self.get_valid_reports(data, verified_contact)

                if not filtered_transactions:
                    return True

                data['transactions'] = filtered_transactions

        except NotAUserClassError:
            return False
        except (SMSError, NoDefaultLocationException):
            send_sms_to_verified_number(verified_contact, unicode(INVALID_MESSAGE))
            return True
        except ProductCodeException as e:
            send_sms_to_verified_number(verified_contact, e.message)
            return True
        except Exception, e:  # todo: should we only trap SMSErrors?
            if settings.UNIT_TESTING or settings.DEBUG:
                raise
            send_sms_to_verified_number(verified_contact, 'problem with stock report: %s' % str(e))
            return True
예제 #7
0
    def handle(self):
        domain = Domain.get_by_name(self.domain)
        split_text = self.msg.text.split(' ', 1)
        if split_text[0].lower() == 'soh':
            text = split_text[1]
        elif split_text[0].startswith('soh'):
            text = split_text[0][3:]
        else:
            text = self.msg.text

        if not domain.commtrack_enabled:
            return False

        if not self.sql_location:
            self.respond(NO_SUPPLY_POINT_MESSAGE)
            return True

        try:
            parser = self.parser
            formatted_text = EWSFormatter().format(text)
            data = parser.parse(formatted_text)
            if not data:
                return False
            if EWS_INVALID_REPORT_RESPONSE.enabled(self.domain):
                filtered_transactions = self.get_valid_reports(data)

                if not filtered_transactions:
                    return True

                data['transactions'] = filtered_transactions

        except NotAUserClassError:
            return False
        except (SMSError, NoDefaultLocationException):
            self.respond(unicode(INVALID_MESSAGE))
            return True
        except ProductCodeException as e:
            self.respond(e.message)
            return True
        except Exception, e:  # todo: should we only trap SMSErrors?
            if settings.UNIT_TESTING or settings.DEBUG:
                raise
            self.respond('problem with stock report: %s' % str(e))
            return True
예제 #8
0
파일: soh.py 프로젝트: bazuzi/commcare-hq
    def handle(self):
        domain = Domain.get_by_name(self.domain)
        split_text = self.msg.text.split(" ", 1)
        if split_text[0].lower() == "soh":
            text = split_text[1]
        elif split_text[0].startswith("soh"):
            text = split_text[0][3:]
        else:
            text = self.msg.text

        if not domain.commtrack_enabled:
            return False

        if not self.sql_location:
            self.respond(NO_SUPPLY_POINT_MESSAGE)
            return True

        try:
            parser = self.parser
            formatted_text = EWSFormatter().format(text)
            data = parser.parse(formatted_text)
            if not data:
                return False
            if EWS_INVALID_REPORT_RESPONSE.enabled(self.domain):
                filtered_transactions = self.get_valid_reports(data)

                if not filtered_transactions:
                    return True

                data["transactions"] = filtered_transactions

        except NotAUserClassError:
            return False
        except (SMSError, NoDefaultLocationException):
            self.respond(unicode(INVALID_MESSAGE))
            return True
        except ProductCodeException as e:
            self.respond(e.message)
            return True
        except Exception, e:  # todo: should we only trap SMSErrors?
            if settings.UNIT_TESTING or settings.DEBUG:
                raise
            self.respond("problem with stock report: %s" % str(e))
            return True
예제 #9
0
    def handle(self):
        domain = Domain.get_by_name(self.domain)
        split_text = self.msg.text.split(' ', 1)
        if split_text[0].lower() == 'soh':
            text = split_text[1]
        elif split_text[0].startswith('soh'):
            text = split_text[0][3:]
        else:
            text = self.msg.text

        if not domain.commtrack_enabled:
            return False

        if not self.sql_location:
            self.respond(NO_SUPPLY_POINT_MESSAGE)
            return True

        try:
            parser = self.parser
            formatted_text = EWSFormatter().format(text)
            data = parser.parse(formatted_text)
            if not data:
                return False
            if EWS_INVALID_REPORT_RESPONSE.enabled(self.domain):
                filtered_transactions = self.get_valid_reports(data)

                if not filtered_transactions:
                    return True

                data['transactions'] = filtered_transactions

        except NotAUserClassError:
            return False
        except (SMSError, NoDefaultLocationException):
            self.respond(unicode(INVALID_MESSAGE))
            return True
        except ProductCodeException as e:
            self.respond(e.message)
            return True
        except Exception as e:  # todo: should we only trap SMSErrors?
            if settings.UNIT_TESTING or settings.DEBUG:
                raise
            self.respond('problem with stock report: %s' % str(e))
            return True

        stockouts = set()
        if self.sql_location.location_type.name in [
                'Regional Medical Store', 'Central Medical Store'
        ]:
            stockouts = set(
                StockState.objects.filter(
                    case_id=self.sql_location.supply_point_id,
                    stock_on_hand=0).values_list('sql_product__name',
                                                 flat=True))

        process(domain.name, data)
        transactions = data['transactions']

        if not self.async_response:
            self.send_messages(parser, stockouts, transactions)
        else:
            send_soh_messages_task.delay(self, parser, stockouts, transactions)
        return True