account_voucher.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_voucher():
  4. company_currency_rate = r.env.user.company_id.currency_id.rate
  5. query = '''
  6. SELECT voucher.id,
  7. voucher.number,
  8. voucher.type,
  9. voucher.date,
  10. journal.currency,
  11. voucher.amount,
  12. CASE
  13. WHEN journal.currency IS NULL
  14. THEN voucher.amount
  15. ELSE voucher.amount * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
  16. END AS amount_currency,
  17. voucher.journal_id,
  18. voucher.reference
  19. FROM account_voucher AS voucher
  20. LEFT JOIN res_store_journal_rel AS journal_rel
  21. ON voucher.journal_id = journal_rel.journal_id
  22. LEFT JOIN account_journal AS journal
  23. ON journal.id = voucher.journal_id
  24. LEFT JOIN res_currency_rate AS rate
  25. ON rate.currency_id = journal.currency
  26. LEFT JOIN account_invoice AS invoice
  27. ON invoice.number = voucher.reference
  28. WHERE voucher.state = 'posted'
  29. GROUP BY
  30. voucher.id,
  31. voucher.number,
  32. voucher.type,
  33. voucher.date,
  34. voucher.amount,
  35. journal.name,
  36. journal.currency
  37. '''
  38. r.cr.execute(query,(tuple([company_currency_rate])))
  39. return [
  40. {
  41. 'id': j[0],
  42. 'number': j[1],
  43. 'type': j[2],
  44. 'date': j[3],
  45. 'currency_id': j[4],
  46. 'amount': j[5],
  47. 'amount_currency': j[6],
  48. 'journal_id': j[7],
  49. 'reference': j[8],
  50. } for j in r.cr.fetchall()
  51. ]