Skip to content

Commit

Permalink
Merge 64.colours, fix #64.
Browse files Browse the repository at this point in the history
This merge adds colour support to products and show products sorted by
colour in the order form.
  • Loading branch information
Epse committed Oct 1, 2018
2 parents eb6eb27 + aab4cc0 commit 9471422
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 10 deletions.
14 changes: 7 additions & 7 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ exclude =
.git,
# This doesn't actually contain any python
static,
pos/static
web/pos/static,
# This is a Django file which we don't edit
manage.py,
web/manage.py,
# No need to check caches
EpPos2/__pycache__,
pos/__pycahce__,
web/EpPos2/__pycache__,
web/pos/__pycahce__,
# This contains a lot of long Django settings strings
EpPos2/settings.py,
web/EpPos2/settings.py,
# This will contain local settings, if available
EpPos2/settings_local.py,
web/EpPos2/settings_local.py,
# These are autogenerated
pos/migrations
web/pos/migrations/
2 changes: 1 addition & 1 deletion web/pos/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class ProductAdmin(admin.ModelAdmin):

# List Page Display Configuration
list_display = (
'code',
'name',
'code',
'price',
'stock',
'minimum_stock',
Expand Down
18 changes: 18 additions & 0 deletions web/pos/migrations/0008_product_colour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.1 on 2018-10-01 10:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pos', '0007_product_minimum_stock'),
]

operations = [
migrations.AddField(
model_name='product',
name='colour',
field=models.CharField(choices=[('.blue', '.blue'), ('.green', '.green'), ('.yellow', '.yellow'), ('.orange', '.orange'), ('.purple', '.purple'), ('.black', '.black')], default='.blue', max_length=10),
),
]
18 changes: 18 additions & 0 deletions web/pos/migrations/0009_auto_20181001_1241.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.1 on 2018-10-01 10:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pos', '0008_product_colour'),
]

operations = [
migrations.AlterField(
model_name='product',
name='colour',
field=models.CharField(choices=[('blue', 'Blue'), ('green', 'Green'), ('yellow', 'Yellow'), ('orange', 'Orange'), ('purple', 'Purple'), ('black', 'Black')], default='blue', max_length=10),
),
]
18 changes: 18 additions & 0 deletions web/pos/migrations/0010_auto_20181001_1404.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.1 on 2018-10-01 12:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pos', '0009_auto_20181001_1241'),
]

operations = [
migrations.AlterField(
model_name='product',
name='colour',
field=models.CharField(choices=[('blue', 'Blue'), ('green', 'Green'), ('yellow', 'Yellow'), ('orange', 'Orange'), ('purple', 'Purple'), ('black', 'Black'), ('pink', 'Pink'), ('cyan', 'Cyan')], default='blue', max_length=10),
),
]
24 changes: 24 additions & 0 deletions web/pos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,37 @@ def validate_product_name(prodname):


class Product(models.Model):
# The different colours, to use as Product.<colour>
BLUE = "blue"
GREEN = "green"
YELLOW = "yellow"
ORANGE = "orange"
PURPLE = "purple"
BLACK = "black"
PINK = "pink"
CYAN = "cyan"

# Colour choices
COLOUR_CHOICES = (
(BLUE, "Blue"),
(GREEN, "Green"),
(YELLOW, "Yellow"),
(ORANGE, "Orange"),
(PURPLE, "Purple"),
(BLACK, "Black"),
(PINK, "Pink"),
(CYAN, "Cyan"),
)

name = models.CharField(max_length=100,
validators=[validate_product_name])
price = models.DecimalField(max_digits=7, decimal_places=2)
stock_applies = models.BooleanField()
minimum_stock = models.PositiveSmallIntegerField(default=0)
stock = models.IntegerField(default=0)
code = models.CharField(max_length=50, unique=True, null=True, blank=True)
colour = models.CharField(max_length=10,
choices=COLOUR_CHOICES, default="blue")

def __str__(self):
return self.name
Expand Down
36 changes: 35 additions & 1 deletion web/pos/templates/pos/order.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-TileImage" content="{% static "pos/img/mstile-144x144.png" %}">
<meta name="theme-color" content="#ffffff">

<style>
.green {
background-color: #86ff4f;
border-color: #86ff4f;
color: #373438;
}
.yellow {
background-color: #ffff4f;
border-color: #ffff4f;
color: #373438;
}
.orange {
background-color: #f48709;
border-color: #f48709;
}
.purple {
background-color: #dd09f4;
border-color: #dd09f4;
}
.black {
background-color: #373438;
border-color: #373438;
}
.pink {
background-color: #fc5eff;
border-color: #fc5eff;
color: #373438;
}
.cyan {
background-color: #43d3ca;
border-color: #43d3ca;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
Expand Down Expand Up @@ -89,7 +123,7 @@
{% if list %}
{% for product in list %}
<div class="col-sm-6 col-md-3" style="padding-top: 5px; padding-bottom: 5px;">
<a role="button" class="btn btn-primary btn-block"
<a role="button" class="btn btn-primary btn-block {{ product.colour }}"
href="#"
onclick="addProduct({{ product.id }});">
{{ product.name }}<br>{{ currency }}{{ product.price }}
Expand Down
3 changes: 2 additions & 1 deletion web/pos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def login(request):

@login_required
def order(request):
list = Product.objects.all
# Sort products by colour, then by name
list = Product.objects.order_by('colour', 'name')
currency = helper.get_currency()

context = {
Expand Down

0 comments on commit 9471422

Please sign in to comment.