采购件,半成品,产品页面初步完成
This commit is contained in:
102
inventory-backend/app/models/inbound/product.py
Normal file
102
inventory-backend/app/models/inbound/product.py
Normal file
@ -0,0 +1,102 @@
|
||||
# app/models/inbound/product.py
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class StockProduct(db.Model):
|
||||
"""
|
||||
成品入库库存表
|
||||
对应数据库表: stock_product
|
||||
"""
|
||||
__tablename__ = 'stock_product'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
base_id = db.Column(db.Integer, db.ForeignKey('material_base.id'), nullable=False)
|
||||
|
||||
sku = db.Column(db.String(100))
|
||||
production_date = db.Column(db.Date)
|
||||
barcode = db.Column(db.String(100))
|
||||
serial_number = db.Column(db.String(100))
|
||||
# SQL 无 batch_number
|
||||
|
||||
# 数量
|
||||
in_quantity = db.Column(db.Numeric(19, 4), default=0)
|
||||
stock_quantity = db.Column(db.Numeric(19, 4), default=0)
|
||||
available_quantity = db.Column(db.Numeric(19, 4), default=0)
|
||||
|
||||
# 状态与位置
|
||||
status = db.Column(db.String(50))
|
||||
warehouse_location = db.Column(db.String(100))
|
||||
|
||||
# 生产与成本
|
||||
bom_code = db.Column('bom_id', db.String(100)) # 映射 SQL: bom_id
|
||||
bom_version = db.Column(db.String(50))
|
||||
work_order_code = db.Column('work_order_id', db.String(100)) # 映射 SQL: work_order_id
|
||||
|
||||
raw_material_cost = db.Column(db.Numeric(19, 4), default=0)
|
||||
manual_cost = db.Column(db.Numeric(19, 4), default=0)
|
||||
|
||||
production_manager = db.Column('producer_name', db.String(100)) # 映射 SQL: producer_name
|
||||
production_time_range = db.Column(db.String(255))
|
||||
|
||||
# 质量与链接
|
||||
quality_status = db.Column(db.String(50))
|
||||
quality_report_link = db.Column(db.Text)
|
||||
detail_link = db.Column(db.Text)
|
||||
|
||||
# 成品特有字段
|
||||
sale_price = db.Column(db.Numeric(19, 4), default=0)
|
||||
inspection_report_link = db.Column(db.Text)
|
||||
order_id = db.Column(db.String(100))
|
||||
|
||||
# 关系定义
|
||||
material = db.relationship('MaterialBase', back_populates='stock_products')
|
||||
|
||||
def to_dict(self):
|
||||
raw_val = float(self.raw_material_cost or 0)
|
||||
man_val = float(self.manual_cost or 0)
|
||||
unit_total = raw_val + man_val
|
||||
|
||||
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 '',
|
||||
|
||||
'sku': self.sku,
|
||||
'inbound_date': self.production_date.strftime('%Y-%m-%d') if self.production_date else '',
|
||||
'barcode': self.barcode,
|
||||
'serial_number': self.serial_number,
|
||||
'warehouse_loc': self.warehouse_location,
|
||||
'status': self.status,
|
||||
|
||||
'in_quantity': float(self.in_quantity or 0),
|
||||
'qty_inbound': float(self.in_quantity or 0),
|
||||
'stock_quantity': float(self.stock_quantity or 0),
|
||||
'qty_stock': float(self.stock_quantity or 0),
|
||||
'available_quantity': float(self.available_quantity or 0),
|
||||
'qty_available': float(self.available_quantity or 0),
|
||||
|
||||
'bom_code': self.bom_code,
|
||||
'bom_version': self.bom_version,
|
||||
'work_order_code': self.work_order_code,
|
||||
'raw_material_cost': raw_val,
|
||||
'manual_cost': man_val,
|
||||
'unit_total_cost': unit_total,
|
||||
'production_manager': self.production_manager,
|
||||
'production_time_range': self.production_time_range,
|
||||
'production_start_time': self.production_time_range.split(' ~ ')[
|
||||
0] if self.production_time_range and ' ~ ' in self.production_time_range else '',
|
||||
'production_end_time': self.production_time_range.split(' ~ ')[
|
||||
1] if self.production_time_range and ' ~ ' in self.production_time_range else '',
|
||||
|
||||
'quality_status': self.quality_status,
|
||||
'quality_report_link': self.quality_report_link,
|
||||
'detail_link': self.detail_link,
|
||||
|
||||
'sale_price': float(self.sale_price or 0),
|
||||
'inspection_report_link': self.inspection_report_link,
|
||||
'order_id': self.order_id
|
||||
}
|
||||
Reference in New Issue
Block a user