diff --git a/inventory-backend/app/services/inbound/buy_service.py b/inventory-backend/app/services/inbound/buy_service.py index 312195c..52545b2 100644 --- a/inventory-backend/app/services/inbound/buy_service.py +++ b/inventory-backend/app/services/inbound/buy_service.py @@ -44,6 +44,11 @@ class BuyInboundService: except ValueError: in_date_val = datetime.utcnow().date() + # --- 修改部分:增加字段兼容性,确保前端传参能被正确读取 --- + in_qty = float(data.get('in_quantity') or data.get('qty_inbound') or 0) + u_price = float(data.get('unit_price') or data.get('price_unit') or 0) + # --------------------------------------------------- + # 3. 创建 StockBuy new_stock = StockBuy( base_id=material.id, @@ -53,12 +58,12 @@ class BuyInboundService: batch_number=data.get('batch_number'), status='在库', inspection_status=data.get('inspection_status'), - in_quantity=data.get('in_quantity', 0), - stock_quantity=data.get('in_quantity', 0), - available_quantity=data.get('in_quantity', 0), - warehouse_location=data.get('warehouse_location'), - unit_price=data.get('unit_price', 0), - total_price=data.get('total_price', 0), + in_quantity=in_qty, + stock_quantity=in_qty, + available_quantity=in_qty, + warehouse_location=data.get('warehouse_location') or data.get('warehouse_loc'), + unit_price=u_price, + total_price=in_qty * u_price, currency=data.get('currency', 'CNY'), exchange_rate=data.get('exchange_rate', 1.0), supplier_name=data.get('supplier_name'), @@ -85,10 +90,11 @@ class BuyInboundService: if not stock: raise ValueError("记录不存在") - # 1. 更新普通字段 + # 1. 更新普通字段 (增加对 warehouse_loc 的兼容) if 'serial_number' in data: stock.serial_number = data['serial_number'] if 'batch_number' in data: stock.batch_number = data['batch_number'] if 'warehouse_location' in data: stock.warehouse_location = data['warehouse_location'] + if 'warehouse_loc' in data: stock.warehouse_location = data['warehouse_loc'] if 'supplier_name' in data: stock.supplier_name = data['supplier_name'] if 'status' in data: stock.status = data['status'] if 'inspection_status' in data: stock.inspection_status = data['inspection_status'] @@ -101,13 +107,14 @@ class BuyInboundService: if 'category' in data: stock.material.category = data['category'] if 'unit' in data: stock.material.unit = data['unit'] - # 3. 核心逻辑:数量与价格联动 + # 3. 核心逻辑:数量与价格联动 (增加对前端返回字段名 qty_inbound 和 price_unit 的识别) qty_changed = False price_changed = False # (A) 数量变更 -> 更新库存和可用量 - if 'in_quantity' in data: - new_qty = float(data['in_quantity']) + new_qty_input = data.get('in_quantity') or data.get('qty_inbound') + if new_qty_input is not None: + new_qty = float(new_qty_input) old_qty = float(stock.in_quantity) diff = new_qty - old_qty @@ -118,8 +125,9 @@ class BuyInboundService: qty_changed = True # (B) 单价变更 - if 'unit_price' in data: - new_price = float(data['unit_price']) + new_price_input = data.get('unit_price') or data.get('price_unit') + if new_price_input is not None: + new_price = float(new_price_input) if new_price != float(stock.unit_price): stock.unit_price = new_price price_changed = True diff --git a/inventory-web/.env.development b/inventory-web/.env.development index 84a38dc..0b9e90e 100644 --- a/inventory-web/.env.development +++ b/inventory-web/.env.development @@ -1,3 +1,3 @@ # .env.development # 注意:这里必须写你电脑的局域网 IP -VITE_API_BASE_URL=http://172.25.16.1:8000/api/v1 \ No newline at end of file +VITE_API_BASE_URL=http://172.16.0.95:8000/api/v1 \ No newline at end of file diff --git a/inventory-web/src/views/dashboard/index.vue b/inventory-web/src/views/dashboard/index.vue index 8dd903b..5a73df0 100644 --- a/inventory-web/src/views/dashboard/index.vue +++ b/inventory-web/src/views/dashboard/index.vue @@ -28,13 +28,6 @@ 借库申请 - -
- - - 数据大屏 (开发中) - -
diff --git a/inventory-web/src/views/material/list.vue b/inventory-web/src/views/material/list.vue index 9f05488..82973be 100644 --- a/inventory-web/src/views/material/list.vue +++ b/inventory-web/src/views/material/list.vue @@ -3,7 +3,6 @@ + \ No newline at end of file diff --git a/inventory-web/src/views/stock/inbound/buy.vue b/inventory-web/src/views/stock/inbound/buy.vue index fbfe004..82aca0e 100644 --- a/inventory-web/src/views/stock/inbound/buy.vue +++ b/inventory-web/src/views/stock/inbound/buy.vue @@ -2,19 +2,19 @@
- 全量采购入库登记 - 刷新数据 + 采购入库登记 + 刷新数据
基础层字段 - {{ c.label }} + {{ c.label }} 库存/财务层字段 - {{ c.label }} + {{ c.label }}
@@ -25,15 +25,16 @@ border stripe style="width: 100%" - size="small" + size="default" highlight-current-row + class="custom-big-table" >