account_invoice.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_invoice_widget():
  4. user_store = r.env.user.store_id.id
  5. user_id = r.env.user.id
  6. company_currency_rate = r.env.user.company_id.currency_id.rate
  7. query = '''
  8. SELECT
  9. invoice.id,
  10. rate.currency_id,
  11. invoice.date_invoice,
  12. invoice.type,
  13. invoice.origin,
  14. invoice.partner_id,
  15. invoice.user_id,
  16. invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as invoice_rate
  17. FROM account_invoice AS invoice
  18. LEFT JOIN res_store_journal_rel AS journal
  19. ON journal.journal_id = invoice.journal_id
  20. LEFT JOIN res_currency_rate AS rate
  21. ON rate.currency_id = invoice.currency_id
  22. LEFT JOIN res_company AS company
  23. ON company.id = invoice.company_id
  24. WHERE invoice.state NOT IN ('draft', 'cancel')
  25. AND TO_CHAR(invoice.date_invoice,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  26. AND journal.store_id = ''' + str(user_store) + ''' AND invoice.user_id = ''' + str(user_id) + '''
  27. GROUP BY
  28. invoice.id,
  29. rate.currency_id,
  30. invoice.date_invoice,
  31. invoice.type,
  32. invoice.origin,
  33. invoice.amount_total,
  34. invoice.partner_id,
  35. invoice.user_id,
  36. invoice.amount_total
  37. '''
  38. r.cr.execute(query,(tuple([company_currency_rate])))
  39. return [
  40. {
  41. 'invoice_id': j[0],
  42. 'currency_id': j[1],
  43. 'date': j[2],
  44. 'type': j[3],
  45. 'origin': j[4],
  46. 'customer_id':j[5],
  47. 'user_id':j[6],
  48. 'amount':j[7],
  49. } for j in r.cr.fetchall()
  50. ]
  51. def get_account_invoice_salesman_ranking():
  52. user_store = r.env.user.store_id.id
  53. company_currency_rate = r.env.user.company_id.currency_id.rate
  54. query = '''
  55. SELECT
  56. invoice.id,
  57. rate.currency_id,
  58. invoice.date_invoice,
  59. invoice.type,
  60. invoice.origin,
  61. invoice.partner_id,
  62. invoice.user_id,
  63. invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as invoice_rate
  64. FROM account_invoice AS invoice
  65. LEFT JOIN res_store_journal_rel AS journal
  66. ON journal.journal_id = invoice.journal_id
  67. LEFT JOIN res_currency_rate AS rate
  68. ON rate.currency_id = invoice.currency_id
  69. LEFT JOIN res_company AS company
  70. ON company.id = invoice.company_id
  71. WHERE invoice.state NOT IN ('draft', 'cancel')
  72. AND TO_CHAR(invoice.date_invoice,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  73. AND journal.store_id = ''' + str(user_store) + '''
  74. GROUP BY
  75. invoice.id,
  76. rate.currency_id,
  77. invoice.date_invoice,
  78. invoice.type,
  79. invoice.origin,
  80. invoice.amount_total,
  81. invoice.partner_id,
  82. invoice.user_id,
  83. invoice.amount_total
  84. '''
  85. r.cr.execute(query,(tuple([company_currency_rate])))
  86. return [
  87. {
  88. 'invoice_id': j[0],
  89. 'currency_id': j[1],
  90. 'date': j[2],
  91. 'type': j[3],
  92. 'origin': j[4],
  93. 'customer_id':j[5],
  94. 'user_id':j[6],
  95. 'amount':j[7],
  96. } for j in r.cr.fetchall()
  97. ]