39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
from sqlalchemy import Column, Integer, String, Date, UniqueConstraint, Numeric, Text
|
|
|
|
from commons.models.mixin.base import BaseModelMixin
|
|
from commons.models.model import Model
|
|
from core.extensions import db
|
|
|
|
|
|
class LocalMaterial(db.Model, Model, BaseModelMixin):
|
|
__tablename__ = 'LOCAL_MATERIAL'
|
|
id = Column('ID', Integer, primary_key=True)
|
|
name = Column('NAME', String(128), default='', comment='名称')
|
|
city = Column('CITY', String(128), default='', comment='地市')
|
|
county = Column('COUNTY', String(128), default='', comment='区县')
|
|
material_id = Column('MATERIAL_ID', String(128), comment='材料id')
|
|
spec = Column('SPEC', String(128), default='', comment='规格')
|
|
unit = Column('UNIT', String(128), default='', comment='单位')
|
|
price = Column('PRICE', Numeric(16, 4), default=0, comment='价格')
|
|
price_without_tax = Column('PRICE_WITHOUT_TAX', Numeric(16, 4), default=0, comment='除税价')
|
|
date = Column('DATE', Date, comment='日期')
|
|
position = Column('POSITION', String(256), comment='位置')
|
|
remark = Column('REMARK', Text, comment='备注')
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint(name, spec, city, county, date, name='Idx_key'),
|
|
{'comment': '地材'},
|
|
)
|
|
|
|
def find_by_key(self):
|
|
cls = self.__class__
|
|
query = cls.query
|
|
query = query.filter(cls.date == self.date)
|
|
query = query.filter(cls.spec == self.spec)
|
|
query = query.filter(cls.name == self.name)
|
|
query = query.filter(cls.city == self.city)
|
|
query = query.filter(cls.county == self.county)
|
|
result = query.one_or_none()
|
|
return result
|
|
|