2024-05-29 10:21:31 +08:00
|
|
|
|
from sqlalchemy import Column, Integer, String
|
|
|
|
|
|
|
|
|
|
from commons.models.mixin.operation_track import OperationTrackMixin
|
2024-06-05 09:04:48 +08:00
|
|
|
|
from commons.models.model import Model
|
2024-05-29 10:21:31 +08:00
|
|
|
|
from core.extensions import db
|
|
|
|
|
|
|
|
|
|
|
2024-06-05 09:04:48 +08:00
|
|
|
|
class Material(db.Model, Model, OperationTrackMixin):
|
2024-05-29 10:21:31 +08:00
|
|
|
|
id = Column('ID', String(128), primary_key=True)
|
|
|
|
|
parent_id = Column('PARENT_ID', String(128))
|
|
|
|
|
category_1 = Column('CATEGORY1', String(128), default='', comment='分类1')
|
|
|
|
|
category_2 = Column('CATEGORY2', String(128), default='', comment='分类2')
|
|
|
|
|
category_3 = Column('CATEGORY3', String(128), default='', comment='分类3')
|
|
|
|
|
category_4 = Column('CATEGORY4', String(128), default='', comment='分类4')
|
|
|
|
|
name = Column('NAME', String(128), default='', comment='名称')
|
|
|
|
|
unit = Column('UNIT', String(128), default='', comment='单位')
|
|
|
|
|
spec = Column('SPEC', String(128), default='', comment='规格')
|
|
|
|
|
tax = Column('TAX', Integer, default=0, comment='税率(%)')
|
|
|
|
|
is_builtin = Column('IS_BUILTIN', Integer, default=0, comment='是否初始内建类型(不允许删除)')
|
|
|
|
|
type = Column('TYPE', Integer, default=0, comment='材料类别(主材、地材)')
|
|
|
|
|
is_tree = Column('IS_TREE', Integer, default=0, comment='是否树')
|
|
|
|
|
|
|
|
|
|
__tablename__ = 'MATERIAL'
|
|
|
|
|
__table_args__ = (
|
|
|
|
|
{'comment': '材料'},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def get_by_key(cls, id):
|
|
|
|
|
return cls.query.filter(cls.id == id).one_or_none()
|
|
|
|
|
|
|
|
|
|
def upsert(self):
|
|
|
|
|
result = self.get_by_key(self.id)
|
|
|
|
|
if not result:
|
|
|
|
|
session = db.session
|
|
|
|
|
session.add(self)
|
|
|
|
|
session.commit()
|
|
|
|
|
else:
|
|
|
|
|
session = db.session
|
|
|
|
|
self.id = result.id
|
|
|
|
|
session.add(result)
|
|
|
|
|
session.commit()
|