account_journal.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_currencies_from_journal():
  4. domain = [
  5. ('type', 'in', ['bank', 'cash']),
  6. ('default_debit_account_id.currency_id', '=', False),
  7. ('active', '=', True)
  8. ]
  9. currencies = []
  10. for j in r.env['account.journal'].search(domain):
  11. c = j.currency or j.company_id.currency_id
  12. currencies.append({
  13. 'id': c.id,
  14. 'name': c.display_name,
  15. 'base': c.base,
  16. 'symbol': c.symbol,
  17. 'position': c.position,
  18. 'rateSilent': c.rate_silent,
  19. 'decimalSeparator': c.decimal_separator,
  20. 'decimalPlaces': c.decimal_places,
  21. 'thousandsSeparator': c.thousands_separator
  22. })
  23. return {c['id']:c for c in currencies}.values()
  24. def get_journals():
  25. domain = [
  26. ('type', 'in', ['bank', 'cash']),
  27. ('default_debit_account_id.currency_id', '=', False),
  28. ('active', '=', True)
  29. ]
  30. return [{
  31. 'id': j.id,
  32. 'name': j.name,
  33. 'displayName': j.display_name,
  34. 'code': j.code,
  35. 'cashControl': j.cash_control,
  36. 'type': j.type,
  37. 'currency': {
  38. 'id': j.currency.id,
  39. 'name': j.currency.name,
  40. 'displayName': j.currency.display_name
  41. },
  42. 'defaultDebitAccount': {
  43. 'id': j.default_debit_account_id.id,
  44. 'name': j.default_debit_account_id.name,
  45. 'displayName': j.default_debit_account_id.display_name,
  46. 'code': j.default_debit_account_id.code,
  47. 'exchange_rate': j.default_credit_account_id.exchange_rate,
  48. 'foreignBalance': j.default_credit_account_id.foreign_balance,
  49. 'reconcile': j.default_credit_account_id.reconcile,
  50. 'debit': j.default_credit_account_id.debit,
  51. 'credit': j.default_credit_account_id.credit,
  52. 'currencyMode': j.default_credit_account_id.currency_mode,
  53. 'companyCurrency': {
  54. 'id': j.default_credit_account_id.company_currency_id.id,
  55. 'name': j.default_credit_account_id.company_currency_id.name,
  56. 'displayName': j.default_credit_account_id.company_currency_id.display_name,
  57. },
  58. 'currency': {
  59. 'id': j.default_credit_account_id.currency_id.id,
  60. 'name': j.default_credit_account_id.currency_id.name,
  61. 'displayName': j.default_credit_account_id.currency_id.display_name
  62. }
  63. }
  64. } for j in r.env['account.journal'].search(domain, order='id')]