added promo
This commit is contained in:
@@ -207,6 +207,9 @@ app.register_blueprint(stats_blueprint, url_prefix='/stats')
|
|||||||
from .ticket import ticket as ticket_blueprint
|
from .ticket import ticket as ticket_blueprint
|
||||||
app.register_blueprint(ticket_blueprint, url_prefix='/ticket')
|
app.register_blueprint(ticket_blueprint, url_prefix='/ticket')
|
||||||
|
|
||||||
|
from .promo import promo as promo_blueprint
|
||||||
|
app.register_blueprint(promo_blueprint, url_prefix='/promo')
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
|
||||||
db.configure_mappers()
|
db.configure_mappers()
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ class Delivery_Delivery(db.Model):
|
|||||||
final_price = db.Column(db.DECIMAL(6, 2))
|
final_price = db.Column(db.DECIMAL(6, 2))
|
||||||
check_number = db.Column(db.VARCHAR(20))
|
check_number = db.Column(db.VARCHAR(20))
|
||||||
|
|
||||||
|
|
||||||
|
promo_id = db.Column(db.INTEGER)
|
||||||
|
promo_money_discount = db.Column(db.DECIMAL(6, 2))
|
||||||
|
|
||||||
|
|
||||||
class Delivery_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
class Delivery_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Delivery_Delivery
|
model = Delivery_Delivery
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from app import db, ma
|
from app import db, ma
|
||||||
from datetime import datetime, timezone
|
|
||||||
|
|
||||||
|
|
||||||
class Money_delivery(db.Model):
|
class Money_delivery(db.Model):
|
||||||
@@ -12,21 +11,21 @@ class Money_delivery(db.Model):
|
|||||||
autoincrement=True,
|
autoincrement=True,
|
||||||
unique=False)
|
unique=False)
|
||||||
|
|
||||||
delivery_id = db.Column(db.INTEGER)
|
delivery_id = db.Column(db.Integer)
|
||||||
time_added = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
time_added = db.Column(db.DATE())
|
||||||
gallons_delivered = db.Column(db.DECIMAL(6, 2))
|
gallons_delivered = db.Column(db.DECIMAL(6, 2))
|
||||||
supplier_price = db.Column(db.DECIMAL(6, 2))
|
supplier_price = db.Column(db.DECIMAL(6, 2))
|
||||||
customer_price = db.Column(db.DECIMAL(6, 2))
|
customer_price = db.Column(db.DECIMAL(6, 2))
|
||||||
|
|
||||||
total_amount_oil = db.Column(db.DECIMAL(6, 2))
|
total_amount_oil = db.Column(db.DECIMAL(6, 2))
|
||||||
total_amount_prime = db.Column(db.DECIMAL(6, 2))
|
total_amount_prime = db.Column(db.DECIMAL(6, 2))
|
||||||
total_amount_same_day = db.Column(db.DECIMAL(6, 2))
|
total_amount_same_day = db.Column(db.DECIMAL(6, 2))
|
||||||
total_amount_fee = db.Column(db.DECIMAL(6, 2))
|
total_amount_fee = db.Column(db.DECIMAL(6, 2))
|
||||||
total_amount = db.Column(db.DECIMAL(6, 2))
|
total_amount = db.Column(db.DECIMAL(6, 2))
|
||||||
total_profit_oil = db.Column(db.DECIMAL(6, 2))
|
total_discount_amount = db.Column(db.DECIMAL(6, 2))
|
||||||
|
total_discount_total = db.Column(db.DECIMAL(6, 2))
|
||||||
taxes_paid = db.Column(db.DECIMAL(6, 2))
|
taxes_paid = db.Column(db.DECIMAL(6, 2))
|
||||||
total_profit = db.Column(db.DECIMAL(6, 2))
|
total_profit = db.Column(db.DECIMAL(6, 2))
|
||||||
|
total_profit_oil = db.Column(db.DECIMAL(6, 2))
|
||||||
|
|
||||||
class Money_delivery_schema(ma.SQLAlchemyAutoSchema):
|
class Money_delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
27
app/classes/promo.py
Normal file
27
app/classes/promo.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from app import db, ma
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Promo_Promo(db.Model):
|
||||||
|
__tablename__ = 'promo_Promo'
|
||||||
|
__bind_key__ = 'eamco'
|
||||||
|
__table_args__ = {"schema": "public"}
|
||||||
|
|
||||||
|
id = db.Column(db.Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
active = db.Column(db.BOOLEAN())
|
||||||
|
name_of_promotion = db.Column(db.VARCHAR(1000))
|
||||||
|
money_off_delivery = db.Column(db.DECIMAL(6, 2))
|
||||||
|
description = db.Column(db.VARCHAR(1000))
|
||||||
|
text_on_ticket = db.Column(db.VARCHAR(100))
|
||||||
|
date_created = db.Column(db.DATE())
|
||||||
|
|
||||||
|
|
||||||
|
class Promo_Promo_schema(ma.SQLAlchemyAutoSchema):
|
||||||
|
class Meta:
|
||||||
|
model = Promo_Promo
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ from app.classes.employee import Employee_Employee
|
|||||||
from app.classes.cards import Card_Card
|
from app.classes.cards import Card_Card
|
||||||
from app.classes.pricing import Pricing_Oil_Oil
|
from app.classes.pricing import Pricing_Oil_Oil
|
||||||
from app.classes.auth import Auth_User
|
from app.classes.auth import Auth_User
|
||||||
|
from app.classes.promo import Promo_Promo
|
||||||
|
|
||||||
@delivery.route("/<int:delivery_id>", methods=["GET"])
|
@delivery.route("/<int:delivery_id>", methods=["GET"])
|
||||||
def get_a_delivery(delivery_id):
|
def get_a_delivery(delivery_id):
|
||||||
@@ -43,6 +43,9 @@ def get_a_delivery(delivery_id):
|
|||||||
'driver_employee_id': get_delivery.driver_employee_id,
|
'driver_employee_id': get_delivery.driver_employee_id,
|
||||||
'driver_first_name': get_delivery.driver_first_name,
|
'driver_first_name': get_delivery.driver_first_name,
|
||||||
'driver_last_name': get_delivery.driver_last_name,
|
'driver_last_name': get_delivery.driver_last_name,
|
||||||
|
'promo_id': get_delivery.promo_id,
|
||||||
|
'promo_money_discount': get_delivery.promo_money_discount,
|
||||||
|
|
||||||
},
|
},
|
||||||
}), 200
|
}), 200
|
||||||
|
|
||||||
@@ -59,6 +62,7 @@ def get_customer_past_delivery1(customer_id):
|
|||||||
delivery_schema = Delivery_Delivery_schema(many=True)
|
delivery_schema = Delivery_Delivery_schema(many=True)
|
||||||
return jsonify(delivery_schema.dump(get_customer_past_delivery))
|
return jsonify(delivery_schema.dump(get_customer_past_delivery))
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/past2/<int:customer_id>", methods=["GET"])
|
@delivery.route("/past2/<int:customer_id>", methods=["GET"])
|
||||||
def get_customer_past_delivery2(customer_id):
|
def get_customer_past_delivery2(customer_id):
|
||||||
|
|
||||||
@@ -104,6 +108,7 @@ def update_a_delivery_payment(delivery_id, type_of_payment):
|
|||||||
return jsonify({"ok": True}), 200
|
return jsonify({"ok": True}), 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/all/<int:page>", methods=["GET"])
|
@delivery.route("/all/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_not_delivered_all(page):
|
def get_deliveries_not_delivered_all(page):
|
||||||
"""
|
"""
|
||||||
@@ -130,6 +135,7 @@ def get_deliveries_not_delivered_all(page):
|
|||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/customer/<int:customer_id>/<int:page>", methods=["GET"])
|
@delivery.route("/customer/<int:customer_id>/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_from_customer(customer_id, page):
|
def get_deliveries_from_customer(customer_id, page):
|
||||||
"""
|
"""
|
||||||
@@ -153,6 +159,8 @@ def get_deliveries_from_customer(customer_id, page):
|
|||||||
customer_schema = Delivery_Delivery_schema(many=True)
|
customer_schema = Delivery_Delivery_schema(many=True)
|
||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/all/order/<int:page>", methods=["GET"])
|
@delivery.route("/all/order/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_not_delivered(page):
|
def get_deliveries_not_delivered(page):
|
||||||
|
|
||||||
@@ -176,6 +184,8 @@ def get_deliveries_not_delivered(page):
|
|||||||
customer_schema = Delivery_Delivery_schema(many=True)
|
customer_schema = Delivery_Delivery_schema(many=True)
|
||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/waiting/<int:page>", methods=["GET"])
|
@delivery.route("/waiting/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_waiting(page):
|
def get_deliveries_waiting(page):
|
||||||
"""
|
"""
|
||||||
@@ -198,6 +208,8 @@ def get_deliveries_waiting(page):
|
|||||||
customer_schema = Delivery_Delivery_schema(many=True)
|
customer_schema = Delivery_Delivery_schema(many=True)
|
||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/delivered/<int:page>", methods=["GET"])
|
@delivery.route("/delivered/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_delivered(page):
|
def get_deliveries_delivered(page):
|
||||||
"""
|
"""
|
||||||
@@ -220,6 +232,8 @@ def get_deliveries_delivered(page):
|
|||||||
customer_schema = Delivery_Delivery_schema(many=True)
|
customer_schema = Delivery_Delivery_schema(many=True)
|
||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/outfordelivery/<int:page>", methods=["GET"])
|
@delivery.route("/outfordelivery/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_outfordelivery(page):
|
def get_deliveries_outfordelivery(page):
|
||||||
"""
|
"""
|
||||||
@@ -269,6 +283,7 @@ def get_deliveries_tommorrow(page):
|
|||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/finalized/<int:page>", methods=["GET"])
|
@delivery.route("/finalized/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_finalized(page):
|
def get_deliveries_finalized(page):
|
||||||
"""
|
"""
|
||||||
@@ -316,6 +331,7 @@ def get_deliveries_cancelled(page):
|
|||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/partialdelivery/<int:page>", methods=["GET"])
|
@delivery.route("/partialdelivery/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_partial(page):
|
def get_deliveries_partial(page):
|
||||||
"""
|
"""
|
||||||
@@ -338,6 +354,8 @@ def get_deliveries_partial(page):
|
|||||||
customer_schema = Delivery_Delivery_schema(many=True)
|
customer_schema = Delivery_Delivery_schema(many=True)
|
||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/issue/<int:page>", methods=["GET"])
|
@delivery.route("/issue/<int:page>", methods=["GET"])
|
||||||
def get_deliveries_issue(page):
|
def get_deliveries_issue(page):
|
||||||
"""
|
"""
|
||||||
@@ -361,6 +379,7 @@ def get_deliveries_issue(page):
|
|||||||
return jsonify(customer_schema.dump(deliveries))
|
return jsonify(customer_schema.dump(deliveries))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/time/today", methods=["GET"])
|
@delivery.route("/time/today", methods=["GET"])
|
||||||
def get_deliveries_today():
|
def get_deliveries_today():
|
||||||
"""
|
"""
|
||||||
@@ -404,13 +423,38 @@ def edit_a_delivery(delivery_id):
|
|||||||
customer_wants_fill = request.json["customer_asked_for_fill"]
|
customer_wants_fill = request.json["customer_asked_for_fill"]
|
||||||
card_payment = request.json["credit"]
|
card_payment = request.json["credit"]
|
||||||
cash_payment = request.json["cash"]
|
cash_payment = request.json["cash"]
|
||||||
delivery_driver_id = request.json["driver_employee_id"]
|
|
||||||
|
|
||||||
|
|
||||||
|
delivery_driver_id = request.json["driver_employee_id"]
|
||||||
|
|
||||||
get_driver = (db.session
|
get_driver = (db.session
|
||||||
.query(Employee_Employee)
|
.query(Employee_Employee)
|
||||||
.filter(Employee_Employee.id == delivery_driver_id)
|
.filter(Employee_Employee.id == delivery_driver_id)
|
||||||
.first())
|
.first())
|
||||||
|
|
||||||
|
## promo
|
||||||
|
|
||||||
|
try:
|
||||||
|
if request.json["promo_id"]:
|
||||||
|
promo_id = request.json["promo_id"]
|
||||||
|
else:
|
||||||
|
promo_id = None
|
||||||
|
except:
|
||||||
|
promo_id = None
|
||||||
|
|
||||||
|
if promo_id is not None:
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.filter(Promo_Promo.id == promo_id)
|
||||||
|
.first())
|
||||||
|
promo_id_get_delivery =get_promo_data.id,
|
||||||
|
promo_money_discount_get_delivery = get_promo_data.money_off_delivery
|
||||||
|
else:
|
||||||
|
promo_id_get_delivery =None
|
||||||
|
promo_money_discount_get_delivery = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if request.json["credit_card_id"]:
|
if request.json["credit_card_id"]:
|
||||||
card_payment_id = request.json["credit_card_id"]
|
card_payment_id = request.json["credit_card_id"]
|
||||||
else:
|
else:
|
||||||
@@ -469,6 +513,8 @@ def edit_a_delivery(delivery_id):
|
|||||||
get_delivery.driver_last_name = get_driver.employee_last_name
|
get_delivery.driver_last_name = get_driver.employee_last_name
|
||||||
get_delivery.driver_first_name = get_driver.employee_first_name
|
get_delivery.driver_first_name = get_driver.employee_first_name
|
||||||
get_delivery.driver_employee_id = get_driver.id
|
get_delivery.driver_employee_id = get_driver.id
|
||||||
|
get_delivery.promo_id =promo_id_get_delivery
|
||||||
|
get_delivery.promo_money_discount = promo_money_discount_get_delivery
|
||||||
|
|
||||||
db.session.add(get_delivery)
|
db.session.add(get_delivery)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@@ -515,26 +561,41 @@ def create_a_delivery(user_id):
|
|||||||
check_payment = request.json["check"]
|
check_payment = request.json["check"]
|
||||||
other_payment = request.json["other"]
|
other_payment = request.json["other"]
|
||||||
|
|
||||||
|
## promo
|
||||||
|
try:
|
||||||
|
if request.json["promo_id"]:
|
||||||
|
promo_id = request.json["promo_id"]
|
||||||
|
else:
|
||||||
|
promo_id = None
|
||||||
|
except:
|
||||||
|
promo_id = None
|
||||||
|
if promo_id is not None:
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.filter(Promo_Promo.id == promo_id)
|
||||||
|
.first())
|
||||||
|
promo_id_get_delivery =get_promo_data.id,
|
||||||
|
promo_money_discount_get_delivery = get_promo_data.money_off_delivery
|
||||||
|
else:
|
||||||
|
promo_id_get_delivery =None
|
||||||
|
promo_money_discount_get_delivery = None
|
||||||
|
|
||||||
|
|
||||||
# 0 = cash only
|
# 0 = cash only
|
||||||
# 1 = credit only
|
# 1 = credit only
|
||||||
# 2 = credit /cash
|
# 2 = credit /cash
|
||||||
# 3 = check
|
# 3 = check
|
||||||
# 4 = other
|
# 4 = other
|
||||||
# 5 = unknown
|
# 5 = unknown
|
||||||
if card_payment is True and cash_payment is True:
|
|
||||||
delivery_payment_method = 2
|
if cash_payment is True:
|
||||||
elif cash_payment is True:
|
|
||||||
delivery_payment_method = 0
|
|
||||||
elif card_payment is True:
|
|
||||||
delivery_payment_method = 1
|
delivery_payment_method = 1
|
||||||
|
if card_payment is True:
|
||||||
elif check_payment is True:
|
delivery_payment_method = 2
|
||||||
|
if check_payment is True:
|
||||||
delivery_payment_method = 3
|
delivery_payment_method = 3
|
||||||
elif other_payment is True:
|
if other_payment is True:
|
||||||
delivery_payment_method = 4
|
delivery_payment_method = 4
|
||||||
else:
|
|
||||||
delivery_payment_method = 4
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get_driver = (db.session
|
get_driver = (db.session
|
||||||
@@ -648,6 +709,10 @@ def create_a_delivery(user_id):
|
|||||||
driver_last_name=driver_l_name,
|
driver_last_name=driver_l_name,
|
||||||
driver_first_name=driver_f_name,
|
driver_first_name=driver_f_name,
|
||||||
driver_employee_id=driver_emp_id,
|
driver_employee_id=driver_emp_id,
|
||||||
|
|
||||||
|
promo_id =promo_id_get_delivery,
|
||||||
|
promo_money_discount = promo_money_discount_get_delivery
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
db.session.add(new_delivery)
|
db.session.add(new_delivery)
|
||||||
@@ -811,7 +876,16 @@ def calculate_total(delivery_id):
|
|||||||
.query(Delivery_Delivery)
|
.query(Delivery_Delivery)
|
||||||
.filter(Delivery_Delivery.id == delivery_id)
|
.filter(Delivery_Delivery.id == delivery_id)
|
||||||
.first())
|
.first())
|
||||||
|
if get_delivery.promo_id:
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.filter(Promo_Promo.id == get_delivery.promo_id)
|
||||||
|
.first())
|
||||||
|
discount = (get_delivery.total_price * get_promo_data.money_off_delivery)
|
||||||
|
total_amount_after_discount = (get_delivery.total_price - discount)
|
||||||
|
else:
|
||||||
|
discount = 0
|
||||||
|
total_amount_after_discount = 0
|
||||||
get_price_query = (db.session
|
get_price_query = (db.session
|
||||||
.query(Pricing_Oil_Oil)
|
.query(Pricing_Oil_Oil)
|
||||||
.order_by(Pricing_Oil_Oil.date.desc())
|
.order_by(Pricing_Oil_Oil.date.desc())
|
||||||
@@ -840,4 +914,6 @@ def calculate_total(delivery_id):
|
|||||||
'pricesameday': pricesameday,
|
'pricesameday': pricesameday,
|
||||||
'priceemergency': priceemergency,
|
'priceemergency': priceemergency,
|
||||||
'total_amount':total,
|
'total_amount':total,
|
||||||
|
'discount': discount,
|
||||||
|
'total_amount_after_discount':total_amount_after_discount,
|
||||||
}), 200
|
}), 200
|
||||||
@@ -136,7 +136,6 @@ def office_finalize_delivery(delivery_id):
|
|||||||
card_payment = request.json["card"]
|
card_payment = request.json["card"]
|
||||||
check_payment = request.json["check"]
|
check_payment = request.json["check"]
|
||||||
other_payment = request.json["other"]
|
other_payment = request.json["other"]
|
||||||
|
|
||||||
check_number = request.json["other"]
|
check_number = request.json["other"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
app/promo/__init__.py
Normal file
7
app/promo/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
promo = Blueprint('promo', __name__)
|
||||||
|
|
||||||
|
from . import views
|
||||||
147
app/promo/views.py
Normal file
147
app/promo/views.py
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
from flask import request, jsonify
|
||||||
|
import decimal
|
||||||
|
from datetime import datetime
|
||||||
|
from app.promo import promo
|
||||||
|
from app import db
|
||||||
|
from app.classes.promo import Promo_Promo, Promo_Promo_schema
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@promo.route("/<int:promo_id>", methods=["GET"])
|
||||||
|
def get_promo(promo_id):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.filter(Promo_Promo.id == promo_id)
|
||||||
|
.first())
|
||||||
|
query_schema = Promo_Promo_schema(many=False)
|
||||||
|
return jsonify(query_schema.dump(get_promo_data))
|
||||||
|
|
||||||
|
|
||||||
|
@promo.route("/all", methods=["GET"])
|
||||||
|
def get_all_promo():
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.all())
|
||||||
|
query_schema = Promo_Promo_schema(many=True)
|
||||||
|
return jsonify(query_schema.dump(get_promo_data))
|
||||||
|
|
||||||
|
|
||||||
|
@promo.route("/delete/<int:promo_id>", methods=["DELETE"])
|
||||||
|
def delete_a_promo(promo_id):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.first(Promo_Promo.id == promo_id)
|
||||||
|
.first())
|
||||||
|
|
||||||
|
db.session.delete(get_promo_data)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"ok": True,
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
@promo.route("/create", methods=["POST"])
|
||||||
|
def create_promo():
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
date_created = datetime.utcnow()
|
||||||
|
name_of_promotion = request.json["name_of_promotion"]
|
||||||
|
money_off_delivery = request.json["money_off_delivery"]
|
||||||
|
description = request.json["description"]
|
||||||
|
text_on_ticket = request.json["text_on_ticket"]
|
||||||
|
# see if it exists
|
||||||
|
|
||||||
|
new_promo = Promo_Promo(
|
||||||
|
name_of_promotion = name_of_promotion,
|
||||||
|
money_off_delivery = float(money_off_delivery),
|
||||||
|
description = description,
|
||||||
|
date_created = date_created,
|
||||||
|
text_on_ticket=text_on_ticket
|
||||||
|
)
|
||||||
|
db.session.add(new_promo)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"ok": True,
|
||||||
|
'promo_id':new_promo.id,
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
|
||||||
|
@promo.route("/edit/<int:promo_id>", methods=["PUT"])
|
||||||
|
def edit_promo(promo_id):
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.filter(Promo_Promo.id == promo_id)
|
||||||
|
.first())
|
||||||
|
text_on_ticket = request.json["text_on_ticket"]
|
||||||
|
name_of_promotion = request.json["name_of_promotion"]
|
||||||
|
money_off_delivery = request.json["money_off_delivery"]
|
||||||
|
description = request.json["description"]
|
||||||
|
|
||||||
|
get_promo_data.text_on_ticket = text_on_ticket
|
||||||
|
get_promo_data.description = description
|
||||||
|
get_promo_data.name_of_promotion = name_of_promotion
|
||||||
|
get_promo_data.money_off_delivery = float(money_off_delivery)
|
||||||
|
|
||||||
|
db.session.add(get_promo_data)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"ok": True,
|
||||||
|
'promo_id':get_promo_data.id,
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@promo.route("/on/<int:promo_id>", methods=["PATCH"])
|
||||||
|
def turn_on_promo(promo_id):
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.filter(Promo_Promo.id == promo_id)
|
||||||
|
.first())
|
||||||
|
|
||||||
|
get_promo_data.active = True
|
||||||
|
|
||||||
|
|
||||||
|
db.session.add(get_promo_data)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"ok": True,
|
||||||
|
'promo_id':get_promo_data.id,
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
@promo.route("/off/<int:promo_id>", methods=["PATCH"])
|
||||||
|
def turn_off_promo(promo_id):
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
get_promo_data = (db.session
|
||||||
|
.query(Promo_Promo)
|
||||||
|
.filter(Promo_Promo.id == promo_id)
|
||||||
|
.first())
|
||||||
|
|
||||||
|
get_promo_data.active = False
|
||||||
|
|
||||||
|
|
||||||
|
db.session.add(get_promo_data)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"ok": True,
|
||||||
|
'promo_id':get_promo_data.id,
|
||||||
|
}), 200
|
||||||
Reference in New Issue
Block a user