Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. def to_be_calibrate():
  2. from sqlalchemy import func
  3. from sqlalchemy.orm import load_only
  4. # days = result.date + \
  5. # relativedelta(
  6. # months=tag.tagtype.calibration_month) - datetime.date.today()
  7. # defect = True if self.states.name.lower() == 'defekt' else False datetime.timedelta(days=0)
  8.  
  9. res = Calibrations.query \
  10. .join(Product, Calibrations.product_id == Product.id) \
  11. .join(ProductTags, ProductTags.product_id == Calibrations.product_id) \
  12. .join(ProductType, ProductType.id == ProductTags.tag_id) \
  13. .group_by(Calibrations.product_id) \
  14. .having(func.max(Calibrations.date)) \
  15. .having(Product.state_id != 4) \
  16. .having(ProductType.calibration == True) \
  17. .order_by(Calibrations.date.desc()) \
  18. .all()
  19. # res = Product.query \
  20. # .filter(Product.state_id != 4) \
  21. # .filter(ProductType.calibration == True) \
  22. # .filter(Calibrations.date < datetime.date.today() - datetime.timedelta(days=ProductType.calibration_month) + datetime.timedelta(days=0)) \
  23. # .join(Calibrations) \
  24. # .all()
  25. print len(res)
  26. new_list = []
  27. for c in res:
  28. for t in c.product.tags:
  29. if c.date < datetime.date.today() - relativedelta(months=t.tagtype.calibration_month) + datetime.timedelta(days=0):
  30. new_list.append(c)
  31. # res = ProductTags.query.join(ProductType).join(Calibrations,
  32. # Calibrations.product_id == ProductTags.product_id).filter(
  33. # ProductType.calibration == 1).order_by(Calibrations.date.desc()).all()
  34. print len(new_list)
  35. # print res[0]
  36.  
  37. return new_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement