Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>
Add Status to Order and allow user to save order as draft
src/alembic/versions/b1a2b379ee3d_add_status_to_order.py | 24 ++++++++++ src/blueprints/cycles.py | 2 src/blueprints/orders.py | 13 +++++ src/templates/cycle.html | 9 +++ src/types/order.py | 17 +++++++
diff --git a/src/alembic/versions/b1a2b379ee3d_add_status_to_order.py b/src/alembic/versions/b1a2b379ee3d_add_status_to_order.py new file mode 100644 index 0000000000000000000000000000000000000000..b4c3e533052371a95004af97415374e16f9cba80 --- /dev/null +++ b/src/alembic/versions/b1a2b379ee3d_add_status_to_order.py @@ -0,0 +1,24 @@ +"""add status to order + +Revision ID: b1a2b379ee3d +Revises: 6454dfce4c2d +Create Date: 2019-12-17 01:33:05.734684 + +""" +from alembic import op +from sqlalchemy import Column +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b1a2b379ee3d' +down_revision = '6454dfce4c2d' +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column('orders', Column('status', sa.String(255), server_default = 'draft')) + +def downgrade(): + op.drop_column('orders', 'status') diff --git a/src/blueprints/cycles.py b/src/blueprints/cycles.py index e7c158ee4502e7a05cb04abae31411f4fdce9cc9..f53f1c30ed28e9ae5e0b27680054399394bb0024 100644 --- a/src/blueprints/cycles.py +++ b/src/blueprints/cycles.py @@ -1,10 +1,12 @@ from flask import Blueprint, jsonify, url_for, request, render_template, redirect from flask_login import current_user + import pdb cycles = Blueprint('cycles', __name__, url_prefix = '/cycles') from ..types.cycle import Cycle, CycleStatus from ..types.product import Product +from ..types.order import OrderStatus @cycles.route('/', methods = ['GET', 'POST']) def index(): diff --git a/src/blueprints/orders.py b/src/blueprints/orders.py index c753fc04f9fc494ab058041c0d156f9d57edc4b6..c4004faa9754f45b56f48d1b0e1238e1b3bf70a1 100644 --- a/src/blueprints/orders.py +++ b/src/blueprints/orders.py @@ -3,6 +3,7 @@ from flask_login import current_user from ..types.cycle import Cycle, CycleStatus from ..types.order import Order +import pdb orders = Blueprint('orders', __name__, url_prefix = '/orders') @@ -25,5 +26,17 @@ if not order: order = Order.create_for(current_user, current_cycle) order.add_products(request.form.getlist('product_ids')) + + if 'confirm' in request.form: + order.confirm() return redirect(url_for('cycles.show', id = current_cycle.id)) + +@orders.route('/<id>/reopen', methods = ['GET']) +def reopen(id): + order = Order.query.get(id) + + order.reopen() + + current_cycle = Cycle.query.filter_by(status = CycleStatus.published).first() + return redirect(url_for('cycles.show', id = current_cycle.id)) diff --git a/src/templates/cycle.html b/src/templates/cycle.html index bc9a853bec2b8d21d4245fb79a557217001bc150..aaf644830a6f5067f25e6911fd2c6f1edf155e4a 100644 --- a/src/templates/cycle.html +++ b/src/templates/cycle.html @@ -3,6 +3,10 @@{{ cycle.name }}
<em>{{ cycle.description }}</em> </section> +{% if current_order.status.value == 'confirmed' %} +<strong> Seu pedido está {{ current_order.status.value }} <a href="{{ url_for('orders.reopen', id = current_order.id) }}">Deseja reabrir?</a></strong> +{% endif %} + <section> {% if not current_order %} <strong>Você não tem um pedido nesse ciclo. <a href="{{ url_for('orders.create') }}">Abrir um</a></strong> @@ -52,7 +56,10 @@