pos_order.py 2.4 KB

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