添加条形码内容
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
# app/services/inbound/buy_service.py
|
||||
from app.extensions import db
|
||||
from app.models.inbound.buy import StockBuy
|
||||
# ==============================================================================
|
||||
# ✅ 修复点:基础物料模型实际位于 app/models/base.py
|
||||
# ==============================================================================
|
||||
from app.models.base import MaterialBase
|
||||
from datetime import datetime
|
||||
from sqlalchemy import or_, func
|
||||
from sqlalchemy import or_, func, text
|
||||
import traceback
|
||||
|
||||
|
||||
@ -71,13 +69,36 @@ class BuyInboundService:
|
||||
in_qty = float(data.get('in_quantity') or 0)
|
||||
u_price = float(data.get('unit_price') or 0)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 1. 获取全局打印流水号 (跨表唯一)
|
||||
# ------------------------------------------------------------------
|
||||
seq_sql = text("SELECT nextval('global_print_seq')")
|
||||
result = db.session.execute(seq_sql)
|
||||
next_global_id = result.scalar()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 2. 自动生成 SKU (格式: 00000001)
|
||||
# ------------------------------------------------------------------
|
||||
generated_sku = f"{next_global_id:08d}"
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 3. 条码逻辑处理 (核心修改)
|
||||
# 如果前端没传条码(barcode),则默认使用系统生成的 SKU 作为条码
|
||||
# 这样保证了条码生成依据是 "自动填写的 SKU"
|
||||
# ------------------------------------------------------------------
|
||||
final_barcode = data.get('barcode')
|
||||
if not final_barcode:
|
||||
final_barcode = generated_sku
|
||||
|
||||
new_stock = StockBuy(
|
||||
base_id=material.id,
|
||||
sku=data.get('sku'),
|
||||
global_print_id=next_global_id,
|
||||
sku=generated_sku, # 自动生成的SKU
|
||||
barcode=final_barcode, # 如果未输入,则存入SKU值
|
||||
|
||||
in_date=in_date_val,
|
||||
serial_number=data.get('serial_number'),
|
||||
batch_number=data.get('batch_number'),
|
||||
barcode=data.get('barcode'),
|
||||
status='在库',
|
||||
in_quantity=in_qty,
|
||||
stock_quantity=in_qty,
|
||||
@ -98,6 +119,8 @@ class BuyInboundService:
|
||||
|
||||
db.session.add(new_stock)
|
||||
db.session.commit()
|
||||
|
||||
# 返回创建的对象实例
|
||||
return new_stock
|
||||
|
||||
except Exception as e:
|
||||
@ -264,7 +287,10 @@ class BuyInboundService:
|
||||
'purchaser_email': item.buyer_email,
|
||||
'source_link': item.original_link,
|
||||
'detail_link': item.detail_link,
|
||||
'arrival_photo': item.arrival_photo
|
||||
'arrival_photo': item.arrival_photo,
|
||||
|
||||
'global_print_id': item.global_print_id,
|
||||
'global_print_id_str': f"{item.global_print_id:08d}" if item.global_print_id else ""
|
||||
}
|
||||
items.append(d)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user