修正git管理关系
This commit is contained in:
0
inventory-backend/app/services/__init__.py
Normal file
0
inventory-backend/app/services/__init__.py
Normal file
0
inventory-backend/app/services/auth_service.py
Normal file
0
inventory-backend/app/services/auth_service.py
Normal file
0
inventory-backend/app/services/material_service.py
Normal file
0
inventory-backend/app/services/material_service.py
Normal file
39
inventory-backend/app/services/stock_service.py
Normal file
39
inventory-backend/app/services/stock_service.py
Normal file
@ -0,0 +1,39 @@
|
||||
from app.extensions import db
|
||||
from app.models.stock import StockBuy
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
|
||||
def create_inbound_stock(data):
|
||||
"""
|
||||
处理采购入库逻辑
|
||||
"""
|
||||
try:
|
||||
# 1. 计算总价
|
||||
qty = data.get('qty_inbound')
|
||||
price = data.get('price_unit', 0)
|
||||
total = float(qty) * float(price)
|
||||
|
||||
# 2. 创建库存记录
|
||||
# 注意:入库时,当前库存(current)和可用库存(available)通常等于入库数量
|
||||
new_stock = StockBuy(
|
||||
material_id=data['material_id'],
|
||||
barcode=data.get('barcode'),
|
||||
batch_no=data.get('batch_no'),
|
||||
qty_inbound=qty,
|
||||
qty_current=qty, # 初始:当前=入库
|
||||
qty_available=qty, # 初始:可用=入库
|
||||
price_unit=price,
|
||||
price_total=total,
|
||||
supplier_name=data.get('supplier_name'),
|
||||
warehouse_loc=data.get('warehouse_loc'),
|
||||
inbound_date=data.get('inbound_date') # 如果前端没传,Model会默认用当前时间
|
||||
)
|
||||
|
||||
db.session.add(new_stock)
|
||||
db.session.commit()
|
||||
|
||||
return new_stock
|
||||
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
raise e
|
||||
0
inventory-backend/app/services/trans_service.py
Normal file
0
inventory-backend/app/services/trans_service.py
Normal file
Reference in New Issue
Block a user