account_invoice.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_invoice_expense():
  4. company_currency_rate = r.env.user.company_id.currency_id.rate
  5. origin = '%PO%'
  6. query = '''
  7. SELECT
  8. invoice.id,
  9. rate.currency_id,
  10. invoice.date_invoice,
  11. invoice.type,
  12. invoice.origin,
  13. invoice.partner_id,
  14. invoice.user_id,
  15. invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
  16. invoice.number,
  17. partner.name,
  18. customer.name,
  19. invoice.amount_tax * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
  20. invoice.state,
  21. journal.store_id,
  22. invoice.journal_id,
  23. invoice.state,
  24. invoice.company_id
  25. FROM account_invoice AS invoice
  26. LEFT JOIN res_store_journal_rel AS journal
  27. ON journal.journal_id = invoice.journal_id
  28. LEFT JOIN res_currency_rate AS rate
  29. ON rate.currency_id = invoice.currency_id
  30. LEFT JOIN res_company AS company
  31. ON company.id = invoice.company_id
  32. LEFT JOIN res_users AS users
  33. ON users.id = invoice.user_id
  34. LEFT JOIN res_partner AS partner
  35. ON partner.id = users.partner_id
  36. LEFT JOIN res_partner AS customer
  37. ON customer.id = invoice.partner_id
  38. WHERE invoice.state NOT IN ('draft', 'cancel')
  39. AND invoice.type IN ('in_invoice')
  40. AND (invoice.origin NOT LIKE %s OR invoice.origin IS NULL)
  41. GROUP BY
  42. invoice.id,
  43. rate.currency_id,
  44. invoice.date_invoice,
  45. invoice.type,
  46. invoice.origin,
  47. invoice.amount_total,
  48. invoice.partner_id,
  49. invoice.user_id,
  50. invoice.amount_total,
  51. partner.name,
  52. customer.name,
  53. invoice.amount_tax,
  54. invoice.state,
  55. journal.store_id,
  56. invoice.journal_id,
  57. invoice.state,
  58. invoice.company_id
  59. '''
  60. r.cr.execute(query,(tuple([company_currency_rate,company_currency_rate,origin])))
  61. return [
  62. {
  63. 'invoice_id': j[0],
  64. 'currency_id': j[1],
  65. 'date': j[2],
  66. 'type': j[3],
  67. 'origin': j[4],
  68. 'customer_id':j[5],
  69. 'user_id':j[6],
  70. 'amount':j[7],
  71. 'number':j[8],
  72. 'user_name':j[9],
  73. 'customer_name':j[10],
  74. 'amount_tax':j[11],
  75. 'state':j[12],
  76. 'store_id':j[13],
  77. 'journal_id':j[14],
  78. 'state':j[15],
  79. 'company_id':j[16]
  80. } for j in r.cr.fetchall()
  81. ]