Example #1
0
 def format(self, text):
     split_text = text.split(' ', 1)
     keyword = split_text[0].lower()
     content = ' '.join('{} {}'.format(code, amount) for code, amount in parse_report(split_text[1]))
     if keyword in ['delivered', 'dlvd', 'nimepokea']:
         text = 'delivered ' + content
     return text
Example #2
0
    def handle(self):
        keyword, content = self.msg.text.split(' ', 1)

        parsed_report = parse_report(content.replace('+', ''))
        if not parsed_report:
            self.respond(LOSS_ADJUST_BAD_FORMAT)
            return True

        report = StockReport.objects.create(
            form_id='ilsgateway-xform',
            date=datetime.utcnow(),
            type='balance',
            domain=self.domain
        )
        error = False
        for product_code, quantity in parsed_report:
            try:
                product_id = SQLProduct.objects.get(domain=self.domain, code__iexact=product_code).product_id
                self._create_stock_transaction(report, product_id, quantity)
            except SQLProduct.DoesNotExist:
                error = True
        if not error:
            self.respond(LOSS_ADJUST_CONFIRM)
        else:
            self.respond(LOSS_ADJUST_BAD_FORMAT)
        return True
Example #3
0
    def handle(self):
        keyword, content = self.msg.text.split(' ', 1)

        parsed_report = parse_report(content.replace('+', ''))
        if not parsed_report:
            self.respond(LOSS_ADJUST_BAD_FORMAT)
            return True

        now = datetime.utcnow()
        report = StockReport.objects.create(
            form_id='ilsgateway-xform',
            date=now,
            server_date=now,
            type='balance',
            domain=self.domain
        )
        error = False
        products_without_soh = set()
        for product_code, quantity in parsed_report:
            try:
                product_id = SQLProduct.objects.get(domain=self.domain, code__iexact=product_code).product_id
                self._create_stock_transaction(report, product_id, quantity)
            except SQLProduct.DoesNotExist:
                error = True
            except StockState.DoesNotExist:
                products_without_soh.add(product_code.lower())

        if error:
            self.respond(LOSS_ADJUST_BAD_FORMAT)
        elif products_without_soh:
            self.respond(LOSS_ADJUST_NO_SOH, products_list=', '.join(sorted(products_without_soh)))
        else:
            self.respond(LOSS_ADJUST_CONFIRM)
        return True
Example #4
0
 def format(self, text):
     split_text = text.split(' ', 1)
     keyword = split_text[0].lower()
     content = ' '.join('{} {}'.format(code, amount)
                        for code, amount in parse_report(split_text[1]))
     if keyword in ['delivered', 'dlvd', 'nimepokea']:
         text = 'delivered ' + content
     return text
Example #5
0
    def handle(self):
        keyword, content = self.msg.text.split(' ', 1)

        parsed_report = parse_report(content)
        if not parsed_report:
            self.respond(LOSS_ADJUST_BAD_FORMAT)

        report = StockReport.objects.create(
            form_id='ilsgateway-xform',
            date=datetime.utcnow(),
            type='balance',
            domain=self.domain
        )
        for product_code, quantity in parsed_report:
            product_id = SQLProduct.objects.get(domain=self.domain, code=product_code).product_id
            self._create_stock_transaction(report, product_id, quantity)
        self.respond(LOSS_ADJUST_CONFIRM)
Example #6
0
    def handle(self):
        sql_location = self.user.sql_location
        if not sql_location or sql_location.location_type.administrative:
            return True

        keyword, content = self.msg.text.split(' ', 1)

        parsed_report = parse_report(content.replace('+', ''))
        if not parsed_report:
            self.respond(LOSS_ADJUST_BAD_FORMAT)
            return True

        now = datetime.utcnow()
        error = False
        products_without_soh = set()
        with transaction.atomic():
            report = StockReport.objects.create(form_id='ilsgateway-xform',
                                                date=now,
                                                server_date=now,
                                                type='balance',
                                                domain=self.domain)
            for product_code, quantity in parsed_report:
                try:
                    product_id = SQLProduct.objects.get(
                        domain=self.domain,
                        code__iexact=product_code).product_id
                    self._create_stock_transaction(report, product_id,
                                                   quantity)
                except SQLProduct.DoesNotExist:
                    error = True
                except StockState.DoesNotExist:
                    products_without_soh.add(product_code.lower())
        if error:
            self.respond(LOSS_ADJUST_BAD_FORMAT)
        elif products_without_soh:
            self.respond(LOSS_ADJUST_NO_SOH,
                         products_list=', '.join(sorted(products_without_soh)))
        else:
            self.respond(LOSS_ADJUST_CONFIRM)
        return True
Example #7
0
 def test_simple_example(self):
     self.assertListEqual(parse_report('zi 10 co 20 la 30'), [('zi', 10),
                                                              ('co', 20),
                                                              ('la', 30)])
Example #8
0
 def test_handling_minus_with_whitespaces(self):
     self.assertListEqual(parse_report('zi -1O co +  2O la -  3O'),
                          [('zi', -10), ('co', 20), ('la', -30)])
Example #9
0
 def test_handling_whitespaces(self):
     self.assertListEqual(parse_report('zi10 co20 la30'), [('zi', 10), ('co', 20), ('la', 30)])
Example #10
0
 def test_simple_example(self):
     self.assertListEqual(parse_report("zi 10 co 20 la 30"), [("zi", 10), ("co", 20), ("la", 30)])
Example #11
0
 def test_handling_extra_spam(self):
     self.assertListEqual(
         parse_report("randomextradata zi1O co2O la3O randomextradata"), [("zi", 10), ("co", 20), ("la", 30)]
     )
Example #12
0
 def test_simple_example(self):
     self.assertListEqual(parse_report('zi 10 co 20 la 30'), [('zi', 10), ('co', 20), ('la', 30)])
Example #13
0
 def test_handling_minus_with_whitespaces(self):
     self.assertListEqual(parse_report('zi -1O co +  2O la -  3O'), [('zi', -10), ('co', 20), ('la', -30)])
Example #14
0
 def test_handling_extra_spam(self):
     self.assertListEqual(
         parse_report('randomextradata zi1O co2O la3O randomextradata'),
         [('zi', 10), ('co', 20), ('la', 30)]
     )
Example #15
0
 def test_handling_zeros(self):
     self.assertListEqual(parse_report('zi1O co2O la3O'), [('zi', 10), ('co', 20), ('la', 30)])
Example #16
0
 def test_handling_zeros(self):
     self.assertListEqual(parse_report("zi1O co2O la3O"), [("zi", 10), ("co", 20), ("la", 30)])
Example #17
0
 def test_handling_whitespaces(self):
     self.assertListEqual(parse_report('zi10 co20 la30'), [('zi', 10),
                                                           ('co', 20),
                                                           ('la', 30)])
Example #18
0
 def test_handling_minus_with_whitespaces(self):
     self.assertListEqual(parse_report("zi -1O co +  2O la -  3O"), [("zi", -10), ("co", 20), ("la", -30)])
Example #19
0
 def test_handling_zeros(self):
     self.assertListEqual(parse_report('zi1O co2O la3O'), [('zi', 10),
                                                           ('co', 20),
                                                           ('la', 30)])
Example #20
0
 def test_handling_whitespaces(self):
     self.assertListEqual(parse_report("zi10 co20 la30"), [("zi", 10), ("co", 20), ("la", 30)])
Example #21
0
 def test_handling_extra_spam(self):
     self.assertListEqual(
         parse_report('randomextradata zi1O co2O la3O randomextradata'),
         [('zi', 10), ('co', 20), ('la', 30)])