From 8264867b1c7839a9eb374f472835b60ed7404848 Mon Sep 17 00:00:00 2001 From: dxc Date: Mon, 2 Mar 2026 12:10:41 +0800 Subject: [PATCH] fix: add total_price field to product inbound creation and update calculation Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) --- inventory-backend/app/services/inbound/product_service.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inventory-backend/app/services/inbound/product_service.py b/inventory-backend/app/services/inbound/product_service.py index bdaf8f9..235e4c3 100644 --- a/inventory-backend/app/services/inbound/product_service.py +++ b/inventory-backend/app/services/inbound/product_service.py @@ -171,6 +171,7 @@ class ProductInboundService: production_time_range=time_range, raw_material_cost=raw_cost, manual_cost=unit_total_cost, + total_price=total_price, quality_status=data.get('quality_status', '合格'), product_photo=json.dumps(photo_list), quality_report_link=json.dumps(quality_list), @@ -230,6 +231,11 @@ class ProductInboundService: stock.stock_quantity = float(stock.stock_quantity) + diff stock.available_quantity = float(stock.available_quantity) + diff + # 计算总成本 + if 'unit_total_cost' in data or 'in_quantity' in data: + qty = float(data.get('in_quantity', stock.in_quantity or 1)) + stock.total_price = float(stock.manual_cost or 0) * qty + if 'production_start_time' in data or 'production_end_time' in data: old_range = stock.production_time_range or " ~ " parts = old_range.split(' ~ ')