voucher.py 1.7 KB

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