Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def to_be_calibrate():
- from sqlalchemy import func
- from sqlalchemy.orm import load_only
- # days = result.date + \
- # relativedelta(
- # months=tag.tagtype.calibration_month) - datetime.date.today()
- # defect = True if self.states.name.lower() == 'defekt' else False datetime.timedelta(days=0)
- res = Calibrations.query \
- .join(Product, Calibrations.product_id == Product.id) \
- .join(ProductTags, ProductTags.product_id == Calibrations.product_id) \
- .join(ProductType, ProductType.id == ProductTags.tag_id) \
- .group_by(Calibrations.product_id) \
- .having(func.max(Calibrations.date)) \
- .having(Product.state_id != 4) \
- .having(ProductType.calibration == True) \
- .order_by(Calibrations.date.desc()) \
- .all()
- # res = Product.query \
- # .filter(Product.state_id != 4) \
- # .filter(ProductType.calibration == True) \
- # .filter(Calibrations.date < datetime.date.today() - datetime.timedelta(days=ProductType.calibration_month) + datetime.timedelta(days=0)) \
- # .join(Calibrations) \
- # .all()
- print len(res)
- new_list = []
- for c in res:
- for t in c.product.tags:
- if c.date < datetime.date.today() - relativedelta(months=t.tagtype.calibration_month) + datetime.timedelta(days=0):
- new_list.append(c)
- # res = ProductTags.query.join(ProductType).join(Calibrations,
- # Calibrations.product_id == ProductTags.product_id).filter(
- # ProductType.calibration == 1).order_by(Calibrations.date.desc()).all()
- print len(new_list)
- # print res[0]
- return new_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement