Updated
This commit is contained in:
@@ -4,6 +4,8 @@ ENV PYTHONFAULTHANDLER=1
|
|||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
ENV MODE="DEVELOPMENT"
|
||||||
|
|
||||||
RUN mkdir -p /app
|
RUN mkdir -p /app
|
||||||
|
|
||||||
COPY requirements.txt /app
|
COPY requirements.txt /app
|
||||||
|
|||||||
20
Dockerfile.prod
Normal file
20
Dockerfile.prod
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
FROM python:3.12-bullseye
|
||||||
|
|
||||||
|
ENV PYTHONFAULTHANDLER=1
|
||||||
|
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
ENV MODE="PRODUCTION"
|
||||||
|
|
||||||
|
RUN mkdir -p /app
|
||||||
|
|
||||||
|
COPY requirements.txt /app
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
CMD ["python", "app.py", "--host", "0.0.0.0"]
|
||||||
|
|
||||||
@@ -10,12 +10,10 @@ from flask_login import LoginManager
|
|||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
from flask_mail import Mail
|
from flask_mail import Mail
|
||||||
|
from config import load_config
|
||||||
|
|
||||||
try:
|
|
||||||
from local_settings import ApplicationConfig
|
|
||||||
except Exception as e:
|
|
||||||
from settings import ApplicationConfig
|
|
||||||
|
|
||||||
|
ApplicationConfig = load_config()
|
||||||
|
|
||||||
app = Flask(__name__,
|
app = Flask(__name__,
|
||||||
static_url_path='',
|
static_url_path='',
|
||||||
@@ -27,8 +25,7 @@ app.config.from_object(ApplicationConfig)
|
|||||||
|
|
||||||
session = sessionmaker()
|
session = sessionmaker()
|
||||||
|
|
||||||
check_enviroment = ApplicationConfig.CURRENT_SETTINGS
|
|
||||||
print(f"starting server with {check_enviroment} settings")
|
|
||||||
|
|
||||||
|
|
||||||
class RegexConverter(BaseConverter):
|
class RegexConverter(BaseConverter):
|
||||||
@@ -45,7 +42,9 @@ app.jinja_env.autoescape = True
|
|||||||
UPLOADED_FILES_DEST_ITEM = ApplicationConfig.UPLOADED_FILES_DEST_ITEM
|
UPLOADED_FILES_DEST_ITEM = ApplicationConfig.UPLOADED_FILES_DEST_ITEM
|
||||||
UPLOADED_FILES_ALLOW = ApplicationConfig.UPLOADED_FILES_ALLOW
|
UPLOADED_FILES_ALLOW = ApplicationConfig.UPLOADED_FILES_ALLOW
|
||||||
CURRENT_SETTINGS = ApplicationConfig.CURRENT_SETTINGS
|
CURRENT_SETTINGS = ApplicationConfig.CURRENT_SETTINGS
|
||||||
|
WHITE = ApplicationConfig.WHITE
|
||||||
|
|
||||||
|
app.config['CORS_ORIGIN_WHITELIST'] = ApplicationConfig.CORS_ORIGIN_WHITELIST
|
||||||
app.config['UPLOADED_FILES_DEST_ITEM'] = ApplicationConfig.UPLOADED_FILES_DEST_ITEM
|
app.config['UPLOADED_FILES_DEST_ITEM'] = ApplicationConfig.UPLOADED_FILES_DEST_ITEM
|
||||||
app.config['UPLOADED_FILES_ALLOW'] = ApplicationConfig.UPLOADED_FILES_ALLOW
|
app.config['UPLOADED_FILES_ALLOW'] = ApplicationConfig.UPLOADED_FILES_ALLOW
|
||||||
app.config['MAX_CONTENT_LENGTH'] = ApplicationConfig.MAX_CONTENT_LENGTH
|
app.config['MAX_CONTENT_LENGTH'] = ApplicationConfig.MAX_CONTENT_LENGTH
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ def create_oil_price():
|
|||||||
price_for_customer = request.json["price_for_customer"]
|
price_for_customer = request.json["price_for_customer"]
|
||||||
price_for_employee = request.json["price_for_employee"]
|
price_for_employee = request.json["price_for_employee"]
|
||||||
price_same_day = request.json["price_same_day"]
|
price_same_day = request.json["price_same_day"]
|
||||||
|
price_prime = request.json["price_prime"]
|
||||||
|
|
||||||
new_admin_oil_price = Pricing_Oil_Oil(
|
new_admin_oil_price = Pricing_Oil_Oil(
|
||||||
price_from_supplier=price_from_supplier,
|
price_from_supplier=price_from_supplier,
|
||||||
price_for_customer=price_for_customer,
|
price_for_customer=price_for_customer,
|
||||||
price_for_employee=price_for_employee,
|
price_for_employee=price_for_employee,
|
||||||
price_same_day=price_same_day,
|
price_same_day=price_same_day,
|
||||||
|
price_prime=price_prime,
|
||||||
date=now,
|
date=now,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class Customer_Customer(db.Model):
|
|||||||
customer_home_type = db.Column(db.INTEGER)
|
customer_home_type = db.Column(db.INTEGER)
|
||||||
customer_apt = db.Column(db.VARCHAR(140))
|
customer_apt = db.Column(db.VARCHAR(140))
|
||||||
customer_address = db.Column(db.VARCHAR(1000))
|
customer_address = db.Column(db.VARCHAR(1000))
|
||||||
|
company_id = db.Column(db.INTEGER)
|
||||||
|
|
||||||
|
|
||||||
class Customer_Customer_schema(ma.SQLAlchemyAutoSchema):
|
class Customer_Customer_schema(ma.SQLAlchemyAutoSchema):
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class Delivery_Delivery(db.Model):
|
|||||||
same_day = db.Column(db.INTEGER)
|
same_day = db.Column(db.INTEGER)
|
||||||
# cash = 0
|
# cash = 0
|
||||||
# credit = 1
|
# credit = 1
|
||||||
|
# credit/cash = 2
|
||||||
payment_type = db.Column(db.INTEGER)
|
payment_type = db.Column(db.INTEGER)
|
||||||
payment_card_id = db.Column(db.INTEGER)
|
payment_card_id = db.Column(db.INTEGER)
|
||||||
cash_recieved = db.Column(db.DECIMAL(50, 2))
|
cash_recieved = db.Column(db.DECIMAL(50, 2))
|
||||||
|
|||||||
@@ -82,13 +82,14 @@ def create_customer():
|
|||||||
customer_phone_number = request.json["customer_phone_number"]
|
customer_phone_number = request.json["customer_phone_number"]
|
||||||
customer_address = request.json["customer_address"]
|
customer_address = request.json["customer_address"]
|
||||||
customer_apt = request.json["customer_apt"]
|
customer_apt = request.json["customer_apt"]
|
||||||
|
|
||||||
if response_customer_automatic is True:
|
if response_customer_automatic is True:
|
||||||
auto_customer = 1
|
auto_customer = 1
|
||||||
else:
|
else:
|
||||||
auto_customer = 0
|
auto_customer = 0
|
||||||
|
|
||||||
int_customer_home_type = int(response_customer_home_type)
|
int_customer_home_type = int(response_customer_home_type)
|
||||||
response_customer_zip = int(response_customer_zip)
|
response_customer_zip = str(response_customer_zip)
|
||||||
response_customer_state = int(response_customer_state)
|
response_customer_state = int(response_customer_state)
|
||||||
|
|
||||||
new_customer = Customer_Customer(
|
new_customer = Customer_Customer(
|
||||||
@@ -104,8 +105,8 @@ def create_customer():
|
|||||||
customer_home_type=int_customer_home_type,
|
customer_home_type=int_customer_home_type,
|
||||||
customer_phone_number=customer_phone_number,
|
customer_phone_number=customer_phone_number,
|
||||||
customer_address=customer_address,
|
customer_address=customer_address,
|
||||||
customer_apt=customer_apt
|
customer_apt=customer_apt,
|
||||||
|
company_id=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
db.session.add(new_customer)
|
db.session.add(new_customer)
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ 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.money import Money_delivery
|
|
||||||
from app.classes.printing import Printer_jobs
|
|
||||||
|
|
||||||
|
|
||||||
@delivery.route("/<int:delivery_id>", methods=["GET"])
|
@delivery.route("/<int:delivery_id>", methods=["GET"])
|
||||||
@@ -387,8 +385,7 @@ def edit_a_delivery(delivery_id):
|
|||||||
gallons_ordered = request.json["gallons_ordered"]
|
gallons_ordered = request.json["gallons_ordered"]
|
||||||
delivery_status = request.json["delivery_status"]
|
delivery_status = request.json["delivery_status"]
|
||||||
when_to_deliver = request.json["expected_delivery_date"]
|
when_to_deliver = request.json["expected_delivery_date"]
|
||||||
print(when_to_deliver)
|
|
||||||
print(request.json["expected_delivery_date"])
|
|
||||||
dispatcher_notes_taken = request.json["dispatcher_notes_taken"]
|
dispatcher_notes_taken = request.json["dispatcher_notes_taken"]
|
||||||
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"]
|
||||||
@@ -416,8 +413,10 @@ def edit_a_delivery(delivery_id):
|
|||||||
else:
|
else:
|
||||||
card_id_from_customer = None
|
card_id_from_customer = None
|
||||||
|
|
||||||
|
|
||||||
if cash_payment is True and card_payment is False:
|
if cash_payment is True and card_payment is False:
|
||||||
delivery_payment_method = 0
|
delivery_payment_method = 0
|
||||||
|
|
||||||
elif card_payment is True and cash_payment is False:
|
elif card_payment is True and cash_payment is False:
|
||||||
delivery_payment_method = 1
|
delivery_payment_method = 1
|
||||||
|
|
||||||
@@ -453,7 +452,6 @@ def edit_a_delivery(delivery_id):
|
|||||||
get_delivery.gallons_ordered = gallons_ordered
|
get_delivery.gallons_ordered = gallons_ordered
|
||||||
get_delivery.payment_type = delivery_payment_method
|
get_delivery.payment_type = delivery_payment_method
|
||||||
get_delivery.payment_card_id = card_id_from_customer
|
get_delivery.payment_card_id = card_id_from_customer
|
||||||
|
|
||||||
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
|
||||||
@@ -527,6 +525,11 @@ def create_a_delivery(user_id):
|
|||||||
else:
|
else:
|
||||||
card_id_from_customer = None
|
card_id_from_customer = None
|
||||||
|
|
||||||
|
# 0 = cash only
|
||||||
|
# 1 = credit only
|
||||||
|
# 2 = credit /cash
|
||||||
|
# 3 unknown
|
||||||
|
|
||||||
if cash_payment is True and card_payment is False:
|
if cash_payment is True and card_payment is False:
|
||||||
delivery_payment_method = 0
|
delivery_payment_method = 0
|
||||||
elif card_payment is True and cash_payment is False:
|
elif card_payment is True and cash_payment is False:
|
||||||
@@ -558,14 +561,20 @@ def create_a_delivery(user_id):
|
|||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Pricing
|
# Pricing
|
||||||
if customer_fill_up == 1:
|
if customer_fill_up == 1:
|
||||||
precharge_amount = (250 * get_today_price.price_for_customer)
|
precharge_amount = (250 * get_today_price.price_for_customer)
|
||||||
|
print(precharge_amount)
|
||||||
else:
|
else:
|
||||||
precharge_amount = int(gallons_ordered) * get_today_price.price_for_customer
|
precharge_amount = int(gallons_ordered) * get_today_price.price_for_customer
|
||||||
|
|
||||||
if same_day_asked == 1 and prime_asked == 0:
|
if same_day_asked == 1 and prime_asked == 0:
|
||||||
total_precharge_amount = precharge_amount + get_today_price.price_same_day
|
total_precharge_amount = precharge_amount + get_today_price.price_same_day
|
||||||
|
print(total_precharge_amount)
|
||||||
|
print(precharge_amount)
|
||||||
|
print(get_today_price.price_same_day)
|
||||||
|
|
||||||
elif prime_asked == 1 and same_day_asked == 0:
|
elif prime_asked == 1 and same_day_asked == 0:
|
||||||
total_precharge_amount = precharge_amount + get_today_price.price_prime
|
total_precharge_amount = precharge_amount + get_today_price.price_prime
|
||||||
@@ -744,7 +753,6 @@ def move_waiting_to_outtodelivery():
|
|||||||
.filter(Delivery_Delivery.expected_delivery_date == date.today())
|
.filter(Delivery_Delivery.expected_delivery_date == date.today())
|
||||||
.all())
|
.all())
|
||||||
for f in deliveries:
|
for f in deliveries:
|
||||||
print(f.id)
|
|
||||||
f.delivery_status = 2
|
f.delivery_status = 2
|
||||||
db.session.add(f)
|
db.session.add(f)
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
@@ -769,9 +777,10 @@ 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())
|
||||||
|
|
||||||
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.asc())
|
||||||
.first())
|
.first())
|
||||||
|
|
||||||
|
|
||||||
@@ -779,15 +788,17 @@ def calculate_total(delivery_id):
|
|||||||
priceprime = get_price_query.price_prime
|
priceprime = get_price_query.price_prime
|
||||||
else:
|
else:
|
||||||
priceprime = 0
|
priceprime = 0
|
||||||
|
|
||||||
if get_delivery.same_day == 1:
|
if get_delivery.same_day == 1:
|
||||||
pricesameday = get_price_query.price_prime
|
pricesameday = get_price_query.price_same_day
|
||||||
else:
|
else:
|
||||||
pricesameday = 0
|
pricesameday = 0
|
||||||
|
|
||||||
total = float(get_delivery.total_price) + float(priceprime) + float(pricesameday)
|
total = float(get_delivery.total_price) + float(priceprime) + float(pricesameday)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"ok": True,
|
"ok": True,
|
||||||
'priceprime': priceprime,
|
'priceprime': priceprime,
|
||||||
'pricesameday': pricesameday,
|
'pricesameday': pricesameday,
|
||||||
'total_amount':total
|
'total_amount':total,
|
||||||
}), 200
|
}), 200
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from flask import jsonify, Response
|
from flask import jsonify, Response, request
|
||||||
from app import app
|
from app import app, WHITE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/robots.txt')
|
@app.route('/robots.txt')
|
||||||
@@ -17,3 +18,15 @@ def static_from_root():
|
|||||||
def index():
|
def index():
|
||||||
return jsonify({"success": "Api is online"}), 200
|
return jsonify({"success": "Api is online"}), 200
|
||||||
|
|
||||||
|
# @app.after_request
|
||||||
|
# def add_cors_headers(response):
|
||||||
|
# r = request.referrer[:-1]
|
||||||
|
# if r in WHITE:
|
||||||
|
# response.headers.add('Access-Control-Allow-Origin', r)
|
||||||
|
# response.headers.add('Access-Control-Allow-Credentials', 'true')
|
||||||
|
# response.headers.add('Access-Control-Allow-Headers', 'Content-Type')
|
||||||
|
# response.headers.add('Access-Control-Allow-Headers', 'Cache-Control')
|
||||||
|
# response.headers.add('Access-Control-Allow-Headers', 'X-Requested-With')
|
||||||
|
# response.headers.add('Access-Control-Allow-Headers', 'Authorization')
|
||||||
|
# response.headers.add('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE')
|
||||||
|
# return response
|
||||||
@@ -48,7 +48,7 @@ class ApplicationConfig:
|
|||||||
CORS_SUPPORT_CREDENTIALS = True
|
CORS_SUPPORT_CREDENTIALS = True
|
||||||
CORS_EXPOSE_HEADERS = None
|
CORS_EXPOSE_HEADERS = None
|
||||||
CORS_ALLOW_HEADERS = "*"
|
CORS_ALLOW_HEADERS = "*"
|
||||||
CORS_ORIGIN_WHITELIST = ['http://localhost:5173', '*']
|
CORS_ORIGIN_WHITELIST = ['*']
|
||||||
|
WHITE = ['*']
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
54
prod_settings.py
Normal file
54
prod_settings.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import redis
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationConfig:
|
||||||
|
"""
|
||||||
|
Basic Configuration for a generic User
|
||||||
|
"""
|
||||||
|
CURRENT_SETTINGS = 'PROD'
|
||||||
|
# databases info
|
||||||
|
POSTGRES_USERNAME = 'postgres'
|
||||||
|
POSTGRES_PW = 'password'
|
||||||
|
POSTGRES_SERVER = '192.168.1.204:5432'
|
||||||
|
POSTGRES_DBNAME00 = 'eamco'
|
||||||
|
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
||||||
|
POSTGRES_PW,
|
||||||
|
POSTGRES_SERVER,
|
||||||
|
POSTGRES_DBNAME00
|
||||||
|
)
|
||||||
|
SQLALCHEMY_BINDS = {'eamco': SQLALCHEMY_DATABASE_URI}
|
||||||
|
# sqlalchemy config
|
||||||
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
TRAP_HTTP_EXCEPTIONS = True
|
||||||
|
PROPAGATE_EXCEPTIONS = True
|
||||||
|
DEBUG = True
|
||||||
|
UPLOADED_FILES_DEST_ITEM = '/data/item'
|
||||||
|
|
||||||
|
# file uploads
|
||||||
|
UPLOADED_FILES_ALLOW = ['png', 'jpeg', 'jpg', 'png', 'gif']
|
||||||
|
MAX_CONTENT_LENGTH = 5 * 2500 * 2500
|
||||||
|
ALLOWED_EXTENSIONS = ['png', 'jpeg', 'jpg', 'png', 'gif']
|
||||||
|
|
||||||
|
# secret keys
|
||||||
|
SECRET_KEY = "34dsfkjh43123cxzfvqwer23432dsf233214efdasf2134321"
|
||||||
|
|
||||||
|
# sessions
|
||||||
|
SESSION_COOKIE_NAME = "eamco_session"
|
||||||
|
SESSION_COOKIE_SECURE = False
|
||||||
|
SESSION_COOKIE_HTTPONLY = True
|
||||||
|
REMEMBER_COOKIE_HTTPONLY = True
|
||||||
|
SESSION_COOKIE_SAMESITE = "Strict"
|
||||||
|
SESSION_PERMANENT = False
|
||||||
|
SESSION_USE_SIGNER = True
|
||||||
|
|
||||||
|
# CORS
|
||||||
|
|
||||||
|
ORIGIN_URL = "http://192.168.1.204:9511"
|
||||||
|
CORS_SEND_WILDCARD = False
|
||||||
|
CORS_SUPPORT_CREDENTIALS = True
|
||||||
|
CORS_EXPOSE_HEADERS = None
|
||||||
|
CORS_ALLOW_HEADERS = "*"
|
||||||
|
CORS_ORIGIN_WHITELIST = ['http://192.168.1.204','http://localhost', 'http://192.168.1.204:9511', "*"]
|
||||||
|
WHITE= ['http://192.168.1.204','http://localhost', "*"]
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user