from app.extensions import db

class BomTable(db.Model):
    __tablename__ = 'bom_table'

    id = db.Column(db.Integer, primary_key=True)
    parent_id = db.Column(db.Integer, db.ForeignKey('material_base.id'), nullable=False)
    child_id = db.Column(db.Integer, db.ForeignKey('material_base.id'), nullable=False)
    bom_no = db.Column(db.String(100), comment='BOM编号')
    version = db.Column(db.String(50), comment='版本')
    dosage = db.Column(db.Numeric(19, 4), comment='用量')
    loss_rate = db.Column(db.Numeric(5, 2), comment='损耗率%')
    remark = db.Column(db.Text, comment='备注')

    # relationships
    parent = db.relationship('MaterialBase', foreign_keys=[parent_id], backref='bom_parents')
    child = db.relationship('MaterialBase', foreign_keys=[child_id], backref='bom_children')
