采购件图像上传初实现

This commit is contained in:
dxc
2026-02-03 11:16:12 +08:00
parent efcd2d923c
commit 7fa40115d9
7 changed files with 510 additions and 91 deletions

View File

@ -82,9 +82,8 @@ class BuyInboundService:
generated_sku = str(next_global_id).zfill(10)
# ------------------------------------------------------------------
# 3. 条码逻辑处理 (核心修改)
# 3. 条码逻辑处理
# 如果前端没传条码(barcode),则默认使用系统生成的 SKU 作为条码
# 这样保证了条码生成依据是 "自动填写的 SKU"
# ------------------------------------------------------------------
final_barcode = data.get('barcode')
if not final_barcode:
@ -93,8 +92,8 @@ class BuyInboundService:
new_stock = StockBuy(
base_id=material.id,
global_print_id=next_global_id,
sku=generated_sku, # 自动生成的SKU
barcode=final_barcode, # 如果未输入则存入SKU值
sku=generated_sku,
barcode=final_barcode,
in_date=in_date_val,
serial_number=data.get('serial_number'),
@ -114,13 +113,15 @@ class BuyInboundService:
buyer_email=data.get('purchaser_email'),
original_link=data.get('source_link'),
detail_link=data.get('detail_link'),
arrival_photo=data.get('arrival_photo')
arrival_photo=data.get('arrival_photo'),
# [新增] 保存检测报告字段
inspection_report=data.get('inspection_report')
)
db.session.add(new_stock)
db.session.commit()
# 返回创建的对象实例
return new_stock
except Exception as e:
@ -151,7 +152,10 @@ class BuyInboundService:
'exchange_rate': 'exchange_rate',
'purchaser': 'buyer_name',
'purchaser_email': 'buyer_email',
'source_link': 'original_link'
'source_link': 'original_link',
# [新增] 允许更新检测报告
'inspection_report': 'inspection_report'
}
for frontend_key, db_attr in field_mapping.items():
@ -207,7 +211,6 @@ class BuyInboundService:
@staticmethod
def get_list(page, limit, keyword=None):
try:
# 1. 查询分页数据
query = db.session.query(StockBuy).outerjoin(MaterialBase, StockBuy.base_id == MaterialBase.id)
if keyword:
@ -223,9 +226,6 @@ class BuyInboundService:
pagination = query.order_by(StockBuy.id.desc()).paginate(page=page, per_page=limit, error_out=False)
# ---------------------------------------------------------------------
# 计算总库存 (聚合)
# ---------------------------------------------------------------------
current_items = pagination.items
base_ids = list(set([item.base_id for item in current_items if item.base_id]))
@ -289,6 +289,9 @@ class BuyInboundService:
'detail_link': item.detail_link,
'arrival_photo': item.arrival_photo,
# [新增] 返回检测报告
'inspection_report': item.inspection_report,
'global_print_id': item.global_print_id,
'global_print_id_str': f"{item.global_print_id:08d}" if item.global_print_id else ""
}