pos_order.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_pos_order():
  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
  14. pos.create_date,
  15. pos.name,
  16. pos.partner_id,
  17. pos.user_id,
  18. SUM(line.price_subtotal_incl) as amount,
  19. partner.name,
  20. pos.id,
  21. salesperson.name,
  22. SUM(line.price_subtotal) as untaxed,
  23. pos.sale_journal,
  24. journal.store_id,
  25. pos.company_id
  26. FROM pos_order as pos
  27. LEFT JOIN res_store_journal_rel as journal
  28. ON journal.journal_id = pos.sale_journal
  29. LEFT JOIN pos_order_line AS line
  30. ON line.order_id = pos.id
  31. LEFT JOIN res_partner AS partner
  32. ON partner.id = pos.partner_id
  33. LEFT JOIN res_users AS users
  34. ON users.id = pos.user_id
  35. LEFT JOIN res_partner AS salesperson
  36. ON salesperson.id = users.partner_id
  37. GROUP BY
  38. pos.create_date,
  39. pos.partner_id,
  40. pos.user_id,
  41. pos.name,
  42. partner.name,
  43. pos.id,
  44. salesperson.name,
  45. pos.sale_journal,
  46. journal.store_id,
  47. pos.company_id
  48. '''
  49. r.cr.execute(validate)
  50. for j in r.cr.fetchall():
  51. band = j[0]
  52. if band == True:
  53. r.cr.execute(query)
  54. return [
  55. {
  56. 'date': j[0],
  57. 'name': j[1],
  58. 'customer_id': j[2],
  59. 'user_id': j[3],
  60. 'amount': j[4],
  61. 'customer_name': j[5],
  62. 'order_id': j[6],
  63. 'user_name': j[7],
  64. 'amount_untaxed': j[8],
  65. 'journal_id': j[9],
  66. 'store_id': j[10],
  67. 'company_id': j[11]
  68. } for j in r.cr.fetchall()
  69. ]
  70. else:
  71. return []