account_invoice.py 2.2 KB

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