From 423bc340efee65a31eda24bcb64a3d5f7af89eae Mon Sep 17 00:00:00 2001 From: Junglejia <2407509566@qq.com> Date: Wed, 30 Apr 2025 18:08:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=9C=80=E8=BF=91=E6=93=8D=E4=BD=9C=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=A0=BC=E5=BC=8F=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=89=AB=E7=A0=81=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?is=5Factive=E9=BB=98=E8=AE=A4=E4=B8=BA0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inventory/barcode_product_form.html | 10 ++ inventory/templates/inventory/index.html | 145 +++++++++++------- inventory/views_barcode.py | 11 +- 3 files changed, 108 insertions(+), 58 deletions(-) diff --git a/inventory/templates/inventory/barcode_product_form.html b/inventory/templates/inventory/barcode_product_form.html index 98ec626..add539b 100644 --- a/inventory/templates/inventory/barcode_product_form.html +++ b/inventory/templates/inventory/barcode_product_form.html @@ -269,6 +269,16 @@ +
+
+ + + {% if form.is_active.errors %} +
{{ form.is_active.errors }}
+ {% endif %} +
+
+
{% if form.description.errors %} diff --git a/inventory/templates/inventory/index.html b/inventory/templates/inventory/index.html index 6860017..5aa0196 100644 --- a/inventory/templates/inventory/index.html +++ b/inventory/templates/inventory/index.html @@ -97,55 +97,6 @@
- -
- -
-
-
-
热销商品
-
-
- {% if top_products %} -
- {% for product in top_products %} -
-
-
{{ product.product__name }}
- {{ product.total_qty }} -
- 销售额: ¥{{ product.total_amount|floatformat:2 }} -
- {% endfor %} -
- {% else %} -

暂无销售数据

- {% endif %} -
-
-
- - -
-
-
-
库存预警
-
-
- {% if low_stock_products > 0 %} -
- 注意: 有 {{ low_stock_products }} 个商品库存不足,其中 {{ out_of_stock_products }} 个商品已无库存! -
- 查看库存不足商品 - {% else %} -
- 所有商品库存充足 -
- {% endif %} -
-
-
-
@@ -158,7 +109,7 @@ 查看全部 -
+
{% if birthday_members %}
{% for member in birthday_members %} @@ -190,13 +141,65 @@ {% endif %}
- - -
+
+
+ + +
+ +
+
+
+
热销商品
+
+
+ {% if top_products %} +
+ {% for product in top_products %} +
+
+
{{ product.product__name }}
+ {{ product.total_qty }} +
+ 销售额: ¥{{ product.total_amount|floatformat:2 }} +
+ {% endfor %} +
+ {% else %} +

暂无销售数据

+ {% endif %} +
+
+
+ + +
+
+
+
库存预警
+
+
+ {% if low_stock_products > 0 %} +
+ 注意: 有 {{ low_stock_products }} 个商品库存不足,其中 {{ out_of_stock_products }} 个商品已无库存! +
+ 查看库存不足商品 + {% else %} +
+ 所有商品库存充足 +
+ {% endif %} +
+
+
+ + +
+
最近操作
-
+
{% if recent_logs %}
{% for log in recent_logs %} @@ -238,6 +241,40 @@ justify-content: center; font-size: 14px; } + + /* 添加固定高度和滚动样式 */ + .card-scrollable { + height: 250px; + overflow-y: auto; + scrollbar-width: thin; + } + + /* 美化滚动条 */ + .card-scrollable::-webkit-scrollbar { + width: 5px; + } + + .card-scrollable::-webkit-scrollbar-track { + background: #f1f1f1; + } + + .card-scrollable::-webkit-scrollbar-thumb { + background: #888; + border-radius: 5px; + } + + .card-scrollable::-webkit-scrollbar-thumb:hover { + background: #555; + } + + /* 确保卡片有统一的高度 */ + .col-md-4 .card { + height: 100%; + } + + .col-md-4 .card-body { + padding: 0.75rem; + } {% block extra_js %} diff --git a/inventory/views_barcode.py b/inventory/views_barcode.py index f697473..8531599 100644 --- a/inventory/views_barcode.py +++ b/inventory/views_barcode.py @@ -41,7 +41,8 @@ def barcode_product_create(request): 'manufacturer': barcode_data.get('manufacturer', ''), 'price': barcode_data.get('suggested_price', 0), 'cost': barcode_data.get('suggested_price', 0) * 0.8 if barcode_data.get('suggested_price') else 0, # 默认成本价为建议售价的80% - 'description': barcode_data.get('description', '') + 'description': barcode_data.get('description', ''), + 'is_active': True # 确保初始化时is_active为True } # 尝试从数据库中查找匹配的商品类别 @@ -57,14 +58,16 @@ def barcode_product_create(request): messages.success(request, '成功获取商品信息,请确认并完善商品详情') else: messages.info(request, f'未找到条码 {barcode} 的商品信息,请手动填写') - initial_data = {'barcode': barcode} + initial_data = {'barcode': barcode, 'is_active': True} # 确保初始化时is_active为True # 处理表单提交 if request.method == 'POST': form = forms.ProductForm(request.POST, request.FILES) if form.is_valid(): - # 保存商品信息 - product = form.save() + # 确保is_active为True + product = form.save(commit=False) + product.is_active = True + product.save() # 创建初始库存记录 initial_stock = request.POST.get('initial_stock', 0)