Extras
This commit is contained in:
parent
a689dcfa1a
commit
4de65752ec
5 changed files with 57 additions and 4 deletions
|
@ -30,6 +30,7 @@ class OrderForm(Form):
|
||||||
|
|
||||||
class OrderItemForm(Form):
|
class OrderItemForm(Form):
|
||||||
product_id = SelectField('Item', coerce=int)
|
product_id = SelectField('Item', coerce=int)
|
||||||
|
extra = StringField('Extra')
|
||||||
submit_button = SubmitField('Submit')
|
submit_button = SubmitField('Submit')
|
||||||
|
|
||||||
def populate(self, location):
|
def populate(self, location):
|
||||||
|
|
26
app/migrations/versions/4e94c0b08ed_.py
Normal file
26
app/migrations/versions/4e94c0b08ed_.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
"""Add extra message
|
||||||
|
|
||||||
|
Revision ID: 4e94c0b08ed
|
||||||
|
Revises: 42709384216
|
||||||
|
Create Date: 2015-06-24 21:42:41.466973
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '4e94c0b08ed'
|
||||||
|
down_revision = '42709384216'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('order_item', sa.Column('extra', sa.String(length=254), nullable=True))
|
||||||
|
### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('order_item', 'extra')
|
||||||
|
### end Alembic commands ###
|
|
@ -102,12 +102,18 @@ class Order(db.Model):
|
||||||
user["paid"] = user.get("paid", True) and item.paid
|
user["paid"] = user.get("paid", True) and item.paid
|
||||||
user["products"] = user.get("products", []) + [item.product]
|
user["products"] = user.get("products", []) + [item.product]
|
||||||
group[item.get_name()] = user
|
group[item.get_name()] = user
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def group_by_product(self):
|
def group_by_product(self):
|
||||||
group = defaultdict(int)
|
group = dict()
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
group[item.product.name] += 1
|
product = group.get(item.product.name, dict())
|
||||||
|
product['count'] = product.get("count", 0) + 1
|
||||||
|
if item.extra:
|
||||||
|
product["extras"] = product.get("extras", []) + [item.extra]
|
||||||
|
group[item.product.name] = product
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def can_close(self, user_id):
|
def can_close(self, user_id):
|
||||||
|
@ -128,6 +134,7 @@ class OrderItem(db.Model):
|
||||||
order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False)
|
order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False)
|
||||||
product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
|
product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
|
||||||
paid = db.Column(db.Boolean, default=False)
|
paid = db.Column(db.Boolean, default=False)
|
||||||
|
extra = db.Column(db.String(254), nullable=True)
|
||||||
name = db.Column(db.String(120))
|
name = db.Column(db.String(120))
|
||||||
|
|
||||||
def configure(self, user, order, product):
|
def configure(self, user, order, product):
|
||||||
|
|
|
@ -18,3 +18,7 @@ body {
|
||||||
.full-width {
|
.full-width {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.product .extras {
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
|
@ -38,6 +38,11 @@
|
||||||
{{ form.product_id(class='form-control select') }}
|
{{ form.product_id(class='form-control select') }}
|
||||||
{{ util.render_form_field_errors(form.product_id) }}
|
{{ util.render_form_field_errors(form.product_id) }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group {{ 'has-errors' if form.product_id.errors }}">
|
||||||
|
{{ form.extra.label(class='control-label') }}<br>
|
||||||
|
{{ form.extra(class='form-control', placeholder='Fill in extras, when applicable') }}
|
||||||
|
{{ util.render_form_field_errors(form.extra) }}
|
||||||
|
</div>
|
||||||
{% if current_user.is_anonymous() %}
|
{% if current_user.is_anonymous() %}
|
||||||
<div class="form-group{{ ' has-error' if form.name.errors }}{{ ' required' if form.name.flags.required }}">
|
<div class="form-group{{ ' has-error' if form.name.errors }}{{ ' required' if form.name.flags.required }}">
|
||||||
{{ form.name.label(class='control-label') }}
|
{{ form.name.label(class='control-label') }}
|
||||||
|
@ -57,7 +62,7 @@
|
||||||
<h3>Items</h3>
|
<h3>Items</h3>
|
||||||
<table class="table table-hover table-condensed">
|
<table class="table table-hover table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th>Name</th><th>Item</th><th>Price</th>{% if courier_or_admin %}<th>Paid?</th>{% endif %}<th>Delete</th></tr>
|
<tr><th>Name</th><th>Item</th><th>Price</th><th>Extra</th>{% if courier_or_admin %}<th>Paid?</th>{% endif %}<th>Delete</th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in order.items -%}
|
{% for item in order.items -%}
|
||||||
|
@ -65,6 +70,7 @@
|
||||||
<td>{{ item.get_name() }}</td>
|
<td>{{ item.get_name() }}</td>
|
||||||
<td>{{ item.product.name }}</td>
|
<td>{{ item.product.name }}</td>
|
||||||
<td>{{ item.product.price|euro }}</td>
|
<td>{{ item.product.price|euro }}</td>
|
||||||
|
<td>{{ item.extra if item.extra }}</td>
|
||||||
{% if courier_or_admin %}<td>{% if not item.paid %} <a class="btn btn-xs btn-primary" href="{{ url_for('.item_paid', order_id=order.id, item_id=item.id) }}">Pay</a> {% else %} <span class="glyphicon glyphicon-chevron-down"></span> {% endif %}</td>{% endif %}
|
{% if courier_or_admin %}<td>{% if not item.paid %} <a class="btn btn-xs btn-primary" href="{{ url_for('.item_paid', order_id=order.id, item_id=item.id) }}">Pay</a> {% else %} <span class="glyphicon glyphicon-chevron-down"></span> {% endif %}</td>{% endif %}
|
||||||
<td>{% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}<a href="{{ url_for('.delete_item', order_id=order.id, item_id=item.id) }}"><span class="glyphicon glyphicon-remove"></span></a>{%- endif %}<br/></td>
|
<td>{% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}<a href="{{ url_for('.delete_item', order_id=order.id, item_id=item.id) }}"><span class="glyphicon glyphicon-remove"></span></a>{%- endif %}<br/></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -75,7 +81,16 @@
|
||||||
<div class="col-md-push-2 col-md-4 darker" id="items-ordered">
|
<div class="col-md-push-2 col-md-4 darker" id="items-ordered">
|
||||||
<h3>Ordered products:</h3>
|
<h3>Ordered products:</h3>
|
||||||
{% for key, value in order.group_by_product().items() -%}
|
{% for key, value in order.group_by_product().items() -%}
|
||||||
{{ key }} - {{ value }}<br/>
|
<div class="product">
|
||||||
|
{{ key }}: {{ value["count"] }}
|
||||||
|
{% if value["extras"] -%}
|
||||||
|
<div class="extras">
|
||||||
|
{% for extra in value["extras"] -%}
|
||||||
|
<div>{{ extra }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{%- endif %}
|
||||||
|
</div>
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue