Beispiel #1
0
def process_upc(request):
    code = request.POST['upc']
    quantity = request.POST['quantity']

    if len(code) == 12:
        upc = Upc(code)
        if upc.verify_check_digit():
            check = 'true'
            item = get_object_or_404(Grocery, upc=upc.upc[:-1])
        else:
            check = 'false'
            item = None
    else:
        check = 'true'
        item = get_object_or_404(Produce, plu=code)
    transaction = Transaction.get_current()
    line_item = transaction.create_line_item(item, 1)

    context_instance = {
        'item': item,
        'quantity': quantity,
        'check_passed': check,
        'transaction': transaction.get_totals(),
        'line_item': line_item
    }

    return render(request, 'register/process_upc.json', context_instance)
Beispiel #2
0
def process_upc(request):
    code = request.POST['upc']
    quantity = request.POST['quantity']

    if len(code) == 12:
        upc = Upc(code)
        if upc.verify_check_digit():
            check = 'true'
            item = get_object_or_404(Grocery, upc=upc.upc[:-1])
        else:
            check = 'false'
            item = None
    else:
        check = 'true'
        item = get_object_or_404(Produce, plu=code)
    transaction = Transaction.get_current()
    line_item = transaction.create_line_item(item, 1)

    context_instance = {
        'item': item,
        'quantity': quantity,
        'check_passed': check,
        'transaction': transaction.get_totals(),
        'line_item': line_item
    }

    return render(request, 'register/process_upc.json', context_instance)
Beispiel #3
0
class UpcTest(TestCase):
    def test_verify_correct_check_digit(self):
        self.test_upc = Upc('008274000061')
        self.assertEqual(self.test_upc.get_check_digit(), 1)
        self.test_upc = Upc('090341100019')
        self.assertEqual(self.test_upc.get_check_digit(), 9)
    def test_verify_check_digit_passes(self):
        self.test_upc = Upc('008274000061')
        self.assertTrue(self.test_upc.verify_check_digit())
        
    def test_verify_check_digit_fails(self):
        self.test_upc = Upc('008274000065')
        self.assertFalse(self.test_upc.verify_check_digit())
Beispiel #4
0
class UpcTest(TestCase):
    def test_verify_correct_check_digit(self):
        self.test_upc = Upc('008274000061')
        self.assertEqual(self.test_upc.get_check_digit(), 1)
        self.test_upc = Upc('090341100019')
        self.assertEqual(self.test_upc.get_check_digit(), 9)

    def test_verify_check_digit_passes(self):
        self.test_upc = Upc('008274000061')
        self.assertTrue(self.test_upc.verify_check_digit())

    def test_verify_check_digit_fails(self):
        self.test_upc = Upc('008274000065')
        self.assertFalse(self.test_upc.verify_check_digit())
Beispiel #5
0
 def test_verify_check_digit_fails(self):
     self.test_upc = Upc('008274000065')
     self.assertFalse(self.test_upc.verify_check_digit())
Beispiel #6
0
 def test_verify_check_digit_passes(self):
     self.test_upc = Upc('008274000061')
     self.assertTrue(self.test_upc.verify_check_digit())
Beispiel #7
0
 def test_verify_correct_check_digit(self):
     self.test_upc = Upc('008274000061')
     self.assertEqual(self.test_upc.get_check_digit(), 1)
     self.test_upc = Upc('090341100019')
     self.assertEqual(self.test_upc.get_check_digit(), 9)
Beispiel #8
0
 def test_verify_check_digit_fails(self):
     self.test_upc = Upc('008274000065')
     self.assertFalse(self.test_upc.verify_check_digit())
Beispiel #9
0
 def test_verify_check_digit_passes(self):
     self.test_upc = Upc('008274000061')
     self.assertTrue(self.test_upc.verify_check_digit())
Beispiel #10
0
 def test_verify_correct_check_digit(self):
     self.test_upc = Upc('008274000061')
     self.assertEqual(self.test_upc.get_check_digit(), 1)
     self.test_upc = Upc('090341100019')
     self.assertEqual(self.test_upc.get_check_digit(), 9)