修复出库时候找不到名称等问题

This commit is contained in:
dxc
2026-02-10 11:13:07 +08:00
parent bccbeaadce
commit e876505a1b
7 changed files with 49 additions and 40 deletions

View File

@ -1,5 +1,8 @@
# inventory-backend/app/models/inbound/buy.py
from app.extensions import db
import json
# 显式导入 MaterialBase 以防 relationship 找不到引用
from app.models.base import MaterialBase
class StockBuy(db.Model):
"""
@ -48,9 +51,8 @@ class StockBuy(db.Model):
# [新增] 全局打印流水号 (用于跨表连续编号,对应 Sequence: global_print_seq)
global_print_id = db.Column(db.Integer)
# 关系定义
# 注意:这里使用字符串 'MaterialBase' 引用,避免了直接 import 导致的潜在循环依赖
material = db.relationship('MaterialBase', back_populates='stock_buys')
# 关系定义 [已修改]
base = db.relationship('MaterialBase', back_populates='stock_buys')
def to_dict(self):
# 辅助解析函数:将数据库存储的 JSON 字符串转为 List
@ -68,11 +70,12 @@ class StockBuy(db.Model):
return {
'id': self.id,
'base_id': self.base_id,
'material_name': self.material.name if self.material else '',
'spec_model': self.material.spec_model if self.material else '',
'category': self.material.category if self.material else '',
'unit': self.material.unit if self.material else '',
'material_type': self.material.material_type if self.material else '',
# [已修改] 使用 self.base
'material_name': self.base.name if self.base else '',
'spec_model': self.base.spec_model if self.base else '',
'category': self.base.category if self.base else '',
'unit': self.base.unit if self.base else '',
'material_type': self.base.material_type if self.base else '',
'sku': self.sku,
'inbound_date': self.in_date.strftime('%Y-%m-%d') if self.in_date else '',