pos_order.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_pos_order_baco():
  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. partner.ruc,
  27. partner.phone,
  28. partner.mobile,
  29. partner.email,
  30. partner.city
  31. FROM pos_order as pos
  32. LEFT JOIN res_store_journal_rel as journal
  33. ON journal.journal_id = pos.sale_journal
  34. LEFT JOIN pos_order_line AS line
  35. ON line.order_id = pos.id
  36. LEFT JOIN res_partner AS partner
  37. ON partner.id = pos.partner_id
  38. LEFT JOIN res_users AS users
  39. ON users.id = pos.user_id
  40. LEFT JOIN res_partner AS salesperson
  41. ON salesperson.id = users.partner_id
  42. GROUP BY
  43. pos.create_date,
  44. pos.partner_id,
  45. pos.user_id,
  46. pos.name,
  47. partner.name,
  48. pos.id,
  49. salesperson.name,
  50. pos.sale_journal,
  51. journal.store_id,
  52. pos.company_id,
  53. partner.ruc,
  54. partner.phone,
  55. partner.mobile,
  56. partner.email,
  57. partner.city
  58. '''
  59. r.cr.execute(validate)
  60. for j in r.cr.fetchall():
  61. band = j[0]
  62. if band == True:
  63. r.cr.execute(query)
  64. return [
  65. {
  66. 'date': j[0],
  67. 'name': j[1],
  68. 'customer_id': j[2],
  69. 'user_id': j[3],
  70. 'amount': j[4],
  71. 'customer_name': j[5],
  72. 'order_id': j[6],
  73. 'user_name': j[7],
  74. 'amount_untaxed': j[8],
  75. 'journal_id': j[9],
  76. 'store_id': j[10],
  77. 'company_id': j[11],
  78. 'customer_ruc': j[12],
  79. 'phone':j[13],
  80. 'mobile':j[14],
  81. 'email':j[15],
  82. 'city':j[16],
  83. } for j in r.cr.fetchall()
  84. ]
  85. else:
  86. return []