account_voucher.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_voucher_customer():
  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. WHERE voucher.state = 'posted'
  27. AND voucher.type = 'receipt'
  28. GROUP BY
  29. voucher.id,
  30. voucher.number,
  31. voucher.type,
  32. voucher.date,
  33. voucher.amount,
  34. journal.name,
  35. journal.currency
  36. '''
  37. r.cr.execute(query,(tuple([company_currency_rate])))
  38. return [
  39. {
  40. 'id': j[0],
  41. 'number': j[1],
  42. 'type': j[2],
  43. 'date': j[3],
  44. 'currency_id': j[4],
  45. 'amount': j[5],
  46. 'amount_currency': j[6],
  47. 'journal_id': j[7],
  48. 'reference': j[8],
  49. } for j in r.cr.fetchall()
  50. ]