Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PEP8 formatted code.
  • Loading branch information
maxolasersquad committed Aug 28, 2015
1 parent 9d686fd commit 513c134
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
4 changes: 4 additions & 0 deletions inventory/api_views.py
Expand Up @@ -38,6 +38,7 @@ def api_root(request, format=None):


class ItemViewSet(viewsets.ModelViewSet):

"""
API endpoint that allows items to be viewed or edited.
"""
Expand All @@ -46,6 +47,7 @@ class ItemViewSet(viewsets.ModelViewSet):


class GroceryViewSet(viewsets.ModelViewSet):

"""
API endpoint that allows groceries to be viewed or edited.
"""
Expand All @@ -54,6 +56,7 @@ class GroceryViewSet(viewsets.ModelViewSet):


class ProduceViewSet(viewsets.ModelViewSet):

"""
API endpoint that allows produce to be viewed or edited.
"""
Expand All @@ -62,6 +65,7 @@ class ProduceViewSet(viewsets.ModelViewSet):


class VendorViewSet(viewsets.ModelViewSet):

"""
API endpoint that allows vendors to be viewed or edited.
"""
Expand Down
1 change: 1 addition & 0 deletions inventory/models.py
Expand Up @@ -57,6 +57,7 @@ class Produce(Item):


class Upc:

def __init__(self, upc):
self.upc = upc

Expand Down
4 changes: 4 additions & 0 deletions inventory/serializers.py
Expand Up @@ -20,24 +20,28 @@


class ItemSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = Item
depth = 1


class GrocerySerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = Grocery
depth = 1


class ProduceSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = Produce
depth = 1


class VendorSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = Vendor
depth = 1
4 changes: 4 additions & 0 deletions inventory/tests.py
Expand Up @@ -23,6 +23,7 @@


class VendorTest(TestCase):

def setUp(self):
self.vendor = Vendor(name='Brand X')

Expand All @@ -31,6 +32,7 @@ def test_vendor_name(self):


class GroceryTest(TestCase):

def setUp(self):
self.vendor = Vendor(name='Brand X')
self.grocery = Grocery(
Expand All @@ -50,6 +52,7 @@ def test_grocery_vendor(self):


class ProduceTest(TestCase):

def setUp(self):
self.produce = Produce(
name='Kumquat',
Expand All @@ -59,6 +62,7 @@ def setUp(self):


class UpcTest(TestCase):

def test_verify_correct_check_digit(self):
self.test_upc = Upc('008274000061')
self.assertEqual(self.test_upc.get_check_digit(), 1)
Expand Down
7 changes: 5 additions & 2 deletions register/api_views.py
Expand Up @@ -39,6 +39,7 @@ def api_root(request, format=None):


class ShiftViewSet(viewsets.ModelViewSet):

"""
API endpoint that allows shifts to be viewed or edited.
"""
Expand All @@ -47,6 +48,7 @@ class ShiftViewSet(viewsets.ModelViewSet):


class TransactionViewSet(viewsets.ModelViewSet):

"""
API endpoint that allows transactions to be viewed or edited.
"""
Expand All @@ -61,7 +63,7 @@ def ring_upc(self, request, *args, **kwargs):
upc = request.GET['upc']
quantity = request.GET['quantity']
if len(upc) != 12:
return Response('Invalid UPC', status=status.HTTP_400_BAD_REQUEST)
return Response('Invalid UPC', status=status.HTTP_400_BAD_REQUEST)
grocery = get_object_or_404(Grocery, upc=upc)
transaction = self.get_object()
line_item = transaction.create_line_item(grocery, 1)
Expand All @@ -75,7 +77,7 @@ def ring_plu(self, request, *args, **kwargs):
plu = request.GET['plu']
quantity = request.GET['quantity']
if 4 <= len(plu) <= 5:
return Response('Invalid PLU', status=status.HTTP_400_BAD_REQUEST)
return Response('Invalid PLU', status=status.HTTP_400_BAD_REQUEST)
produce = get_object_or_404(Produce, plu=plu)
transaction = self.get_object()
line_item = transaction.create_line_item(produce, 1)
Expand All @@ -97,6 +99,7 @@ def get_current(self, request, *args, **kwargs):


class LineItemViewSet(viewsets.ModelViewSet):

"""
API endpoint that allows line items to be viewed or edited.
"""
Expand Down
21 changes: 17 additions & 4 deletions register/models.py
Expand Up @@ -185,6 +185,7 @@ class Tender(models.Model):


class TransactionTotal():

def __init__(self, sub_total, tax_total, paid_total):
self.sub_total = sub_total
self.tax_total = tax_total
Expand All @@ -193,6 +194,7 @@ def __init__(self, sub_total, tax_total, paid_total):


class ShiftTotal():

def __init__(self, sub_total, tax_total, total, transaction_count):
self.sub_total = sub_total
self.tax_total = tax_total
Expand All @@ -201,6 +203,7 @@ def __init__(self, sub_total, tax_total, total, transaction_count):


class Receipt():

def __init__(self, transaction, lines=None):
self.transaction = transaction
self.header = settings.RECEIPT_HEADER
Expand Down Expand Up @@ -242,12 +245,16 @@ def print_body(self):
)
self.printer.print_line(
'Total: ' + "{:19,.2f}".format(trans_totals.sub_total +
trans_totals.tax_total) + ' Change: ' +
"{:20,.2f}".format(trans_totals.total) + '\n\n'
trans_totals.tax_total) +
' Change: ' +
"{:20,.2f}".format(
trans_totals.total)
+ '\n\n'
)


class ZReport():

def __init__(self, shift):
self.shift = shift
self.printer = Printer(settings.PRINTER)
Expand All @@ -258,15 +265,18 @@ def print(self):
self.printer.print_line(
'Transactions: ' + str(totals.transaction_count) + '\n'
)
self.printer.print_line('SubTotal: ' + str(totals.sub_total) + '\n')
self.printer.print_line('TaxTotal: ' + str(totals.tax_total) + '\n')
self.printer.print_line(
'SubTotal: ' + str(totals.sub_total) + '\n')
self.printer.print_line(
'TaxTotal: ' + str(totals.tax_total) + '\n')
self.printer.print_line('Total: ' + str(totals.total) + '\n')
self.printer.kick_drawer()
self.printer.cut()
self.printer.close()


class Printer():

def __init__(self, spool):
self.spool = spool

Expand Down Expand Up @@ -294,8 +304,11 @@ def kick_drawer(self):
chr(27) + chr(112) + chr(0) + chr(48) + '0' + chr(10)
)


class PrinterNotFound(Exception):

def __init__(self, value):
self.value = value

def __str__(self):
return self.value
3 changes: 3 additions & 0 deletions register/serializers.py
Expand Up @@ -20,15 +20,18 @@


class ShiftSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = Shift


class TransactionSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = Transaction


class LineItemSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = LineItem
8 changes: 8 additions & 0 deletions register/tests.py
Expand Up @@ -24,20 +24,25 @@


class ShiftTest(TestCase):

def setUp(self):
self.shift = Shift(begin_date=timezone.now())
self.shift.save()

def test_end_shift(self):
self.shift.end_shift()
self.assertIsNotNone(self.shift.finish_date)

def test_cannot_end_ended_shift(self):
self.shift.end_shift()
finish_date = self.shift.finish_date
self.shift.end_shift()
self.assertEqual(self.shift.finish_date, finish_date)

def test_create_transaction(self):
transaction = self.shift.create_transaction()
self.assertIsNotNone(transaction)

def test_cannot_create_transaction_on_ended_shift(self):
transaction = self.shift.create_transaction()
self.shift.end_shift()
Expand All @@ -46,6 +51,7 @@ def test_cannot_create_transaction_on_ended_shift(self):


class TransactionTest(TestCase):

def setUp(self):
self.shift = Shift(begin_date=timezone.now())
self.shift.save()
Expand Down Expand Up @@ -134,7 +140,9 @@ def test_cancel_ends_shift(self):
self.transaction.cancel()
self.assertIsNotNone(self.transaction.finish_date)


class LineItemTest(TestCase):

def setUp(self):
self.shift = Shift(begin_date=timezone.now())
self.shift.save()
Expand Down

0 comments on commit 513c134

Please sign in to comment.