pos_order_line.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_pos_order_line_widget():
  4. user_store = r.env.user.store_id.id
  5. company_currency_rate = r.env.user.company_id.currency_id.rate
  6. validate = '''
  7. SELECT EXISTS(
  8. SELECT table_name
  9. FROM information_schema.columns
  10. WHERE table_schema='public'
  11. AND table_name='pos_order')
  12. '''
  13. query = '''
  14. SELECT
  15. pos.id,
  16. line.id,
  17. pos.name,
  18. product.name_template,
  19. line.price_unit,
  20. line.qty,
  21. line.price_subtotal,
  22. (line.price_unit * line.qty) - line.price_subtotal AS impuestos,
  23. (array_agg(history.cost ORDER BY history.id DESC))[1] AS cost,
  24. history.product_template_id,
  25. pos.date_order
  26. FROM pos_order AS pos
  27. LEFT JOIN pos_order_line AS line
  28. ON pos.id = line.order_id
  29. LEFT JOIN res_store_journal_rel as journal
  30. ON journal.journal_id = pos.sale_journal
  31. LEFT JOIN product_product as product
  32. ON product.id = line.product_id
  33. LEFT JOIN product_price_history AS history
  34. ON history.product_template_id = product.product_tmpl_id
  35. WHERE TO_CHAR(pos.date_order,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  36. AND journal.store_id = ''' + str(user_store) + '''
  37. AND pos.state NOT IN ('draft')
  38. GROUP BY
  39. pos.id,
  40. line.id,
  41. pos.name,
  42. product.name_template,
  43. line.price_unit,
  44. line.qty,
  45. line.price_subtotal,
  46. history.product_template_id,
  47. pos.date_order
  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,(tuple([company_currency_rate])))
  54. return [
  55. {
  56. 'order_id': j[0],
  57. 'order_line_id': j[1],
  58. 'name': j[2],
  59. 'product_name':j[3],
  60. 'price_unit':j[4],
  61. 'quantity':j[5],
  62. 'subtotal':j[6],
  63. 'tax': j[7],
  64. 'cost': j[8],
  65. 'history_id': j[9],
  66. 'date': j[10],
  67. } for j in r.cr.fetchall()
  68. ]
  69. else:
  70. return []