Compare commits
5 Commits
a5fcbd70f8
...
e3a143f730
| Author | SHA1 | Date | |
|---|---|---|---|
| e3a143f730 | |||
| f4b8acb916 | |||
| 09db84b0ce | |||
| 06ec540c41 | |||
| 71e763bcb6 |
@ -343,6 +343,7 @@ class ProductInboundService:
|
|||||||
'order_id': StockProduct.order_id,
|
'order_id': StockProduct.order_id,
|
||||||
'sale_price': StockProduct.sale_price,
|
'sale_price': StockProduct.sale_price,
|
||||||
'production_manager': StockProduct.production_manager,
|
'production_manager': StockProduct.production_manager,
|
||||||
|
'total_price': (StockProduct.manual_cost * StockProduct.in_quantity),
|
||||||
}
|
}
|
||||||
for cond in advanced_filters:
|
for cond in advanced_filters:
|
||||||
field = cond.get('field')
|
field = cond.get('field')
|
||||||
@ -406,6 +407,7 @@ class ProductInboundService:
|
|||||||
'order_id': StockProduct.order_id,
|
'order_id': StockProduct.order_id,
|
||||||
'sale_price': StockProduct.sale_price,
|
'sale_price': StockProduct.sale_price,
|
||||||
'production_manager': StockProduct.production_manager,
|
'production_manager': StockProduct.production_manager,
|
||||||
|
'total_price': (StockProduct.manual_cost * StockProduct.in_quantity),
|
||||||
}
|
}
|
||||||
order_field = order_mapping.get(order_by_column)
|
order_field = order_mapping.get(order_by_column)
|
||||||
if order_field is not None:
|
if order_field is not None:
|
||||||
|
|||||||
@ -156,8 +156,14 @@ class SemiInboundService:
|
|||||||
|
|
||||||
in_qty = float(data.get('in_quantity') or 0)
|
in_qty = float(data.get('in_quantity') or 0)
|
||||||
raw_cost = float(data.get('raw_material_cost') or 0)
|
raw_cost = float(data.get('raw_material_cost') or 0)
|
||||||
# 【重要修改】:把前端的 unit_total_cost(单件成本)存入原数据库的 manual_cost 字段中
|
bom_code = data.get('bom_code')
|
||||||
unit_cost = float(data.get('unit_total_cost') or raw_cost)
|
bom_version = data.get('bom_version')
|
||||||
|
# 根据是否有BOM决定单价
|
||||||
|
if bom_code and bom_version:
|
||||||
|
# 使用BOM成本作为单价
|
||||||
|
unit_cost = SemiInboundService.calculate_bom_cost(bom_code, bom_version)
|
||||||
|
else:
|
||||||
|
unit_cost = raw_cost
|
||||||
total_value = unit_cost * in_qty
|
total_value = unit_cost * in_qty
|
||||||
|
|
||||||
next_global_id = 0
|
next_global_id = 0
|
||||||
@ -304,13 +310,23 @@ class SemiInboundService:
|
|||||||
|
|
||||||
if 'raw_material_cost' in data:
|
if 'raw_material_cost' in data:
|
||||||
stock.raw_material_cost = float(data['raw_material_cost'])
|
stock.raw_material_cost = float(data['raw_material_cost'])
|
||||||
if 'unit_total_cost' in data:
|
|
||||||
stock.manual_cost = float(data['unit_total_cost']) # 映射到 manual_cost 物理字段
|
# 决定单件成本:有BOM用BOM成本,否则用raw_material_cost
|
||||||
|
bom_code = data.get('bom_code', stock.bom_code)
|
||||||
|
bom_version = data.get('bom_version', stock.bom_version)
|
||||||
|
raw_cost = float(data.get('raw_material_cost', stock.raw_material_cost or 0))
|
||||||
|
if bom_code and bom_version:
|
||||||
|
try:
|
||||||
|
unit_cost = SemiInboundService.calculate_bom_cost(bom_code, bom_version)
|
||||||
|
except Exception:
|
||||||
|
unit_cost = raw_cost
|
||||||
|
else:
|
||||||
|
unit_cost = raw_cost
|
||||||
|
stock.manual_cost = unit_cost
|
||||||
|
|
||||||
if 'unit_total_cost' in data or qty_changed:
|
if 'unit_total_cost' in data or qty_changed:
|
||||||
qty = float(stock.in_quantity or 1)
|
qty = float(stock.in_quantity or 1)
|
||||||
# 使用存入 manual_cost 的单价计算总价
|
stock.total_price = unit_cost * qty
|
||||||
stock.total_price = float(stock.manual_cost or 0) * qty
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return stock
|
return stock
|
||||||
|
|||||||
@ -559,18 +559,18 @@ const fieldOptions = ref([
|
|||||||
{ label: 'BaseID', value: 'base_id' },
|
{ label: 'BaseID', value: 'base_id' },
|
||||||
{ label: '所属公司', value: 'company_name' },
|
{ label: '所属公司', value: 'company_name' },
|
||||||
{ label: '名称', value: 'material_name' },
|
{ label: '名称', value: 'material_name' },
|
||||||
{ label: '规格型号', value: 'spec_model' },
|
{ label: '规格', value: 'spec_model' },
|
||||||
{ label: '类别', value: 'category' },
|
{ label: '类别', value: 'category' },
|
||||||
{ label: '类型', value: 'material_type' },
|
{ label: '类型', value: 'material_type' },
|
||||||
{ label: '单位', value: 'unit' },
|
{ label: '单位', value: 'unit' },
|
||||||
{ label: 'SKU', value: 'sku' },
|
{ label: 'SKU', value: 'sku' },
|
||||||
{ label: '入库日期', value: 'inbound_date' },
|
{ label: '入库日期', value: 'inbound_date' },
|
||||||
{ label: '条码', value: 'barcode' },
|
{ label: '条码', value: 'barcode' },
|
||||||
{ label: '序列号', value: 'serial_number' },
|
{ label: '序列号(SN)', value: 'serial_number' },
|
||||||
{ label: '批号', value: 'batch_number' },
|
{ label: '批号', value: 'batch_number' },
|
||||||
{ label: '状态', value: 'status' },
|
{ label: '库存状态', value: 'status' },
|
||||||
{ label: '质量状态', value: 'quality_status' },
|
{ label: '质量状态', value: 'quality_status' },
|
||||||
{ label: '入库量', value: 'in_quantity' },
|
{ label: '入库数量', value: 'in_quantity' },
|
||||||
{ label: '库存数', value: 'stock_quantity' },
|
{ label: '库存数', value: 'stock_quantity' },
|
||||||
{ label: '可用数', value: 'available_quantity' },
|
{ label: '可用数', value: 'available_quantity' },
|
||||||
{ label: '库位', value: 'warehouse_location' },
|
{ label: '库位', value: 'warehouse_location' },
|
||||||
@ -580,9 +580,9 @@ const fieldOptions = ref([
|
|||||||
{ label: '原料成本', value: 'raw_material_cost' },
|
{ label: '原料成本', value: 'raw_material_cost' },
|
||||||
{ label: '单件成本', value: 'unit_total_cost' },
|
{ label: '单件成本', value: 'unit_total_cost' },
|
||||||
{ label: '总成本', value: 'total_price' },
|
{ label: '总成本', value: 'total_price' },
|
||||||
{ label: '生产负责人', value: 'production_manager' },
|
{ label: '订单号', value: 'order_id' },
|
||||||
{ label: '生产开始', value: 'production_start_time' },
|
{ label: '产品定价', value: 'sale_price' },
|
||||||
{ label: '生产结束', value: 'production_end_time' },
|
{ label: '负责人', value: 'production_manager' },
|
||||||
])
|
])
|
||||||
const operatorOptions = ref([
|
const operatorOptions = ref([
|
||||||
{ label: '等于', value: '=' },
|
{ label: '等于', value: '=' },
|
||||||
|
|||||||
@ -632,23 +632,24 @@ const fieldOptions = ref([
|
|||||||
{ label: 'SKU', value: 'sku' },
|
{ label: 'SKU', value: 'sku' },
|
||||||
{ label: '入库日期', value: 'inbound_date' },
|
{ label: '入库日期', value: 'inbound_date' },
|
||||||
{ label: '条码', value: 'barcode' },
|
{ label: '条码', value: 'barcode' },
|
||||||
{ label: '序列号', value: 'serial_number' },
|
|
||||||
{ label: '批号', value: 'batch_number' },
|
{ label: '批号', value: 'batch_number' },
|
||||||
{ label: '状态', value: 'status' },
|
{ label: '序列号', value: 'serial_number' },
|
||||||
{ label: '质量状态', value: 'quality_status' },
|
|
||||||
{ label: '入库量', value: 'qty_inbound' },
|
|
||||||
{ label: '库存数', value: 'qty_stock' },
|
|
||||||
{ label: '可用数', value: 'qty_available' },
|
|
||||||
{ label: '库位', value: 'warehouse_location' },
|
{ label: '库位', value: 'warehouse_location' },
|
||||||
|
{ label: '入库数量', value: 'qty_inbound' },
|
||||||
|
{ label: '当前库存', value: 'qty_stock' },
|
||||||
|
{ label: '当前可用', value: 'qty_available' },
|
||||||
|
{ label: '库存状态', value: 'status' },
|
||||||
|
{ label: '质量状态', value: 'quality_status' },
|
||||||
{ label: 'BOM编号', value: 'bom_code' },
|
{ label: 'BOM编号', value: 'bom_code' },
|
||||||
{ label: 'BOM版本', value: 'bom_version' },
|
{ label: 'BOM版本', value: 'bom_version' },
|
||||||
{ label: '工单号', value: 'work_order_code' },
|
{ label: '工单号', value: 'work_order_code' },
|
||||||
{ label: '原料成本', value: 'raw_material_cost' },
|
|
||||||
{ label: '单件成本', value: 'unit_total_cost' },
|
|
||||||
{ label: '总成本', value: 'total_price' },
|
|
||||||
{ label: '生产负责人', value: 'production_manager' },
|
{ label: '生产负责人', value: 'production_manager' },
|
||||||
{ label: '生产开始', value: 'production_start_time' },
|
{ label: '生产时间', value: 'production_start_time' },
|
||||||
{ label: '生产结束', value: 'production_end_time' },
|
{ label: '生产结束时间', value: 'production_end_time' },
|
||||||
|
{ label: '估算成本', value: 'raw_material_cost' },
|
||||||
|
{ label: '基于BOM成本', value: 'unit_total_cost' },
|
||||||
|
{ label: '总成本', value: 'total_price' },
|
||||||
|
{ label: '详情链接', value: 'detail_link' },
|
||||||
])
|
])
|
||||||
const operatorOptions = ref([
|
const operatorOptions = ref([
|
||||||
{ label: '等于', value: '=' },
|
{ label: '等于', value: '=' },
|
||||||
@ -807,11 +808,24 @@ const form = reactive({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// === 监听计算总成本 ===
|
// === 监听计算总成本 ===
|
||||||
watch([() => form.unit_total_cost, () => form.in_quantity], ([unit, qty]) => {
|
const computeTotalPrice = () => {
|
||||||
const unitNum = Number(unit || 0)
|
let unitCost = 0
|
||||||
const qtyNum = Number(qty || 1)
|
if (form.bom_code) {
|
||||||
form.total_price = Number((unitNum * qtyNum).toFixed(2))
|
// 如果BOM编号有值,则单价采用基于BOM成本 (unit_total_cost)
|
||||||
})
|
unitCost = Number(form.unit_total_cost || 0)
|
||||||
|
} else {
|
||||||
|
// 如果BOM编号为空,则单价采用估算成本 (raw_material_cost)
|
||||||
|
unitCost = Number(form.raw_material_cost || 0)
|
||||||
|
}
|
||||||
|
const qty = Number(form.in_quantity || 1)
|
||||||
|
form.total_price = Number((unitCost * qty).toFixed(2))
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [form.bom_code, form.unit_total_cost, form.raw_material_cost, form.in_quantity],
|
||||||
|
() => computeTotalPrice(),
|
||||||
|
{ immediate: true, deep: false }
|
||||||
|
)
|
||||||
|
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// BOM Search Logic
|
// BOM Search Logic
|
||||||
|
|||||||
Reference in New Issue
Block a user