pos_order.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 []