fix: add total_price field to product inbound creation and update calculation

Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
dxc
2026-03-02 12:10:41 +08:00
parent d993e6796e
commit 8264867b1c

View File

@ -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(' ~ ')