account_invoice.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_invoice():
  4. user_store = r.env.user.store_id.id
  5. company_currency_rate = r.env.user.company_id.currency_id.rate
  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]) as invoice_rate,
  16. invoice.number
  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 = 'open'
  25. AND journal.store_id = ''' + str(user_store) + '''
  26. GROUP BY
  27. invoice.id,
  28. rate.currency_id,
  29. invoice.date_invoice,
  30. invoice.type,
  31. invoice.origin,
  32. invoice.amount_total,
  33. invoice.partner_id,
  34. invoice.user_id,
  35. invoice.amount_total
  36. '''
  37. r.cr.execute(query,(tuple([company_currency_rate])))
  38. return [
  39. {
  40. 'invoice_id': j[0],
  41. 'currency_id': j[1],
  42. 'date': j[2],
  43. 'type': j[3],
  44. 'origin': j[4],
  45. 'customer_id':j[5],
  46. 'user_id':j[6],
  47. 'amount':j[7],
  48. 'number':j[8],
  49. } for j in r.cr.fetchall()
  50. ]