41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
import datetime
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
from sqlalchemy import Column, Integer, String, Date, UniqueConstraint, Numeric
|
|
|
|
from core.extensions import db
|
|
|
|
|
|
class FujianSurvey(db.Model):
|
|
__tablename__ = 'FUJIAN_SURVEY'
|
|
id = Column('ID', Integer, primary_key=True)
|
|
name = Column('NAME', String(128), default='', comment='名称')
|
|
spec = Column('SPEC', String(128), default='', comment='规格')
|
|
price = Column('PRICE', Numeric(16, 4), default=0, comment='价格')
|
|
date = Column('DATE', Date, comment='日期')
|
|
material_id = Column('MATERIAL_ID', String(128), comment='材料id')
|
|
unit = Column('UNIT', String(128), comment='单位')
|
|
brand = Column('BRAND', String(128), comment='品牌')
|
|
tax = Column('TAX', Integer, comment='税率')
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint(name, spec, date, name='Idx_key'),
|
|
{'comment': '福建省交通工程材料调查表'},
|
|
)
|
|
|
|
@classmethod
|
|
def get_query(cls, year=None, month=None, name=None, spec=None, name_in=None):
|
|
query = cls.query
|
|
if year and month:
|
|
start_date = datetime.date(year, month, 1)
|
|
end_date = start_date + relativedelta(months=1)
|
|
query = query.filter(cls.date >= start_date)
|
|
query = query.filter(cls.date < end_date)
|
|
if name:
|
|
query = query.filter(cls.name == name)
|
|
if name_in:
|
|
query = query.filter(cls.name.in_(name_in))
|
|
if spec:
|
|
query = query.filter(cls.spec == spec)
|
|
return query
|