Evo-ERP/app/__init__.py
2024-11-06 02:39:48 +08:00

53 lines
1.4 KiB
Python

from flask import Flask, redirect, url_for
from .extensions import db, migrate
from config import Config
from datetime import datetime, timedelta
def create_app():
app = Flask(__name__)
app.config.from_object(Config)
# 初始化擴展
db.init_app(app)
migrate.init_app(app, db)
# 導入模型
from .models import product, transaction
# 註冊藍圖
from .web.views import product as product_views
from .web.views import transaction as transaction_views
from .web.views import report as report_views
from .web.views import inventory as inventory_views
app.register_blueprint(product_views.bp)
app.register_blueprint(transaction_views.bp)
app.register_blueprint(report_views.bp)
app.register_blueprint(inventory_views.bp)
# 添加模板上下文處理器
@app.context_processor
def utility_processor():
def get_low_stock_count():
from .models.product import Product
return Product.query.filter(
Product.quantity <= Product.min_quantity
).count()
return dict(
get_low_stock_count=get_low_stock_count,
datetime=datetime,
timedelta=timedelta,
today=datetime.today(),
min=min,
build_version='20241106.01',
version='1.0.2'
)
@app.route('/')
def index():
return redirect(url_for('product.list_products'))
return app