dashboard_objective.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_dashboard_objective_widget():
  4. user_store = r.env.user.store_id.id
  5. query = '''
  6. SELECT user_id,
  7. store_id,
  8. date,
  9. sale_objective
  10. FROM salesman_objective
  11. WHERE TO_CHAR(date,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  12. AND store_id = ''' + str(user_store) + '''
  13. '''
  14. r.cr.execute(query)
  15. return [
  16. {
  17. 'user_id': j[0],
  18. 'store_id': j[1],
  19. 'date': j[2],
  20. 'sale_objective': j[3],
  21. } for j in r.cr.fetchall()
  22. ]
  23. def get_own_objective():
  24. user_id = r.env.user.id
  25. user_store = r.env.user.store_id.id
  26. query = '''
  27. SELECT user_id,
  28. store_id,
  29. date,
  30. sale_objective
  31. FROM salesman_objective
  32. WHERE TO_CHAR(date,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  33. AND store_id = ''' + str(user_store) + ''' AND user_id = ''' + str(user_id) + '''
  34. '''
  35. r.cr.execute(query)
  36. return [
  37. {
  38. 'user_id': j[0],
  39. 'store_id': j[1],
  40. 'date': j[2],
  41. 'sale_objective': j[3],
  42. } for j in r.cr.fetchall()
  43. ]