account_bank_statement.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_bank_statement_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
  8. statement.id,
  9. statement.name,
  10. journal.name,
  11. journal.type,
  12. journal.currency,
  13. statement.balance_end,
  14. CASE
  15. WHEN journal.currency IS NULL
  16. THEN statement.balance_end
  17. ELSE statement.balance_end * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
  18. END AS balance_end_currency,
  19. currency.symbol,
  20. currency.decimal_places,
  21. currency.thousands_separator,
  22. currency.decimal_separator
  23. FROM account_bank_statement AS statement
  24. LEFT JOIN res_store_journal_rel AS journal_rel
  25. ON statement.journal_id = journal_rel.journal_id
  26. LEFT JOIN account_journal AS journal
  27. ON statement.journal_id = journal.id
  28. LEFT JOIN res_currency_rate AS rate
  29. ON rate.currency_id = journal.currency
  30. LEFT JOIN res_currency AS currency
  31. ON currency.id = journal.currency
  32. WHERE statement.state NOT IN ('confirm')
  33. AND journal_rel.store_id = ''' + str(user_store) + '''
  34. GROUP BY
  35. statement.id,
  36. statement.name,
  37. journal.name,
  38. journal.type,
  39. journal.currency,
  40. statement.balance_end,
  41. currency.symbol,
  42. currency.decimal_places,
  43. currency.thousands_separator,
  44. currency.decimal_separator
  45. '''
  46. r.cr.execute(query,(tuple([company_currency_rate])))
  47. return [
  48. {
  49. 'id': j[0],
  50. 'name': j[1],
  51. 'journal_name': j[2],
  52. 'journal_type': j[3],
  53. 'journal_currency': j[4],
  54. 'balance_end': j[5],
  55. 'balance_end_currency': j[6],
  56. 'symbol': j[7],
  57. 'decimal_places': j[8],
  58. 'thousands_separator': j[9],
  59. 'decimal_separator': j[10],
  60. } for j in r.cr.fetchall()
  61. ]