对于采购件的税率添加以及所属公司添加
This commit is contained in:
@ -4,6 +4,7 @@ import json
|
||||
# 显式导入 MaterialBase 以防 relationship 找不到引用
|
||||
from app.models.base import MaterialBase
|
||||
|
||||
|
||||
class StockBuy(db.Model):
|
||||
"""
|
||||
采购入库库存表
|
||||
@ -32,35 +33,36 @@ class StockBuy(db.Model):
|
||||
available_quantity = db.Column(db.Numeric(19, 4), default=0)
|
||||
|
||||
# 财务与商务
|
||||
unit_price = db.Column(db.Numeric(19, 4), default=0)
|
||||
total_price = db.Column(db.Numeric(19, 4), default=0)
|
||||
unit_price = db.Column(db.Numeric(19, 4), default=0) # 现意为:不含税单价
|
||||
total_price = db.Column(db.Numeric(19, 4), default=0) # 总价
|
||||
# [新增] 税率
|
||||
tax_rate = db.Column(db.Numeric(5, 2), default=0)
|
||||
|
||||
currency = db.Column(db.String(20), default='CNY')
|
||||
exchange_rate = db.Column(db.Numeric(15, 6), default=1.0)
|
||||
|
||||
supplier_name = db.Column(db.String(255))
|
||||
buyer_name = db.Column(db.String(100)) # 对应 SQL: buyer_name
|
||||
buyer_email = db.Column(db.String(100)) # 对应 SQL: buyer_email
|
||||
original_link = db.Column(db.Text) # 对应 SQL: original_link
|
||||
buyer_name = db.Column(db.String(100))
|
||||
buyer_email = db.Column(db.String(100))
|
||||
original_link = db.Column(db.Text)
|
||||
detail_link = db.Column(db.Text)
|
||||
|
||||
# 图片字段 (存储 JSON 字符串)
|
||||
arrival_photo = db.Column(db.Text)
|
||||
# [新增] 检测报告图片路径 (存储 JSON 字符串)
|
||||
inspection_report = db.Column(db.Text)
|
||||
|
||||
# [新增] 全局打印流水号 (用于跨表连续编号,对应 Sequence: global_print_seq)
|
||||
# 全局打印流水号
|
||||
global_print_id = db.Column(db.Integer)
|
||||
|
||||
# 关系定义 [已修改]
|
||||
# 关系定义
|
||||
base = db.relationship('MaterialBase', back_populates='stock_buys')
|
||||
|
||||
def to_dict(self):
|
||||
# 辅助解析函数:将数据库存储的 JSON 字符串转为 List
|
||||
# 辅助解析函数
|
||||
def parse_img_list(json_str):
|
||||
if not json_str:
|
||||
return []
|
||||
try:
|
||||
# 兼容旧数据:如果不是 JSON 格式(比如是单个 URL),则包装成 list
|
||||
if not json_str.startswith('['):
|
||||
return [json_str]
|
||||
return json.loads(json_str)
|
||||
@ -70,7 +72,9 @@ class StockBuy(db.Model):
|
||||
return {
|
||||
'id': self.id,
|
||||
'base_id': self.base_id,
|
||||
# [已修改] 使用 self.base
|
||||
|
||||
# [修改] 增加公司名称
|
||||
'company_name': self.base.company_name if self.base else '',
|
||||
'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 '',
|
||||
@ -95,6 +99,9 @@ class StockBuy(db.Model):
|
||||
|
||||
'unit_price': float(self.unit_price or 0),
|
||||
'total_price': float(self.total_price or 0),
|
||||
# [新增] 税率
|
||||
'tax_rate': float(self.tax_rate or 0),
|
||||
|
||||
'currency': self.currency,
|
||||
'exchange_rate': float(self.exchange_rate or 1.0),
|
||||
|
||||
@ -104,11 +111,9 @@ class StockBuy(db.Model):
|
||||
'source_link': self.original_link,
|
||||
'detail_link': self.detail_link,
|
||||
|
||||
# [修改] 解析为数组返回给前端
|
||||
'arrival_photo': parse_img_list(self.arrival_photo),
|
||||
'inspection_report': parse_img_list(self.inspection_report),
|
||||
|
||||
# [新增] 返回全局打印ID及其格式化字符串
|
||||
'global_print_id': self.global_print_id,
|
||||
'global_print_id_str': f"{self.global_print_id:010d}" if self.global_print_id else ""
|
||||
}
|
||||
Reference in New Issue
Block a user