pos_order.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_pos_order_widget():
  4. user_store = r.env.user.store_id.id
  5. validate = '''
  6. SELECT EXISTS(
  7. SELECT table_name
  8. FROM information_schema.columns
  9. WHERE table_schema='public'
  10. AND table_name='pos_order')
  11. '''
  12. query = '''
  13. SELECT pos.create_date, pos.name, pos.partner_id, pos.user_id, SUM(line.price_subtotal_incl) as amount
  14. FROM pos_order as pos
  15. LEFT JOIN res_store_journal_rel as journal
  16. ON journal.journal_id = pos.sale_journal
  17. LEFT JOIN pos_order_line AS line
  18. ON line.order_id = pos.id
  19. --LEFT JOIN res_partner AS partner
  20. --ON partner.id = pos.partner_id
  21. WHERE TO_CHAR(pos.date_order,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  22. AND journal.store_id = ''' + str(user_store) + '''
  23. GROUP BY pos.create_date, pos.partner_id, pos.user_id, pos.name
  24. '''
  25. r.cr.execute(validate)
  26. for j in r.cr.fetchall():
  27. band = j[0]
  28. if band == True:
  29. r.cr.execute(query)
  30. return [
  31. {
  32. 'date': j[0],
  33. 'name': j[1],
  34. 'customer_id': j[2],
  35. 'user_id': j[3],
  36. 'amount': j[4],
  37. } for j in r.cr.fetchall()
  38. ]
  39. else:
  40. return []
  41. def get_pos_order_widget_own():
  42. user_store = r.env.user.store_id.id
  43. user_id = r.env.user.id
  44. validate = '''
  45. SELECT EXISTS(
  46. SELECT table_name
  47. FROM information_schema.columns
  48. WHERE table_schema='public'
  49. AND table_name='pos_order')
  50. '''
  51. query = '''
  52. SELECT pos.create_date, pos.name, pos.partner_id, pos.user_id, SUM(line.price_subtotal_incl) as amount
  53. FROM pos_order as pos
  54. LEFT JOIN res_store_journal_rel as journal
  55. ON journal.journal_id = pos.sale_journal
  56. LEFT JOIN pos_order_line AS line
  57. ON line.order_id = pos.id
  58. --LEFT JOIN res_partner AS partner
  59. --ON partner.id = pos.partner_id
  60. WHERE TO_CHAR(pos.date_order,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  61. AND journal.store_id = ''' + str(user_store) + ''' AND pos.user_id = ''' + str(user_id) + '''
  62. GROUP BY pos.create_date, pos.partner_id, pos.user_id, pos.name
  63. '''
  64. r.cr.execute(validate)
  65. for j in r.cr.fetchall():
  66. band = j[0]
  67. if band == True:
  68. r.cr.execute(query)
  69. return [
  70. {
  71. 'date': j[0],
  72. 'name': j[1],
  73. 'customer_id': j[2],
  74. 'user_id': j[3],
  75. 'amount': j[4],
  76. } for j in r.cr.fetchall()
  77. ]
  78. else:
  79. return []