Compare commits

5 Commits

Author SHA1 Message Date
dxc
e3a143f730 fix: correct field labels in product advanced filter
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
2026-03-02 17:18:23 +08:00
dxc
f4b8acb916 feat: add total_price field and update advanced filter options
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
2026-03-02 17:09:25 +08:00
dxc
09db84b0ce fix: sync advanced filter field options with actual form fields
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
2026-03-02 17:00:30 +08:00
dxc
06ec540c41 fix: correct advanced filter field options in semi.vue
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
2026-03-02 16:54:47 +08:00
dxc
71e763bcb6 feat: calculate semi-inbound cost based on BOM code
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
2026-03-02 16:47:49 +08:00
4 changed files with 61 additions and 29 deletions

View File

@ -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:

View File

@ -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

View File

@ -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: '=' },

View File

@ -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