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

36 lines
1.1 KiB
Python

from flask import Blueprint, render_template, redirect, url_for, flash
from ...services.product_service import ProductService
from ..forms.product import ProductForm
bp = Blueprint('product', __name__)
@bp.route('/products')
def list_products():
products = ProductService.get_all_products()
total_value = ProductService.calculate_total_value(products)
return render_template(
'product/list.html',
products=products,
total_value=total_value
)
@bp.route('/products/create', methods=['GET', 'POST'])
def create_product():
form = ProductForm()
if form.validate_on_submit():
try:
data = {
'name': form.name.data,
'price': form.price.data,
'min_quantity': form.min_quantity.data
}
ProductService.create_product(data)
flash('商品新增成功', 'success')
return redirect(url_for('product.list_products'))
except ValueError as e:
flash(str(e), 'error')
return render_template('product/create.html', form=form)